Merge branch 'master' of https://github.com/highfidelity/hifi into decouple-avatar-updates

This commit is contained in:
Howard Stearns 2015-08-26 12:04:28 -07:00
commit 0e18395fd0
48 changed files with 755 additions and 142 deletions

View file

@ -13,10 +13,9 @@
EntityActionPointer assignmentActionFactory(EntityActionType type, const QUuid& id, EntityItemPointer ownerEntity) {
return (EntityActionPointer) new AssignmentAction(type, id, ownerEntity);
return EntityActionPointer(new AssignmentAction(type, id, ownerEntity));
}
EntityActionPointer AssignmentActionFactory::factory(EntityActionType type,
const QUuid& id,
EntityItemPointer ownerEntity,

View file

@ -131,9 +131,6 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
qDebug() << " numBytesPacketHeader=" << packet->totalHeadersSize();
qDebug() << " sizeof(sequence)=" << sizeof(sequence);
qDebug() << " sizeof(sentAt)=" << sizeof(sentAt);
}
if (debugProcessPacket) {
qDebug() << " atByte (in payload)=" << packet->pos();
qDebug() << " payload size=" << packet->getPayloadSize();

View file

@ -643,7 +643,7 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
quint64 averageLoggingTime = _tree->getAverageLoggingTime();
float averageElementsPerPacket = totalPacketsProcessed == 0 ? 0 : totalElementsProcessed / totalPacketsProcessed;
float averageElementsPerPacket = totalPacketsProcessed == 0 ? 0 : (float)totalElementsProcessed / totalPacketsProcessed;
statsString += QString(" Current Inbound Packets Queue: %1 packets\r\n")
.arg(locale.toString((uint)currentPacketsInQueue).rightJustified(COLUMN_WIDTH, ' '));
@ -695,7 +695,7 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
totalElementsProcessed = senderStats.getTotalElementsProcessed();
totalPacketsProcessed = senderStats.getTotalPacketsProcessed();
averageElementsPerPacket = totalPacketsProcessed == 0 ? 0 : totalElementsProcessed / totalPacketsProcessed;
averageElementsPerPacket = totalPacketsProcessed == 0 ? 0 : (float)totalElementsProcessed / totalPacketsProcessed;
statsString += QString(" Total Inbound Packets: %1 packets\r\n")
.arg(locale.toString((uint)totalPacketsProcessed).rightJustified(COLUMN_WIDTH, ' '));
@ -1075,9 +1075,7 @@ void OctreeServer::run() {
// now set up PersistThread
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
if (_persistThread) {
_persistThread->initialize(true);
}
_persistThread->initialize(true);
}
HifiSockAddr senderSockAddr;

View file

@ -57,7 +57,7 @@ function(AUTOSCRIBE_SHADER SHADER_FILE)
set(SCRIBE_ARGS -c++ -D GLPROFILE ${GLPROFILE} ${SCRIBE_INCLUDES} -o ${SHADER_TARGET} ${SHADER_FILE})
add_custom_command(OUTPUT ${SHADER_TARGET} COMMAND scribe ${SCRIBE_ARGS} DEPENDS scribe ${SHADER_INCLUDE_FILES} ${SHADER_FILE})
else (APPLE)
else ()
set(GLPROFILE PC_GL)
set(SCRIBE_ARGS -c++ -D GLPROFILE ${GLPROFILE} ${SCRIBE_INCLUDES} -o ${SHADER_TARGET} ${SHADER_FILE})
@ -91,7 +91,8 @@ macro(AUTOSCRIBE_SHADER_LIB)
#message(${SHADER_INCLUDE_FILES})
foreach(SHADER_FILE ${SHADER_SOURCE_FILES})
AUTOSCRIBE_SHADER(${SHADER_FILE} ${SHADER_INCLUDE_FILES})
list(APPEND AUTOSCRIBE_SHADER_SRC ${AUTOSCRIBE_SHADER_RETURN})
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${AUTOSCRIBE_SHADER_RETURN}" AUTOSCRIBE_GENERATED_FILE)
list(APPEND AUTOSCRIBE_SHADER_SRC ${AUTOSCRIBE_GENERATED_FILE})
endforeach()
#message(${AUTOSCRIBE_SHADER_SRC})

View file

@ -23,8 +23,8 @@ macro(SETUP_HIFI_PROJECT)
endforeach()
# add the executable, include additional optional sources
add_executable(${TARGET_NAME} ${TARGET_SRCS} "${AUTOMTC_SRC}")
add_executable(${TARGET_NAME} ${TARGET_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC})
set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN})
list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core)

View file

@ -185,4 +185,26 @@ Hifi.VrMenu {
}
}
}
function addMenu(menu, newMenu) {
return menu.addMenu(newMenu);
}
function addItem(menu, newMenuItem) {
return menu.addItem(newMenuItem);
}
function insertItem(menu, beforeItem, newMenuItem) {
for (var i = 0; i < menu.items.length; ++i) {
console.log(menu.items[i]);
if (menu.items[i] === beforeItem) {
return menu.insertItem(i, newMenuItem);
}
}
return addItem(menu, newMenuItem);
}
function removeItem(menu, menuItem) {
menu.removeItem(menuItem);
}
}

View file

@ -126,6 +126,7 @@
#include "scripting/AccountScriptingInterface.h"
#include "scripting/AudioDeviceScriptingInterface.h"
#include "scripting/ClipboardScriptingInterface.h"
#include "scripting/DesktopScriptingInterface.h"
#include "scripting/HMDScriptingInterface.h"
#include "scripting/GlobalServicesScriptingInterface.h"
#include "scripting/LocationScriptingInterface.h"
@ -284,6 +285,7 @@ bool setupEssentials(int& argc, char** argv) {
auto dialogsManager = DependencyManager::set<DialogsManager>();
auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
auto resourceCacheSharedItems = DependencyManager::set<ResourceCacheSharedItems>();
auto desktopScriptingInterface = DependencyManager::set<DesktopScriptingInterface>();
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
auto windowScriptingInterface = DependencyManager::set<WindowScriptingInterface>();
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
@ -1270,7 +1272,7 @@ void Application::resizeGL() {
loadViewFrustum(_myCamera, _viewFrustum);
float fov = glm::radians(DEFAULT_FIELD_OF_VIEW_DEGREES);
// FIXME the aspect ratio for stereo displays is incorrect based on this.
float aspectRatio = aspect(_renderResolution);
float aspectRatio = displayPlugin->getRecommendedAspectRatio();
_myCamera.setProjection(glm::perspective(fov, aspectRatio, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
}
@ -1426,7 +1428,6 @@ void Application::keyPressEvent(QKeyEvent* event) {
bool isMeta = event->modifiers().testFlag(Qt::ControlModifier);
bool isOption = event->modifiers().testFlag(Qt::AltModifier);
switch (event->key()) {
break;
case Qt::Key_Enter:
case Qt::Key_Return:
if (isOption) {
@ -3979,6 +3980,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue,
RayToOverlayIntersectionResultFromScriptValue);
scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
LocationScriptingInterface::locationSetter, windowValue);

View file

@ -62,7 +62,7 @@ void GLCanvas::paintGL() {
// FIXME - I'm not sure why this still remains, it appears as if this GLCanvas gets a single paintGL call near
// the beginning of the application starting up. I'm not sure if we really need to call Application::paintGL()
// in this case, since the display plugins eventually handle all the painting
if ((!Application::getInstance()->getWindow()->isMinimized() || !Application::getInstance()->isThrottleFPSEnabled())) {
if (!Application::getInstance()->getWindow()->isMinimized() || !Application::getInstance()->isThrottleFPSEnabled()) {
Application::getInstance()->paintGL();
}
}

View file

@ -1046,6 +1046,9 @@ QAction* MenuWrapper::addAction(const QString& menuName, const QObject* receiver
void MenuWrapper::removeAction(QAction* action) {
_realMenu->removeAction(action);
VrMenu::executeOrQueue([=](VrMenu* vrMenu) {
vrMenu->removeAction(action);
});
}
void MenuWrapper::insertAction(QAction* before, QAction* action) {

View file

@ -65,9 +65,8 @@ FSTReader::ModelType ModelSelector::getModelType() const {
return FSTReader::ATTACHMENT_MODEL;
} else if (text == ENTITY_MODEL_STRING) {
return FSTReader::ENTITY_MODEL;
} else {
Q_UNREACHABLE();
}
}
Q_UNREACHABLE();
}
void ModelSelector::accept() {

View file

@ -1307,7 +1307,7 @@ glm::vec3 MyAvatar::applyKeyboardMotor(float deltaTime, const glm::vec3& localVe
bool isThrust = (glm::length2(_thrust) > EPSILON);
if (_isPushing || isThrust ||
(_scriptedMotorTimescale < MAX_KEYBOARD_MOTOR_TIMESCALE &&
_motionBehaviors | AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED)) {
(_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED))) {
// we don't want to brake if something is pushing the avatar around
timescale = _keyboardMotorTimescale;
_isBraking = false;

View file

@ -0,0 +1,27 @@
//
// DesktopScriptingInterface.h
// interface/src/scripting
//
// Created by David Rowe on 25 Aug 2015.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "DesktopScriptingInterface.h"
#include <QWindow>
#include <QScreen>
#include "Application.h"
#include "MainWindow.h"
int DesktopScriptingInterface::getWidth() {
QSize size = Application::getInstance()->getWindow()->windowHandle()->screen()->virtualSize();
return size.width();
}
int DesktopScriptingInterface::getHeight() {
QSize size = Application::getInstance()->getWindow()->windowHandle()->screen()->virtualSize();
return size.height();
}

View file

@ -0,0 +1,29 @@
//
// DesktopScriptingInterface.h
// interface/src/scripting
//
// Created by David Rowe on 25 Aug 2015.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_DesktopScriptingInterface_h
#define hifi_DesktopScriptingInterface_h
#include <QObject>
#include <DependencyManager.h>
class DesktopScriptingInterface : public QObject, public Dependency {
Q_OBJECT
Q_PROPERTY(int width READ getWidth) // Physical width of screen(s) including task bars and system menus
Q_PROPERTY(int height READ getHeight) // Physical height of screen(s) including task bars and system menus
public:
int getWidth();
int getHeight();
};
#endif // hifi_DesktopScriptingInterface_h

View file

@ -437,7 +437,6 @@ void OctreeStatsDialog::showOctreeServersOfType(int& serverCount, NodeType_t ser
case MOST: {
extraDetails << "<br/>" ;
const unsigned long USECS_PER_MSEC = 1000;
float lastFullEncode = stats.getLastFullTotalEncodeTime() / USECS_PER_MSEC;
float lastFullSend = stats.getLastFullElapsedTime() / USECS_PER_MSEC;
float lastFullSendInSeconds = stats.getLastFullElapsedTime() / USECS_PER_SECOND;

View file

@ -49,6 +49,7 @@ PreferencesDialog::PreferencesDialog(QWidget* parent) :
connect(ui.buttonChangeAppearance, &QPushButton::clicked, this, &PreferencesDialog::openFullAvatarModelBrowser);
connect(ui.appearanceDescription, &QLineEdit::textChanged, this, [this](const QString& url) {
DependencyManager::get<AvatarManager>()->getMyAvatar()->useFullAvatarURL(url, "");
this->fullAvatarURLChanged(url, "");
});
connect(Application::getInstance(), &Application::fullAvatarURLChanged, this, &PreferencesDialog::fullAvatarURLChanged);

View file

@ -130,8 +130,8 @@ void Stats::updateStats() {
STAT_UPDATE(audioPing, audioMixerNode ? audioMixerNode->getPingMs() : -1);
STAT_UPDATE(avatarPing, avatarMixerNode ? avatarMixerNode->getPingMs() : -1);
//// Now handle voxel servers, since there could be more than one, we average their ping times
unsigned long totalPingOctree = 0;
//// Now handle entity servers, since there could be more than one, we average their ping times
int totalPingOctree = 0;
int octreeServerCount = 0;
int pingOctreeMax = 0;
nodeList->eachNode([&](const SharedNodePointer& node) {
@ -144,6 +144,9 @@ void Stats::updateStats() {
}
}
});
// update the entities ping with the average for all connected entity servers
STAT_UPDATE(entitiesPing, octreeServerCount ? totalPingOctree / octreeServerCount : -1);
} else {
// -2 causes the QML to hide the ping column
STAT_UPDATE(audioPing, -2);

View file

@ -27,9 +27,10 @@ class AngularConstraint;
class JointState {
public:
JointState() {}
JointState(const JointState& other) : _constraint(NULL) { copyState(other); }
JointState(const JointState& other) { copyState(other); }
JointState(const FBXJoint& joint);
~JointState();
JointState& operator=(const JointState& other) { copyState(other); return *this; }
void copyState(const JointState& state);
void buildConstraint();

View file

@ -77,10 +77,8 @@ AudioFrameBuffer< T >::~AudioFrameBuffer() {
template< typename T >
void AudioFrameBuffer< T >::allocateFrames() {
_frameBuffer = new T*[_channelCountMax];
if (_frameBuffer) {
for (uint32_t i = 0; i < _channelCountMax; ++i) {
_frameBuffer[i] = new T[_frameCountMax];
}
for (uint32_t i = 0; i < _channelCountMax; ++i) {
_frameBuffer[i] = new T[_frameCountMax];
}
}

View file

@ -108,14 +108,14 @@ public:
void setParameters(uint32_t filterStage, uint32_t filterChannel, const float32_t sampleRate, const float32_t frequency,
const float32_t gain, const float32_t slope) {
if (filterStage >= 0 && filterStage < _filterCount && filterChannel >= 0 && filterChannel < _channelCount) {
if (filterStage < _filterCount && filterChannel >= 0 && filterChannel < _channelCount) {
_filters[filterStage][filterChannel].setParameters(sampleRate,frequency,gain,slope);
}
}
void getParameters(uint32_t filterStage, uint32_t filterChannel, float32_t& sampleRate, float32_t& frequency,
float32_t& gain, float32_t& slope) {
if (filterStage >= 0 && filterStage < _filterCount && filterChannel >= 0 && filterChannel < _channelCount) {
if (filterStage < _filterCount && filterChannel >= 0 && filterChannel < _channelCount) {
_filters[filterStage][filterChannel].getParameters(sampleRate,frequency,gain,slope);
}
}

View file

@ -85,12 +85,12 @@ public:
_bufferFirst(NULL),
_bufferLast(NULL),
_at(NULL) {}
ConstIterator(int16_t* bufferFirst, int capacity, int16_t* at)
: _bufferLength(capacity),
_bufferFirst(bufferFirst),
_bufferLast(bufferFirst + capacity - 1),
_at(at) {}
ConstIterator(const ConstIterator& rhs) = default;
bool isNull() const { return _at == NULL; }

View file

@ -8,12 +8,12 @@
#pragma once
#include "plugins/Plugin.h"
#include <QSize>
#include <QPoint>
#include <functional>
#include "gpu/GPUConfig.h"
#include "GLMHelpers.h"
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
@ -92,6 +92,11 @@ public:
return getRecommendedRenderSize();
}
// By default the aspect ratio is just the render size
virtual float getRecommendedAspectRatio() const {
return aspect(getRecommendedRenderSize());
}
// Stereo specific methods
virtual glm::mat4 getProjection(Eye eye, const glm::mat4& baseProjection) const {
return baseProjection;

View file

@ -91,3 +91,9 @@ void StereoDisplayPlugin::deactivate() {
CONTAINER->unsetFullscreen();
WindowOpenGLDisplayPlugin::deactivate();
}
// Derived classes will override the recommended render size based on the window size,
// so here we want to fix the aspect ratio based on the window, not on the render size
float StereoDisplayPlugin::getRecommendedAspectRatio() const {
return aspect(WindowOpenGLDisplayPlugin::getRecommendedRenderSize());
}

View file

@ -19,6 +19,7 @@ public:
virtual void activate() override;
virtual void deactivate() override;
virtual float getRecommendedAspectRatio() const override;
virtual glm::mat4 getProjection(Eye eye, const glm::mat4& baseProjection) const override;
virtual glm::mat4 getEyePose(Eye eye) const override;

View file

@ -2003,6 +2003,7 @@ FBXGeometry* extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping
material._material = make_shared<model::Material>();
material._material->setEmissive(material.emissive);
// FIXME both cases are identical
if (glm::all(glm::equal(material.diffuse, glm::vec3(0.0f)))) {
material._material->setDiffuse(material.diffuse);
} else {

View file

@ -149,7 +149,7 @@ protected:
void updateSize(const TexturePointer& texture);
// Non exposed
Framebuffer(const Framebuffer& framebuffer) {}
Framebuffer(const Framebuffer& framebuffer) = delete;
Framebuffer() {}
// This shouldn't be used by anything else than the Backend class with the proper casting.

View file

@ -234,14 +234,21 @@ void GLBackend::do_clearFramebuffer(Batch& batch, uint32 paramOffset) {
std::vector<GLenum> drawBuffers;
if (masks & Framebuffer::BUFFER_COLORS) {
for (unsigned int i = 0; i < Framebuffer::MAX_NUM_RENDER_BUFFERS; i++) {
if (masks & (1 << i)) {
drawBuffers.push_back(GL_COLOR_ATTACHMENT0 + i);
if (_output._framebuffer) {
for (unsigned int i = 0; i < Framebuffer::MAX_NUM_RENDER_BUFFERS; i++) {
if (masks & (1 << i)) {
drawBuffers.push_back(GL_COLOR_ATTACHMENT0 + i);
}
}
}
if (!drawBuffers.empty()) {
glDrawBuffers(drawBuffers.size(), drawBuffers.data());
if (!drawBuffers.empty()) {
glDrawBuffers(drawBuffers.size(), drawBuffers.data());
glClearColor(color.x, color.y, color.z, color.w);
glmask |= GL_COLOR_BUFFER_BIT;
(void) CHECK_GL_ERROR();
}
} else {
glClearColor(color.x, color.y, color.z, color.w);
glmask |= GL_COLOR_BUFFER_BIT;
}

View file

@ -226,9 +226,12 @@ void UserInputMapper::update(float deltaTime) {
}
// Scale all the channel step with the scale
static const float EPSILON = 0.01f;
for (auto i = 0; i < NUM_ACTIONS; i++) {
_actionStates[i] *= _actionScales[i];
if (_actionStates[i] > 0) {
// Emit only on change, and emit when moving back to 0
if (fabs(_actionStates[i] - _lastActionStates[i]) > EPSILON) {
_lastActionStates[i] = _actionStates[i];
emit actionEvent(i, _actionStates[i]);
}
// TODO: emit signal for pose changes

View file

@ -248,6 +248,7 @@ protected:
std::vector<float> _actionStates = std::vector<float>(NUM_ACTIONS, 0.0f);
std::vector<float> _actionScales = std::vector<float>(NUM_ACTIONS, 1.0f);
std::vector<float> _lastActionStates = std::vector<float>(NUM_ACTIONS, 0.0f);
std::vector<PoseValue> _poseStates = std::vector<PoseValue>(NUM_ACTIONS);
glm::mat4 _sensorToWorldMat;

View file

@ -95,7 +95,7 @@ void ViveControllerManager::activate() {
vr::RenderModel_t model;
if (!_hmd->LoadRenderModel(CONTROLLER_MODEL_STRING.toStdString().c_str(), &model)) {
qDebug("Unable to load render model %s\n", CONTROLLER_MODEL_STRING);
qDebug() << QString("Unable to load render model %1\n").arg(CONTROLLER_MODEL_STRING);
} else {
model::Mesh* mesh = new model::Mesh();
model::MeshPointer meshPtr(mesh);
@ -198,7 +198,7 @@ void ViveControllerManager::renderHand(UserInputMapper::PoseValue pose, gpu::Bat
Transform transform(userInputMapper->getSensorToWorldMat());
transform.postTranslate(pose.getTranslation() + pose.getRotation() * glm::vec3(0, 0, CONTROLLER_LENGTH_OFFSET));
int sign = index == LEFT_HAND ? 1.0f : -1.0f;
int sign = index == LEFT_HAND ? 1 : -1;
glm::quat rotation = pose.getRotation() * glm::angleAxis(PI, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::angleAxis(sign * PI_OVER_TWO, glm::vec3(0.0f, 0.0f, 1.0f));
transform.postRotate(rotation);
@ -325,7 +325,7 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) {
glm::quat rotation = glm::quat_cast(mat);
// Flip the rotation appropriately for each hand
int sign = index == LEFT_HAND ? 1.0f : -1.0f;
int sign = index == LEFT_HAND ? 1 : -1;
rotation = rotation * glm::angleAxis(PI, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::angleAxis(sign * PI_OVER_TWO, glm::vec3(0.0f, 0.0f, 1.0f));
position += rotation * glm::vec3(0, 0, -CONTROLLER_LENGTH_OFFSET);

View file

@ -338,7 +338,7 @@ void CoverageRegion::erase() {
}
**/
// If we're in charge of managing the polygons, then clean them up first
if (_managePolygons) {
if (_polygons && _managePolygons) {
for (int i = 0; i < _polygonCount; i++) {
delete _polygons[i];
_polygons[i] = NULL; // do we need to do this?

View file

@ -1318,7 +1318,8 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element,
// If the user also asked for occlusion culling, check if this element is occluded
if (params.wantOcclusionCulling && childElement->isLeaf()) {
// Don't check occlusion here, just add them to our distance ordered array...
// FIXME params.ViewFrustum is used here, but later it is checked against nullptr.
OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(
params.viewFrustum->getProjectedPolygon(childElement->getAACube()));

View file

@ -621,6 +621,7 @@ QSharedPointer<Texture> DilatableNetworkTexture::getDilatedTexture(float dilatio
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
if (dilatedImage.hasAlphaChannel()) {
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA));
// FIXME either remove the ?: operator or provide different arguments depending on linear
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::BGRA));
}
texture->_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, dilatedImage.width(), dilatedImage.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));

View file

@ -81,8 +81,10 @@ public:
return OPEN;
case QAbstractSocket::SocketState::ClosingState:
return CLOSING;
case QAbstractSocket::SocketState::UnconnectedState:
default:
return CLOSED;
}
return CLOSED;
}
void setOnClose(QScriptValue eventFunction) { _onCloseEvent = eventFunction; }

View file

@ -20,8 +20,8 @@
#include "Transform.h"
void Extents::reset() {
minimum = glm::vec3(FLT_MAX);
maximum = glm::vec3(-FLT_MAX);
minimum = Vectors::MAX;
maximum = Vectors::MIN;
}
bool Extents::containsPoint(const glm::vec3& point) const {

View file

@ -18,14 +18,15 @@
#include <QDebug>
#include "StreamUtils.h"
#include "GLMHelpers.h"
class AABox;
class Transform;
class Extents {
public:
Extents(const glm::vec3& minimum, const glm::vec3& maximum) : minimum(minimum), maximum(maximum) { }
Extents() { reset(); }
Extents() { }
Extents(const glm::vec3& minimum, const glm::vec3& maximum) : minimum(minimum), maximum(maximum) {}
Extents(const AABox& box) { reset(); add(box); }
/// set minimum and maximum to FLT_MAX and -FLT_MAX respectively
@ -49,7 +50,7 @@ public:
/// \return whether or not the extents are empty
bool isEmpty() const { return minimum == maximum; }
bool isValid() const { return !((minimum == glm::vec3(FLT_MAX)) && (maximum == glm::vec3(-FLT_MAX))); }
bool isValid() const { return !((minimum == Vectors::MAX) && (maximum == Vectors::MIN)); }
/// \param vec3 for delta amount to shift the extents by
/// \return true if point is within current limits
@ -75,8 +76,8 @@ public:
return temp;
}
glm::vec3 minimum;
glm::vec3 maximum;
glm::vec3 minimum{ Vectors::MAX };
glm::vec3 maximum{ Vectors::MIN };
};
inline QDebug operator<<(QDebug debug, const Extents& extents) {

View file

@ -13,6 +13,24 @@
#include "NumericalConstants.h"
const vec3 Vectors::UNIT_X{ 1.0f, 0.0f, 0.0f };
const vec3 Vectors::UNIT_Y{ 0.0f, 1.0f, 0.0f };
const vec3 Vectors::UNIT_Z{ 0.0f, 0.0f, 1.0f };
const vec3 Vectors::UNIT_NEG_X{ -1.0f, 0.0f, 0.0f };
const vec3 Vectors::UNIT_NEG_Y{ 0.0f, -1.0f, 0.0f };
const vec3 Vectors::UNIT_NEG_Z{ 0.0f, 0.0f, -1.0f };
const vec3 Vectors::UNIT_XY{ glm::normalize(UNIT_X + UNIT_Y) };
const vec3 Vectors::UNIT_XZ{ glm::normalize(UNIT_X + UNIT_Z) };
const vec3 Vectors::UNIT_YZ{ glm::normalize(UNIT_Y + UNIT_Z) };
const vec3 Vectors::UNIT_XYZ{ glm::normalize(UNIT_X + UNIT_Y + UNIT_Z) };
const vec3 Vectors::MAX{ FLT_MAX };
const vec3 Vectors::MIN{ -FLT_MAX };
const vec3 Vectors::ZERO{ 0.0f };
const vec3 Vectors::ONE{ 1.0f };
const vec3& Vectors::RIGHT = Vectors::UNIT_X;
const vec3& Vectors::UP = Vectors::UNIT_Y;
const vec3& Vectors::FRONT = Vectors::UNIT_NEG_Z;
// Safe version of glm::mix; based on the code in Nick Bobick's article,
// http://www.gamasutra.com/features/19980703/quaternions_01.htm (via Clyde,
// https://github.com/threerings/clyde/blob/master/src/main/java/com/threerings/math/Quaternion.java)

View file

@ -53,6 +53,28 @@ const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f,-1.0f);
glm::quat safeMix(const glm::quat& q1, const glm::quat& q2, float alpha);
class Vectors {
public:
static const vec3 UNIT_X;
static const vec3 UNIT_Y;
static const vec3 UNIT_Z;
static const vec3 UNIT_NEG_X;
static const vec3 UNIT_NEG_Y;
static const vec3 UNIT_NEG_Z;
static const vec3 UNIT_XY;
static const vec3 UNIT_XZ;
static const vec3 UNIT_YZ;
static const vec3 UNIT_ZX;
static const vec3 UNIT_XYZ;
static const vec3 MAX;
static const vec3 MIN;
static const vec3 ZERO;
static const vec3 ONE;
static const vec3& RIGHT;
static const vec3& UP;
static const vec3& FRONT;
};
// These pack/unpack functions are designed to start specific known types in as efficient a manner
// as possible. Taking advantage of the known characteristics of the semantic types.

View file

@ -38,14 +38,14 @@ LogHandler::LogHandler() :
const char* stringForLogType(LogMsgType msgType) {
switch (msgType) {
case QtDebugMsg:
case LogDebug:
return "DEBUG";
case QtCriticalMsg:
return "CRITICAL";
case QtFatalMsg:
return "FATAL";
case QtWarningMsg:
case LogWarning:
return "WARNING";
case LogCritical:
return "CRITICAL";
case LogFatal:
return "FATAL";
case LogSuppressed:
return "SUPPRESS";
default:

View file

@ -22,10 +22,10 @@
const int VERBOSE_LOG_INTERVAL_SECONDS = 5;
enum LogMsgType {
LogDebug,
LogWarning,
LogCritical,
LogFatal,
LogDebug = QtDebugMsg,
LogWarning = QtWarningMsg,
LogCritical = QtCriticalMsg,
LogFatal = QtFatalMsg,
LogSuppressed
};

View file

@ -174,7 +174,7 @@ public:
}
bool operator<=(const Iterator& rhs) {
return age() < rhs.age();
return age() <= rhs.age();
}
bool operator>=(const Iterator& rhs) {

View file

@ -37,7 +37,7 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
norm = (norm > n ? norm : n);
}
rotationMat = nextRotation;
} while (count < 100 && norm > ACCURACY_THREASHOLD);
} while (count++ < 100 && norm > ACCURACY_THREASHOLD);
// extract scale of the matrix as the length of each axis

View file

@ -83,46 +83,6 @@ VrMenu::VrMenu(QQuickItem* parent) : QQuickItem(parent) {
this->setEnabled(false);
}
// QML helper functions
QObject* addMenu(QObject* parent, const QString& text) {
// FIXME add more checking here to ensure no name conflicts
QVariant returnedValue;
QMetaObject::invokeMethod(parent, "addMenu", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, text));
QObject* result = returnedValue.value<QObject*>();
if (result) {
result->setObjectName(text);
}
return result;
}
class QQuickMenuItem;
QObject* addItem(QObject* parent, const QString& text) {
// FIXME add more checking here to ensure no name conflicts
QQuickMenuItem* returnedValue{ nullptr };
bool invokeResult =
QMetaObject::invokeMethod(parent, "addItem", Qt::DirectConnection, Q_RETURN_ARG(QQuickMenuItem*, returnedValue),
Q_ARG(QString, text));
#ifndef QT_NO_DEBUG
Q_ASSERT(invokeResult);
#else
Q_UNUSED(invokeResult);
#endif
QObject* result = reinterpret_cast<QObject*>(returnedValue);
return result;
}
const QObject* VrMenu::findMenuObject(const QString& menuOption) const {
if (menuOption.isEmpty()) {
return _rootMenu;
}
const QObject* result = _rootMenu->findChild<QObject*>(menuOption);
return result;
}
QObject* VrMenu::findMenuObject(const QString& menuOption) {
if (menuOption.isEmpty()) {
return _rootMenu;
@ -147,7 +107,16 @@ void VrMenu::addMenu(QMenu* menu) {
} else {
Q_ASSERT(false);
}
QObject* result = ::addMenu(qmlParent, menu->title());
QVariant returnedValue;
bool invokeResult = QMetaObject::invokeMethod(this, "addMenu", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, QVariant::fromValue(qmlParent)),
Q_ARG(QVariant, QVariant::fromValue(menu->title())));
Q_ASSERT(invokeResult);
QObject* result = returnedValue.value<QObject*>();
Q_ASSERT(result);
// Bind the QML and Widget together
new MenuUserData(menu, result);
}
@ -175,9 +144,15 @@ void VrMenu::addAction(QMenu* menu, QAction* action) {
Q_ASSERT(!MenuUserData::forObject(action));
Q_ASSERT(MenuUserData::forObject(menu));
MenuUserData* userData = MenuUserData::forObject(menu);
QObject* parent = findMenuObject(userData->uuid.toString());
Q_ASSERT(parent);
QObject* result = ::addItem(parent, action->text());
QObject* menuQml = findMenuObject(userData->uuid.toString());
Q_ASSERT(menuQml);
QVariant returnedValue;
bool invokeResult = QMetaObject::invokeMethod(this, "addItem", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, QVariant::fromValue(menuQml)),
Q_ARG(QVariant, QVariant::fromValue(action->text())));
Q_ASSERT(invokeResult);
QObject* result = returnedValue.value<QObject*>();
Q_ASSERT(result);
// Bind the QML and Widget together
bindActionToQmlAction(result, action);
@ -190,38 +165,34 @@ void VrMenu::insertAction(QAction* before, QAction* action) {
Q_ASSERT(beforeUserData);
beforeQml = findMenuObject(beforeUserData->uuid.toString());
}
QObject* menu = beforeQml->parent();
int index{ -1 };
QVariant itemsVar = menu->property("items");
QList<QVariant> items = itemsVar.toList();
// FIXME add more checking here to ensure no name conflicts
for (index = 0; index < items.length(); ++index) {
QObject* currentQmlItem = items.at(index).value<QObject*>();
if (currentQmlItem == beforeQml) {
break;
}
}
QObject* result{ nullptr };
if (index < 0 || index >= items.length()) {
result = ::addItem(menu, action->text());
} else {
QQuickMenuItem* returnedValue{ nullptr };
bool invokeResult =
QMetaObject::invokeMethod(menu, "insertItem", Qt::DirectConnection, Q_RETURN_ARG(QQuickMenuItem*, returnedValue),
Q_ARG(int, index), Q_ARG(QString, action->text()));
#ifndef QT_NO_DEBUG
Q_ASSERT(invokeResult);
#else
Q_UNUSED(invokeResult);
#endif
result = reinterpret_cast<QObject*>(returnedValue);
}
QVariant returnedValue;
bool invokeResult = QMetaObject::invokeMethod(this, "insertItem", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, QVariant::fromValue(menu)),
Q_ARG(QVariant, QVariant::fromValue(beforeQml)),
Q_ARG(QVariant, QVariant::fromValue(action->text())));
Q_ASSERT(invokeResult);
QObject* result = returnedValue.value<QObject*>();
Q_ASSERT(result);
bindActionToQmlAction(result, action);
}
void VrMenu::removeAction(QAction* action) {
// FIXME implement
MenuUserData* userData = MenuUserData::forObject(action);
if (!userData) {
qWarning("Attempted to remove menu action with no found QML object");
return;
}
QObject* item = findMenuObject(userData->uuid.toString());
QObject* menu = item->parent();
// Proxy QuickItem requests through the QML layer
bool invokeResult = QMetaObject::invokeMethod(this, "removeItem", Qt::DirectConnection,
Q_ARG(QVariant, QVariant::fromValue(menu)),
Q_ARG(QVariant, QVariant::fromValue(item)));
#ifndef QT_NO_DEBUG
Q_ASSERT(invokeResult);
#else
Q_UNUSED(invokeResult);
#endif
}

View file

@ -38,9 +38,7 @@ public:
protected:
QObject* _rootMenu{ nullptr };
QObject* findMenuObject(const QString& name);
const QObject* findMenuObject(const QString& name) const;
static VrMenu* _instance;
friend class MenuUserData;

View file

@ -0,0 +1,15 @@
set(TARGET_NAME gpu-test)
AUTOSCRIBE_SHADER_LIB(gpu model render-utils)
# This is not a testcase -- just set it up as a regular hifi project
setup_hifi_project(Quick Gui OpenGL Script Widgets)
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/")
#include_oglplus()
# link in the shared libraries
link_hifi_libraries(render-utils gpu shared networking fbx model animation script-engine)
copy_dlls_beside_windows_executable()

415
tests/gpu-test/src/main.cpp Normal file
View file

@ -0,0 +1,415 @@
//
// main.cpp
// tests/gpu-test/src
//
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <unordered_map>
#include <memory>
#include <glm/glm.hpp>
#include <QApplication>
#include <QDir>
#include <QElapsedTimer>
#include <QFile>
#include <QImage>
#include <QLoggingCategory>
#include <gpu/Context.h>
#include <gpu/Batch.h>
#include <gpu/Stream.h>
#include <gpu/StandardShaderLib.h>
#include <gpu/GLBackend.h>
#include <QOpenGLContext>
#include <QResizeEvent>
#include <QTime>
#include <QTimer>
#include <QWindow>
#include <cstdio>
#include <PathUtils.h>
#include <GeometryCache.h>
#include "simple_frag.h"
#include "simple_vert.h"
class RateCounter {
std::vector<float> times;
QElapsedTimer timer;
public:
RateCounter() {
timer.start();
}
void reset() {
times.clear();
}
unsigned int count() const {
return times.size() - 1;
}
float elapsed() const {
if (times.size() < 1) {
return 0.0f;
}
float elapsed = *times.rbegin() - *times.begin();
return elapsed;
}
void increment() {
times.push_back(timer.elapsed() / 1000.0f);
}
float rate() const {
if (elapsed() == 0.0f) {
return NAN;
}
return (float) count() / elapsed();
}
};
#define MOVE_PARAM(name) decltype(name) && name
struct BasicModel {
gpu::PipelinePointer pipeline;
// gpu::BufferPointer vertexBuffer;
// gpu::BufferPointer indexBuffer;
// gpu::BufferPointer normalBuffer;
gpu::BufferView vertices;
gpu::BufferView normals;
gpu::BufferPointer indices;
gpu::Stream::FormatPointer format;
BasicModel (MOVE_PARAM(pipeline), MOVE_PARAM(vertices), MOVE_PARAM(normals), MOVE_PARAM(indices), MOVE_PARAM(format))
: pipeline(pipeline), vertices(vertices), normals(normals), indices(indices), format(format) {}
// BasicModel (gpu::PipelinePointer && pipeline, gpu::BufferPointer && buffer, gpu::Stream::FormatPointer && format)
// : pipeline(pipeline), buffer(buffer), format(format) {}
};
typedef std::shared_ptr<BasicModel> BasicModelPointer;
#undef MOVE_PARAM
BasicModelPointer makeCube () {
// Axis-aligned cube, facing the user at +z
// coords == binary mapping of each index, with z inverted (front face faces camera,
// instead of away from the camera)
//
// -x,+y,-z ----------- +x,+y,-z
// ___--- | ___--- |
// -x,+y,+z --------- +x,+y,+z |
// | | | |
// | | | |
// | | | |
// | | | |
// | -x,-y,-z ------|---- +x,-y,-z
// | ___--- | ___----
// -x,-y,+z --------- +x,-y,+z
//
float s = 1.0f;
const glm::vec3 raw_verts[8] = {
// x, y, z
{ -s, -s, +s }, // 0b000 0x0
{ +s, -s, +s }, // 0b001 0x1
{ -s, +s, +s }, // 0b010 0x2
{ +s, +s, +s }, // 0b011 0x3
{ -s, -s, -s }, // 0b100 0x4
{ +s, -s, -s }, // 0b101 0x5
{ -s, +s, -s }, // 0b110 0x6
{ +s, +s, -s } // 0b111 0x7
};
const glm::vec3 raw_normals[6] = {
{ 0.0f, 0.0f, +1.0f }, // x > 0: 1, 3, 5, 7 (N 0)
{ 0.0f, 0.0f, -1.0f }, // x < 0: 0, 2, 4, 6 (N 1)
{ 0.0f, +1.0f, 0.0f }, // y > 0: 2, 3, 6, 7 (N 2)
{ 0.0f, -1.0f, 0.0f }, // y < 0: 0, 1, 4, 5 (N 3)
{ +1.0f, 0.0f, 0.0f }, // z > 0: 0, 1, 2, 3 (N 4)
{ -1.0f, 0.0f, 0.0f } // z < 0: 4, 5, 6, 7 (N 5)
};
const glm::vec3 cube_verts[24] = {
raw_verts[1], raw_verts[3], raw_verts[5], raw_verts[7],
raw_verts[0], raw_verts[2], raw_verts[4], raw_verts[6],
raw_verts[2], raw_verts[3], raw_verts[6], raw_verts[7],
raw_verts[0], raw_verts[1], raw_verts[4], raw_verts[5],
raw_verts[0], raw_verts[1], raw_verts[2], raw_verts[3],
raw_verts[4], raw_verts[5], raw_verts[6], raw_verts[7]
};
const glm::vec3 cube_normals[24] = {
raw_normals[0], raw_normals[0], raw_normals[0], raw_normals[0],
raw_normals[1], raw_normals[1], raw_normals[1], raw_normals[1],
raw_normals[2], raw_normals[2], raw_normals[2], raw_normals[2],
raw_normals[3], raw_normals[3], raw_normals[3], raw_normals[3],
raw_normals[4], raw_normals[4], raw_normals[4], raw_normals[4],
raw_normals[5], raw_normals[5], raw_normals[5], raw_normals[5]
};
int16_t cube_indices_tris[36];
for (int i = 0, k = 0; i < 36; k += 4) {
cube_indices_tris[i++] = k + 0;
cube_indices_tris[i++] = k + 3;
cube_indices_tris[i++] = k + 1;
cube_indices_tris[i++] = k + 0;
cube_indices_tris[i++] = k + 2;
cube_indices_tris[i++] = k + 3;
}
// const int16_t cube_indices_tris[36] {
// 0, 3, 1, 0, 2, 3,
// };
// const glm::vec3 cube_normals[] = {
// { 0.0f, 0.0f, 1.0f },
// { 0.0f, 0.0f, 1.0f },
// { 0.0f, 0.0f, 1.0f },
// { 0.0f, 0.0f, 1.0f },
// { -1.0f, 0.0f, 0.0f },
// { -1.0f, 0.0f, 0.0f },
// { -1.0f, 0.0f, 0.0f },
// { -1.0f, 0.0f, 0.0f },
// };
// const int16_t cube_indices[] = {
// 3, 1, 0, 2, 3, 0,
// 6, 2, 0, 4, 6, 0,
// };
gpu::Stream::FormatPointer format = std::make_shared<gpu::Stream::Format>();
assert(gpu::Stream::POSITION == 0 && gpu::Stream::NORMAL == 1);
const int BUFFER_SLOT = 0;
format->setAttribute(gpu::Stream::POSITION, BUFFER_SLOT, gpu::Element::VEC3F_XYZ);
format->setAttribute(gpu::Stream::NORMAL, BUFFER_SLOT, gpu::Element::VEC3F_XYZ);
auto vertexBuffer = std::make_shared<gpu::Buffer>(24 * sizeof(glm::vec3), (gpu::Byte*)cube_verts);
auto normalBuffer = std::make_shared<gpu::Buffer>(24 * sizeof(glm::vec3), (gpu::Byte*)cube_normals);
gpu::BufferPointer indexBuffer = std::make_shared<gpu::Buffer>(36 * sizeof(int16_t), (gpu::Byte*)cube_indices_tris);
auto positionElement = format->getAttributes().at(gpu::Stream::POSITION)._element;
auto normalElement = format->getAttributes().at(gpu::Stream::NORMAL)._element;
gpu::BufferView vertexView { vertexBuffer, positionElement };
gpu::BufferView normalView { normalBuffer, normalElement };
// Create shaders
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ simple_vert }));
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel({ simple_frag }));
auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
gpu::Shader::BindingSet bindings;
bindings.insert({ "lightPosition", 1 });
if (!gpu::Shader::makeProgram(*shader, bindings)) {
printf("Could not compile shader\n");
if (!vs)
printf("bad vertex shader\n");
if (!fs)
printf("bad fragment shader\n");
if (!shader)
printf("bad shader program\n");
exit(-1);
}
auto state = std::make_shared<gpu::State>();
// state->setAntialiasedLineEnable(true);
state->setMultisampleEnable(true);
state->setDepthTest({ true });
auto pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state));
return std::make_shared<BasicModel>(
std::move(pipeline),
std::move(vertexView),
std::move(normalView),
std::move(indexBuffer),
std::move(format)
);
}
void renderCube(gpu::Batch & batch, const BasicModel & cube) {
batch.setPipeline(cube.pipeline);
batch.setInputFormat(cube.format);
batch.setInputBuffer(gpu::Stream::POSITION, cube.vertices);
batch.setInputBuffer(gpu::Stream::NORMAL, cube.normals);
batch.setIndexBuffer(gpu::INT16, cube.indices, 0);
// batch.drawIndexed(gpu::TRIANGLES, 12);
batch.draw(gpu::TRIANGLES, 24);
}
gpu::ShaderPointer makeShader(const std::string & vertexShaderSrc, const std::string & fragmentShaderSrc, const gpu::Shader::BindingSet & bindings) {
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vertexShaderSrc));
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShaderSrc));
auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
if (!gpu::Shader::makeProgram(*shader, bindings)) {
printf("Could not compile shader\n");
exit(-1);
}
return shader;
}
// Creates an OpenGL window that renders a simple unlit scene using the gpu library and GeometryCache
// Should eventually get refactored into something that supports multiple gpu backends.
class QTestWindow : public QWindow {
Q_OBJECT
QOpenGLContext* _qGlContext{ nullptr };
QSize _size;
gpu::ContextPointer _context;
gpu::PipelinePointer _pipeline;
glm::mat4 _projectionMatrix;
// BasicModelPointer _cubeModel;
RateCounter fps;
QTime _time;
protected:
void renderText();
private:
void resizeWindow(const QSize& size) {
_size = size;
}
public:
QTestWindow() {
setSurfaceType(QSurface::OpenGLSurface);
QSurfaceFormat format;
// Qt Quick may need a depth and stencil buffer. Always make sure these are available.
format.setDepthBufferSize(16);
format.setStencilBufferSize(8);
format.setVersion(4, 1);
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
format.setOption(QSurfaceFormat::DebugContext);
setFormat(format);
_qGlContext = new QOpenGLContext;
_qGlContext->setFormat(format);
_qGlContext->create();
show();
makeCurrent();
gpu::Context::init<gpu::GLBackend>();
_context = std::make_shared<gpu::Context>();
auto shader = makeShader(simple_vert, simple_frag, gpu::Shader::BindingSet {});
auto state = std::make_shared<gpu::State>();
state->setMultisampleEnable(true);
state->setDepthTest(gpu::State::DepthTest { true });
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state));
// Clear screen
gpu::Batch batch;
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, 0.0, 0.5, 1.0 });
_context->render(batch);
// _cubeModel = makeCube();
DependencyManager::set<GeometryCache>();
setFramePosition(QPoint(-1000, 0));
resize(QSize(800, 600));
_time.start();
}
virtual ~QTestWindow() {
}
void draw() {
if (!isVisible()) {
return;
}
makeCurrent();
gpu::Batch batch;
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.0f, 0.0f, 0.0f, 1.0f });
batch.clearDepthFramebuffer(1e4);
batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() });
batch.setProjectionTransform(_projectionMatrix);
double t = _time.elapsed() * 1e-3;
glm::vec3 unitscale { 1.0f };
glm::vec3 up { 0.0f, 1.0f, 0.0f };
glm::vec3 cam_pos { 1.5f * sin(t), 0.0f, 2.0f };
// glm::vec3 camera_focus { 5.0f * cos(t * 0.1f), 0.0f, 0.0f };
glm::vec3 camera_focus { 0.0f, 0.0f, 0.0f };
glm::quat cam_rotation;
// glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, camera_focus, up));
// cam_rotation.w = -cam_rotation.w;
// printf("cam rotation: %f %f %f %f\n", cam_rotation.x, cam_rotation.y, cam_rotation.z, cam_rotation.w);
Transform cam_transform { cam_rotation, unitscale, cam_pos };
batch.setViewTransform(cam_transform);
batch.setPipeline(_pipeline);
auto geometryCache = DependencyManager::get<GeometryCache>();
// Render grid on xz plane (not the optimal way to do things, but w/e)
// Note: GeometryCache::renderGrid will *not* work, as it is apparenly unaffected by batch rotations and renders xy only
batch.setModelTransform(Transform());
for (int i = 0; i < 100; ++i) {
geometryCache->renderLine(batch, { -100.0f, -1.0f, -50.0f + float(i) }, { 100.0f, -1.0f, -50.0f + float(i) }, { 0.35f, 0.25f, 0.15f, 1.0f });
}
for (int i = 0; i < 100; ++i) {
geometryCache->renderLine(batch, { -50.0f + float(i), -1.0f, -100.0f}, { -50.0f + float(i), -1.0f, 100.0f }, { 0.15f, 0.25f, 0.35f, 1.0f });
}
// Render unlit cube + sphere
geometryCache->renderUnitCube(batch);
geometryCache->renderWireCube(batch, 1.0f, { 0.4f, 0.4f, 0.7f, 1.0f });
batch.setModelTransform(Transform().setTranslation({ 1.5f, -0.5f, -0.5f }));
geometryCache->renderSphere(batch, 0.5f, 50, 50, { 0.8f, 0.25f, 0.25f });
_context->render(batch);
_qGlContext->swapBuffers(this);
fps.increment();
if (fps.elapsed() >= 0.5f) {
qDebug() << "FPS: " << fps.rate();
fps.reset();
}
}
void makeCurrent() {
_qGlContext->makeCurrent(this);
}
protected:
void resizeEvent(QResizeEvent* ev) override {
resizeWindow(ev->size());
float fov_degrees = 60.0f;
float aspect_ratio = (float)_size.width() / _size.height();
float near_clip = 0.1f;
float far_clip = 1000.0f;
_projectionMatrix = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip);
}
};
int main(int argc, char** argv) {
QGuiApplication app(argc, argv);
QTestWindow window;
QTimer timer;
timer.setInterval(0);
app.connect(&timer, &QTimer::timeout, &app, [&] {
window.draw();
});
timer.start();
app.exec();
return 0;
}
#include "main.moc"

View file

@ -0,0 +1,29 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple.frag
// fragment shader
//
// Created by Andrzej Kapolka on 9/15/14.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include DeferredBufferWrite.slh@>
<@include model/Material.slh@>
// the interpolated normal
in vec3 _normal;
in vec3 _color;
void main(void) {
Material material = getMaterial();
packDeferredFragment(
normalize(_normal.xyz),
glowIntensity,
_color.rgb,
DEFAULT_SPECULAR, DEFAULT_SHININESS);
}

View file

@ -0,0 +1,36 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple.vert
// vertex shader
//
// Created by Andrzej Kapolka on 9/15/14.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@>
<$declareStandardTransform()$>
// the interpolated normal
out vec3 _normal;
out vec3 _color;
out vec2 _texCoord0;
void main(void) {
_color = inColor.rgb;
_texCoord0 = inTexCoord0.st;
// standard transform
TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
}

View file

@ -196,7 +196,7 @@ bool TextTemplate::grabUntilEndTag(std::istream* str, std::string& grabbed, Tag:
preEnd = Tag::REM;
}
while (!str->eof()) {
while (!str->eof() && !str->fail()) {
// looking for the end of the tag means find the next preEnd
std::string dataToken;
getline((*str), dataToken, preEnd);
@ -233,7 +233,7 @@ bool TextTemplate::stepForward(std::istream* str, std::string& grabbed, std::str
if (grabUntilEndTag(str, tag, tagType)) {
// skip trailing space and new lines only after Command or Remark tag block
if ((tagType == Tag::COMMAND) || (tagType == Tag::REMARK)) {
while (!str->eof()) {
while (!str->eof() && !str->fail()) {
char c = str->peek();
if ((c == ' ') || (c == '\t') || (c == '\n')) {
str->get();