From fe74ec3f89f3a8be875de527311b5c91efaeed4a Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Fri, 31 Jul 2015 14:42:45 -0700 Subject: [PATCH 01/24] copied starting point from render-utils-test --- tests/gpu-test/CMakeLists.txt | 13 ++ tests/gpu-test/src/main.cpp | 219 ++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 tests/gpu-test/CMakeLists.txt create mode 100644 tests/gpu-test/src/main.cpp diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt new file mode 100644 index 0000000000..9f423e3645 --- /dev/null +++ b/tests/gpu-test/CMakeLists.txt @@ -0,0 +1,13 @@ + +set(TARGET_NAME gpu-test) + +# This is not a testcase -- just set it up as a regular hifi project +setup_hifi_project(Quick Gui OpenGL) +set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") + +#include_oglplus() + +# link in the shared libraries +link_hifi_libraries(render-utils gpu shared) + +copy_dlls_beside_windows_executable() \ No newline at end of file diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp new file mode 100644 index 0000000000..1724e368d8 --- /dev/null +++ b/tests/gpu-test/src/main.cpp @@ -0,0 +1,219 @@ +// +// 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 +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#include + +class RateCounter { + std::vector 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(); + } +}; + + +const QString& getQmlDir() { + static QString dir; + if (dir.isEmpty()) { + QDir path(__FILE__); + path.cdUp(); + dir = path.cleanPath(path.absoluteFilePath("../../../interface/resources/qml/")) + "/"; + qDebug() << "Qml Path: " << dir; + } + return dir; +} + +// Create a simple OpenGL window that renders text in various ways +class QTestWindow : public QWindow { + Q_OBJECT + + QOpenGLContext* _context{ nullptr }; + QSize _size; + //TextRenderer* _textRenderer[4]; + RateCounter fps; + +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, 5); + format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); + format.setOption(QSurfaceFormat::DebugContext); + + setFormat(format); + + _context = new QOpenGLContext; + _context->setFormat(format); + _context->create(); + + show(); + makeCurrent(); + + gpu::Context::init(); + + + + { + QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); + logger->initialize(); // initializes in the current context, i.e. ctx + logger->enableMessages(); + connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) { + qDebug() << debugMessage; + }); + // logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); + } + qDebug() << (const char*)glGetString(GL_VERSION); + + //_textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false); + //_textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false, + // TextRenderer::SHADOW_EFFECT); + //_textRenderer[2] = TextRenderer::getInstance(MONO_FONT_FAMILY, 48, -1, + // false, TextRenderer::OUTLINE_EFFECT); + //_textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glClearColor(0.2f, 0.2f, 0.2f, 1); + glDisable(GL_DEPTH_TEST); + + makeCurrent(); + + setFramePosition(QPoint(-1000, 0)); + resize(QSize(800, 600)); + } + + virtual ~QTestWindow() { + } + + void draw(); + void makeCurrent() { + _context->makeCurrent(this); + } + +protected: + + void resizeEvent(QResizeEvent* ev) override { + resizeWindow(ev->size()); + } +}; + +#ifndef SERIF_FONT_FAMILY +#define SERIF_FONT_FAMILY "Times New Roman" +#endif + +//static const wchar_t* EXAMPLE_TEXT = L"Hello"; +//static const wchar_t* EXAMPLE_TEXT = L"\xC1y Hello 1.0\ny\xC1 line 2\n\xC1y"; +static const glm::uvec2 QUAD_OFFSET(10, 10); + +static const glm::vec3 COLORS[4] = { { 1.0, 1.0, 1.0 }, { 0.5, 1.0, 0.5 }, { + 1.0, 0.5, 0.5 }, { 0.5, 0.5, 1.0 } }; + + +void QTestWindow::draw() { + if (!isVisible()) { + return; + } + + makeCurrent(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio()); + + _context->swapBuffers(this); + glFinish(); + + fps.increment(); + if (fps.elapsed() >= 2.0f) { + qDebug() << "FPS: " << fps.rate(); + fps.reset(); + } +} + +int main(int argc, char** argv) { + QGuiApplication app(argc, argv); + QTestWindow window; + QTimer timer; + timer.setInterval(1); + app.connect(&timer, &QTimer::timeout, &app, [&] { + window.draw(); + }); + timer.start(); + app.exec(); + return 0; +} + +#include "main.moc" From 883aa7af8dac1f83734803259325b2d9451dfdf5 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Mon, 3 Aug 2015 11:58:38 -0700 Subject: [PATCH 02/24] changed gl calls to gpu:: --- tests/gpu-test/src/main.cpp | 163 ++++++++++++++++++++++++++++-------- 1 file changed, 128 insertions(+), 35 deletions(-) diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 1724e368d8..a4a68c1d84 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -21,20 +21,27 @@ #include #include +#include +#include +#include +//#include + #include -#include +//#include #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include #include #include #include +#include + #include @@ -74,6 +81,15 @@ public: } }; +const char * basicVS = +" varying vec3 pos; " +" void main(void) { " +" gl_Position.xyz = pos; " +" } "; +const char * basicFS = +" void main(void) { " +" gl_FragColor.xyz = vec3(0.7, 0.2, 0.5); " +" } "; const QString& getQmlDir() { static QString dir; @@ -90,8 +106,14 @@ const QString& getQmlDir() { class QTestWindow : public QWindow { Q_OBJECT - QOpenGLContext* _context{ nullptr }; + QOpenGLContext* _qGlContext{ nullptr }; QSize _size; + + gpu::ContextPointer _context; + gpu::PipelinePointer _pipeline; + gpu::BufferPointer _buffer; + gpu::Stream::FormatPointer _format; + //TextRenderer* _textRenderer[4]; RateCounter fps; @@ -117,27 +139,62 @@ public: setFormat(format); - _context = new QOpenGLContext; - _context->setFormat(format); - _context->create(); + _qGlContext = new QOpenGLContext; + _qGlContext->setFormat(format); + _qGlContext->create(); show(); makeCurrent(); gpu::Context::init(); - - - - { - QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); - logger->initialize(); // initializes in the current context, i.e. ctx - logger->enableMessages(); - connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) { - qDebug() << debugMessage; - }); - // logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); + _context = std::make_shared(); + + // Clear screen + gpu::Batch batch; + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, 0.0, 0.5, 1.0 }); + _context->render(batch); + + // Create default shaders + + std::string vsSource (basicVS); + std::string fsSource (basicFS); + + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vsSource)); + auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fsSource)); + auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); + + gpu::Shader::BindingSet bindings; + if (!gpu::Shader::makeProgram(*shader, bindings)) { + printf("Could not compile shader"); + exit(-1); } - qDebug() << (const char*)glGetString(GL_VERSION); + +// auto shader = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); + + auto state = std::make_shared(); + _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state)); + + float z = 10.0f; + const glm::vec3 vertices[] = { + { -1.0f, 1.0f, z }, + { 1.0f, -1.0f, z }, + { -1.0f, -1.0f, z } + }; + _buffer = std::make_shared(sizeof(vertices), (const gpu::Byte*)vertices); + _format = std::make_shared(); + _format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)); + + +// { +// QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); +// logger->initialize(); // initializes in the current context, i.e. ctx +// logger->enableMessages(); +// connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) { +// qDebug() << debugMessage; +// }); +// // logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); +// } +// qDebug() << (const char*)glGetString(GL_VERSION); //_textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false); //_textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false, @@ -146,12 +203,14 @@ public: // false, TextRenderer::OUTLINE_EFFECT); //_textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(0.2f, 0.2f, 0.2f, 1); - glDisable(GL_DEPTH_TEST); +// glEnable(GL_BLEND); +// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// glClearColor(0.2f, 0.2f, 0.2f, 1); +// glDisable(GL_DEPTH_TEST); makeCurrent(); + + _context->syncCache(); setFramePosition(QPoint(-1000, 0)); resize(QSize(800, 600)); @@ -162,7 +221,7 @@ public: void draw(); void makeCurrent() { - _context->makeCurrent(this); + _qGlContext->makeCurrent(this); } protected: @@ -180,8 +239,12 @@ protected: //static const wchar_t* EXAMPLE_TEXT = L"\xC1y Hello 1.0\ny\xC1 line 2\n\xC1y"; static const glm::uvec2 QUAD_OFFSET(10, 10); -static const glm::vec3 COLORS[4] = { { 1.0, 1.0, 1.0 }, { 0.5, 1.0, 0.5 }, { - 1.0, 0.5, 0.5 }, { 0.5, 0.5, 1.0 } }; +static const glm::vec3 COLORS[4] = { + { 1.0, 1.0, 1.0 }, + { 0.5, 1.0, 0.5 }, + { 1.0, 0.5, 0.5 }, + { 0.5, 0.5, 1.0 } +}; void QTestWindow::draw() { @@ -190,15 +253,45 @@ void QTestWindow::draw() { } makeCurrent(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio()); - - _context->swapBuffers(this); - glFinish(); + + gpu::Batch batch; + static int frameNum = 0; + frameNum++; + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, float(frameNum % 60)/60.0f, 0.5, 1.0 }); +// _context->render(batch); + + +//// batch.clear(); +// batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); +// + glm::quat cubeOrientation; +// + batch.setViewTransform(Transform()); + batch.setProjectionTransform(glm::mat4()); +// batch.setProjectionTransform(_viewFrustrum->getProjection()); + batch.setModelTransform(Transform().setRotation(cubeOrientation)); + batch.setPipeline(_pipeline); + batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); + batch.setInputFormat(_format); + batch.draw(gpu::TRIANGLES, 3); + _context->render(batch); +// +//// gpu::Stream::Format format; +//// format.setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::Vec3, gpu::FLOAT, gpu::XYZ)); +//// batch.setInputBuffer(gpu::Stream::POSITION, _trianglePosBuffer, ) +// +// +//// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +//// glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio()); +// +//// _context->swapBuffers(this); +//// glFinish(); +// + _qGlContext->swapBuffers(this); fps.increment(); if (fps.elapsed() >= 2.0f) { - qDebug() << "FPS: " << fps.rate(); + qDebug() << "FPS: " << fps.rate(); // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? fps.reset(); } } @@ -207,7 +300,7 @@ int main(int argc, char** argv) { QGuiApplication app(argc, argv); QTestWindow window; QTimer timer; - timer.setInterval(1); + timer.setInterval(1000 / 120.0f); app.connect(&timer, &QTimer::timeout, &app, [&] { window.draw(); }); From 4e3cfd7c494c338b44f977946dea1fdba43a7235 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Mon, 3 Aug 2015 12:04:02 -0700 Subject: [PATCH 03/24] clear empty frame buffer fix thanks sam! --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index d75d0cf521..94cfd0fe88 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -231,14 +231,21 @@ void GLBackend::do_clearFramebuffer(Batch& batch, uint32 paramOffset) { std::vector 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; } From 9caf4407466c6291f1e6d3900a3cd9392ae6420e Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 4 Aug 2015 12:53:23 -0700 Subject: [PATCH 04/24] basic shader sort-of working (sip) --- tests/gpu-test/CMakeLists.txt | 2 + tests/gpu-test/src/gputest_shaders.h | 48 ++++ tests/gpu-test/src/main.cpp | 334 +++++++++++++++++++-------- 3 files changed, 287 insertions(+), 97 deletions(-) create mode 100644 tests/gpu-test/src/gputest_shaders.h diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index 9f423e3645..c4aaf73eb8 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -1,6 +1,8 @@ set(TARGET_NAME gpu-test) +AUTOSCRIBE_SHADER_LIB(gpu) + # This is not a testcase -- just set it up as a regular hifi project setup_hifi_project(Quick Gui OpenGL) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") diff --git a/tests/gpu-test/src/gputest_shaders.h b/tests/gpu-test/src/gputest_shaders.h new file mode 100644 index 0000000000..911ae4b624 --- /dev/null +++ b/tests/gpu-test/src/gputest_shaders.h @@ -0,0 +1,48 @@ +// +// gputest_shaders.h +// hifi +// +// Created by Seiji Emery on 8/3/15. +// +// + +#ifndef hifi_gputest_shaders_h +#define hifi_gputest_shaders_h + +const std::string & basicVertexShader () { + static std::string src = R"( + +// attribute vec3 position; +// attribute vec3 normal; + + varying vec3 normal; + + void main (void) { +// gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + normal = gl_Normal; + } + + )"; + return src; +} + +const std::string & basicFragmentShader () { + static std::string src = R"( + #version 400 + + varying vec3 normal; + + void main(void) { + gl_FragColor.rgb = vec3(0.7, 0.2, 0.5) + gl_FragCoord.xyz * 0.2; + + vec3 diffuse = vec3(0.7, 0.2, 0.5); + vec3 light_normal = vec3(0.5, -0.5, 0.7); + + gl_FragColor.rgb = diffuse * dot(light_normal, normal); + } + + )"; + return src; +} +#endif diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index a4a68c1d84..a0dabc2516 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -38,13 +38,12 @@ #include #include #include - - #include - - #include +#include "gputest_shaders.h" + + class RateCounter { std::vector times; QElapsedTimer timer; @@ -81,15 +80,6 @@ public: } }; -const char * basicVS = -" varying vec3 pos; " -" void main(void) { " -" gl_Position.xyz = pos; " -" } "; -const char * basicFS = -" void main(void) { " -" gl_FragColor.xyz = vec3(0.7, 0.2, 0.5); " -" } "; const QString& getQmlDir() { static QString dir; @@ -102,6 +92,170 @@ const QString& getQmlDir() { return dir; } +#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 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(); + format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element::VEC3F_XYZ); + format->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, gpu::Element::VEC3F_XYZ); + + auto vertexBuffer = std::make_shared(24 * sizeof(glm::vec3), (gpu::Byte*)cube_verts); + auto normalBuffer = std::make_shared(24 * sizeof(glm::vec3), (gpu::Byte*)cube_normals); + gpu::BufferPointer indexBuffer = std::make_shared(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(basicVertexShader())); + auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(basicFragmentShader())); + auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); + + gpu::Shader::BindingSet bindings; + + 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(); +// state->setAntialiasedLineEnable(true); + state->setMultisampleEnable(true); + state->setDepthTest({ true }); + auto pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state)); + + return std::make_shared( + 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); +} + // Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { Q_OBJECT @@ -111,9 +265,7 @@ class QTestWindow : public QWindow { gpu::ContextPointer _context; gpu::PipelinePointer _pipeline; - gpu::BufferPointer _buffer; - gpu::Stream::FormatPointer _format; - + BasicModelPointer _cubeModel; //TextRenderer* _textRenderer[4]; RateCounter fps; @@ -154,63 +306,10 @@ public: batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, 0.0, 0.5, 1.0 }); _context->render(batch); - // Create default shaders + _cubeModel = makeCube(); - std::string vsSource (basicVS); - std::string fsSource (basicFS); - - auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vsSource)); - auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fsSource)); - auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); - - gpu::Shader::BindingSet bindings; - if (!gpu::Shader::makeProgram(*shader, bindings)) { - printf("Could not compile shader"); - exit(-1); - } - -// auto shader = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); - - auto state = std::make_shared(); - _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state)); - - float z = 10.0f; - const glm::vec3 vertices[] = { - { -1.0f, 1.0f, z }, - { 1.0f, -1.0f, z }, - { -1.0f, -1.0f, z } - }; - _buffer = std::make_shared(sizeof(vertices), (const gpu::Byte*)vertices); - _format = std::make_shared(); - _format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)); - - -// { -// QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); -// logger->initialize(); // initializes in the current context, i.e. ctx -// logger->enableMessages(); -// connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) { -// qDebug() << debugMessage; -// }); -// // logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); -// } -// qDebug() << (const char*)glGetString(GL_VERSION); - - //_textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false); - //_textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false, - // TextRenderer::SHADOW_EFFECT); - //_textRenderer[2] = TextRenderer::getInstance(MONO_FONT_FAMILY, 48, -1, - // false, TextRenderer::OUTLINE_EFFECT); - //_textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24); - -// glEnable(GL_BLEND); -// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -// glClearColor(0.2f, 0.2f, 0.2f, 1); -// glDisable(GL_DEPTH_TEST); - - makeCurrent(); - - _context->syncCache(); +// makeCurrent(); +// _context->syncCache(); setFramePosition(QPoint(-1000, 0)); resize(QSize(800, 600)); @@ -257,41 +356,81 @@ void QTestWindow::draw() { gpu::Batch batch; static int frameNum = 0; frameNum++; - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, float(frameNum % 60)/60.0f, 0.5, 1.0 }); -// _context->render(batch); + float t = frameNum / 120.0f; + + float k = (frameNum % 120) / 120; + float ks = glm::sin(glm::pi() * 2.0f * k); + + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); +// batch.clearDepthFramebuffer(-10000.0f); +// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, float(frameNum % 60)/60.0f, 0.5, 1.0 }); + + batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); -//// batch.clear(); -// batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); -// - glm::quat cubeOrientation; -// - batch.setViewTransform(Transform()); - batch.setProjectionTransform(glm::mat4()); -// batch.setProjectionTransform(_viewFrustrum->getProjection()); - batch.setModelTransform(Transform().setRotation(cubeOrientation)); - batch.setPipeline(_pipeline); - batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); - batch.setInputFormat(_format); - batch.draw(gpu::TRIANGLES, 3); + + // camera at x: 5 * sin(t) + // y: 1, + // z: +10 + // obj at (0, 0, 0) + // camera is looking at obj (using glm::lookAt) + + glm::vec3 up { 0.0f, 1.0f, 0.0f }; + glm::vec3 unitscale { 1.0f }; + + float cube_angle = 0.0f; +// glm::vec3 cube_pos { +// 0.0f, +// 0.0f, +// 0.0f +// }; + glm::vec3 cube_pos { + 20.0f * cos(t * 5.0f), + 10.0f * sin(t * 2.5f) + 1.0f, + -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3 + }; + + // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f; +// glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up); + glm::quat cube_rotation; + Transform cube_transform { cube_rotation, unitscale, cube_pos }; + +// glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f }; + glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f }; + glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up)); + cam_rotation.w = -cam_rotation.w; + Transform cam_transform { cam_rotation, unitscale, cam_pos }; + + float fov_degrees = 120.0f; +// float aspect_ratio = _size.height() / (_size.width() || 1.0f); + float aspect_ratio = 16.0f / 9.0f; + float near_clip = 0.1f; + float far_clip = 1000.0f; + auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); + + batch.setProjectionTransform(projection); + batch.setViewTransform(cam_transform); + batch.setModelTransform(cube_transform); + + batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f})); +// batch.setPipeline(_pipeline); +// batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); +// batch.setInputFormat(_format); +// batch.draw(gpu::TRIANGLES, 3); + + renderCube(batch, *_cubeModel); _context->render(batch); // //// gpu::Stream::Format format; //// format.setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::Vec3, gpu::FLOAT, gpu::XYZ)); //// batch.setInputBuffer(gpu::Stream::POSITION, _trianglePosBuffer, ) -// -// -//// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -//// glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio()); -// -//// _context->swapBuffers(this); -//// glFinish(); -// + _qGlContext->swapBuffers(this); + // glFinish(); fps.increment(); if (fps.elapsed() >= 2.0f) { - qDebug() << "FPS: " << fps.rate(); // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? + qDebug() << "FPS: " << fps.rate() * 2.0f; // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? fps.reset(); } } @@ -300,7 +439,8 @@ int main(int argc, char** argv) { QGuiApplication app(argc, argv); QTestWindow window; QTimer timer; - timer.setInterval(1000 / 120.0f); +// timer.setInterval(1000 / 120.0f); + timer.setInterval(0); app.connect(&timer, &QTimer::timeout, &app, [&] { window.draw(); }); From 5ce84c15ae22317cb14cd0ddfd6125ebcf36506a Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 4 Aug 2015 16:27:07 -0700 Subject: [PATCH 05/24] updated shaders --- tests/gpu-test/src/gputest_shaders.h | 106 +++++++++++++++++++++++---- tests/gpu-test/src/main.cpp | 17 +++-- 2 files changed, 102 insertions(+), 21 deletions(-) diff --git a/tests/gpu-test/src/gputest_shaders.h b/tests/gpu-test/src/gputest_shaders.h index 911ae4b624..376ed3c3f3 100644 --- a/tests/gpu-test/src/gputest_shaders.h +++ b/tests/gpu-test/src/gputest_shaders.h @@ -9,18 +9,96 @@ #ifndef hifi_gputest_shaders_h #define hifi_gputest_shaders_h -const std::string & basicVertexShader () { + +const std::string & standardVertexShader() { static std::string src = R"( -// attribute vec3 position; -// attribute vec3 normal; + in vec4 inPosition; + in vec4 inNormal; + in vec4 inColor; + in vec4 inTexCoord0; + in vec4 inTangent; + in vec4 inSkinClusterIndex; + in vec4 inSkinClusterWeight; + in vec4 inTexCoord1; - varying vec3 normal; + struct TransformObject { + mat4 _model; + mat4 _modelInverse; + }; + + struct TransformCamera { + mat4 _view; + mat4 _viewInverse; + mat4 _projectionViewUntranslated; + mat4 _projection; + mat4 _projectionInverse; + vec4 _viewport; + }; + + uniform transformObjectBuffer { + TransformObject _object; + }; + TransformObject getTransformObject() { + return _object; + } + + uniform transformCameraBuffer { + TransformCamera _camera; + }; + TransformCamera getTransformCamera() { + return _camera; + } + + + const int MAX_TEXCOORDS = 2; + + uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + + out vec4 _position; + out vec3 _normal; + out vec3 _color; + out vec2 _texCoord0; + + )"; + return src; +} + + + + + +const std::string & basicVertexShader () { + static std::string src = R"( + // Basic forward-rendered shading w/ a single directional light source. + + #version 410 + + // I/O + layout (location = 0) in vec3 vertexPosition; + layout (location = 1) in vec3 vertexNormal; + + out vec3 outColor; + + // Light info + uniform vec4 lightPosition; + uniform vec3 kd; // diffuse reflectivity + uniform vec3 ld; // light source intensity + + // Model transforms + uniform mat4 modelViewMatrix; + uniform mat3 normalMatrix; + uniform mat4 projectionMatrix; + uniform mat4 mvp; void main (void) { -// gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - normal = gl_Normal; + vec3 norm = normalize(normalMatrix * vertexNormal); + vec4 eyePos = modelViewMatrix * vec4(vertexPosition, 0); + vec3 s = normalize(vec3(lightPosition - eyePos)); + + outColor = ld * kd * max(dot(s, norm), 0.0); + + gl_Position = mvp * vec4(vertexPosition, 1.0); } )"; @@ -29,17 +107,15 @@ const std::string & basicVertexShader () { const std::string & basicFragmentShader () { static std::string src = R"( - #version 400 + #version 410 - varying vec3 normal; + // Just pass interpolated color value along + in vec3 outColor; + + layout (location = 0) out vec4 fragColor; void main(void) { - gl_FragColor.rgb = vec3(0.7, 0.2, 0.5) + gl_FragCoord.xyz * 0.2; - - vec3 diffuse = vec3(0.7, 0.2, 0.5); - vec3 light_normal = vec3(0.5, -0.5, 0.7); - - gl_FragColor.rgb = diffuse * dot(light_normal, normal); + fragColor = vec4(outColor, 1.0); } )"; diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index a0dabc2516..9fdfc3917d 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -199,15 +199,19 @@ BasicModelPointer makeCube () { // }; gpu::Stream::FormatPointer format = std::make_shared(); - format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element::VEC3F_XYZ); - format->setAttribute(gpu::Stream::NORMAL, gpu::Stream::NORMAL, gpu::Element::VEC3F_XYZ); + + 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(24 * sizeof(glm::vec3), (gpu::Byte*)cube_verts); auto normalBuffer = std::make_shared(24 * sizeof(glm::vec3), (gpu::Byte*)cube_normals); gpu::BufferPointer indexBuffer = std::make_shared(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; + auto normalElement = format->getAttributes().at(gpu::Stream::NORMAL)._element; gpu::BufferView vertexView { vertexBuffer, positionElement }; gpu::BufferView normalView { normalBuffer, normalElement }; @@ -218,7 +222,8 @@ BasicModelPointer makeCube () { 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) @@ -285,8 +290,8 @@ public: // Qt Quick may need a depth and stencil buffer. Always make sure these are available. format.setDepthBufferSize(16); format.setStencilBufferSize(8); - format.setVersion(4, 5); - format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile); + format.setVersion(4, 1); + format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); setFormat(format); From 91bfd07cd43319c2d30ed89ef9666e6e8cc62226 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Wed, 5 Aug 2015 12:35:52 -0700 Subject: [PATCH 06/24] use geometry cache --- tests/gpu-test/src/main.cpp | 233 ++++++++++++++++++++++++++---------- 1 file changed, 169 insertions(+), 64 deletions(-) diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 9fdfc3917d..86f0c86bf1 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "gputest_shaders.h" @@ -249,7 +250,6 @@ BasicModelPointer makeCube () { std::move(format) ); } - void renderCube(gpu::Batch & batch, const BasicModel & cube) { batch.setPipeline(cube.pipeline); @@ -329,7 +329,6 @@ public: } protected: - void resizeEvent(QResizeEvent* ev) override { resizeWindow(ev->size()); } @@ -351,13 +350,30 @@ static const glm::vec3 COLORS[4] = { }; +void renderTestScene (gpu::Batch & batch) { + std::once_flag initFlag; + gpu::PipelinePointer pipeline { nullptr }; + + std::call_once(initFlag, [&](){ + + }); + + auto geometryCache = DependencyManager::get(); + + geometryCache->renderGrid(batch, 4, 4, { 0.2f, 0.3f, 0.7f, 1.0f }); + + + + + +} + + void QTestWindow::draw() { if (!isVisible()) { return; } - makeCurrent(); - gpu::Batch batch; static int frameNum = 0; frameNum++; @@ -365,74 +381,67 @@ void QTestWindow::draw() { float k = (frameNum % 120) / 120; float ks = glm::sin(glm::pi() * 2.0f * k); - - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); -// batch.clearDepthFramebuffer(-10000.0f); -// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, float(frameNum % 60)/60.0f, 0.5, 1.0 }); + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); - - - // camera at x: 5 * sin(t) - // y: 1, - // z: +10 - // obj at (0, 0, 0) - // camera is looking at obj (using glm::lookAt) - - glm::vec3 up { 0.0f, 1.0f, 0.0f }; - glm::vec3 unitscale { 1.0f }; - - float cube_angle = 0.0f; + renderTestScene(batch); +// +// +// // camera at x: 5 * sin(t) +// // y: 1, +// // z: +10 +// // obj at (0, 0, 0) +// // camera is looking at obj (using glm::lookAt) +// +// glm::vec3 up { 0.0f, 1.0f, 0.0f }; +// glm::vec3 unitscale { 1.0f }; +// +// float cube_angle = 0.0f; +// // glm::vec3 cube_pos { +// // 0.0f, +// // 0.0f, +// // 0.0f +// // }; // glm::vec3 cube_pos { -// 0.0f, -// 0.0f, -// 0.0f +// 20.0f * cos(t * 5.0f), +// 10.0f * sin(t * 2.5f) + 1.0f, +// -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3 // }; - glm::vec3 cube_pos { - 20.0f * cos(t * 5.0f), - 10.0f * sin(t * 2.5f) + 1.0f, - -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3 - }; +// +// // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f; +// // glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up); +// glm::quat cube_rotation; +// Transform cube_transform { cube_rotation, unitscale, cube_pos }; +// +// // glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f }; +// glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f }; +// glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up)); +// cam_rotation.w = -cam_rotation.w; +// Transform cam_transform { cam_rotation, unitscale, cam_pos }; +// +// float fov_degrees = 120.0f; +// // float aspect_ratio = _size.height() / (_size.width() || 1.0f); +// float aspect_ratio = 16.0f / 9.0f; +// float near_clip = 0.1f; +// float far_clip = 1000.0f; +// auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); +// +// batch.setProjectionTransform(projection); +// batch.setViewTransform(cam_transform); +// batch.setModelTransform(cube_transform); +// +// batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f})); +// // batch.setPipeline(_pipeline); +// // batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); +// // batch.setInputFormat(_format); +// // batch.draw(gpu::TRIANGLES, 3); +// +// renderCube(batch, *_cubeModel); - // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f; -// glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up); - glm::quat cube_rotation; - Transform cube_transform { cube_rotation, unitscale, cube_pos }; - -// glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f }; - glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f }; - glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up)); - cam_rotation.w = -cam_rotation.w; - Transform cam_transform { cam_rotation, unitscale, cam_pos }; - - float fov_degrees = 120.0f; -// float aspect_ratio = _size.height() / (_size.width() || 1.0f); - float aspect_ratio = 16.0f / 9.0f; - float near_clip = 0.1f; - float far_clip = 1000.0f; - auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); - - batch.setProjectionTransform(projection); - batch.setViewTransform(cam_transform); - batch.setModelTransform(cube_transform); - - batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f})); -// batch.setPipeline(_pipeline); -// batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); -// batch.setInputFormat(_format); -// batch.draw(gpu::TRIANGLES, 3); - - renderCube(batch, *_cubeModel); _context->render(batch); -// -//// gpu::Stream::Format format; -//// format.setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::Vec3, gpu::FLOAT, gpu::XYZ)); -//// batch.setInputBuffer(gpu::Stream::POSITION, _trianglePosBuffer, ) - _qGlContext->swapBuffers(this); - // glFinish(); - + fps.increment(); if (fps.elapsed() >= 2.0f) { qDebug() << "FPS: " << fps.rate() * 2.0f; // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? @@ -440,6 +449,102 @@ void QTestWindow::draw() { } } + + + + + +//void QTestWindow::draw() { +// if (!isVisible()) { +// return; +// } +// +// makeCurrent(); +// +// gpu::Batch batch; +// static int frameNum = 0; +// frameNum++; +// float t = frameNum / 120.0f; +// +// float k = (frameNum % 120) / 120; +// float ks = glm::sin(glm::pi() * 2.0f * k); +// +// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); +//// batch.clearDepthFramebuffer(-10000.0f); +//// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, float(frameNum % 60)/60.0f, 0.5, 1.0 }); +// +// batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); +// +// +// +// // camera at x: 5 * sin(t) +// // y: 1, +// // z: +10 +// // obj at (0, 0, 0) +// // camera is looking at obj (using glm::lookAt) +// +// glm::vec3 up { 0.0f, 1.0f, 0.0f }; +// glm::vec3 unitscale { 1.0f }; +// +// float cube_angle = 0.0f; +//// glm::vec3 cube_pos { +//// 0.0f, +//// 0.0f, +//// 0.0f +//// }; +// glm::vec3 cube_pos { +// 20.0f * cos(t * 5.0f), +// 10.0f * sin(t * 2.5f) + 1.0f, +// -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3 +// }; +// +// // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f; +//// glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up); +// glm::quat cube_rotation; +// Transform cube_transform { cube_rotation, unitscale, cube_pos }; +// +//// glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f }; +// glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f }; +// glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up)); +// cam_rotation.w = -cam_rotation.w; +// Transform cam_transform { cam_rotation, unitscale, cam_pos }; +// +// float fov_degrees = 120.0f; +//// float aspect_ratio = _size.height() / (_size.width() || 1.0f); +// float aspect_ratio = 16.0f / 9.0f; +// float near_clip = 0.1f; +// float far_clip = 1000.0f; +// auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); +// +// batch.setProjectionTransform(projection); +// batch.setViewTransform(cam_transform); +// batch.setModelTransform(cube_transform); +// +// batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f})); +//// batch.setPipeline(_pipeline); +//// batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); +//// batch.setInputFormat(_format); +//// batch.draw(gpu::TRIANGLES, 3); +// +// renderCube(batch, *_cubeModel); +// +// DependencyManager::get()->renderGrid(batch, 4, 4, glm::vec4 { 0.3f, 0.3f, 0.3f, 1.0f }); +// _context->render(batch); +//// +////// gpu::Stream::Format format; +////// format.setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::Vec3, gpu::FLOAT, gpu::XYZ)); +////// batch.setInputBuffer(gpu::Stream::POSITION, _trianglePosBuffer, ) +// +// _qGlContext->swapBuffers(this); +// // glFinish(); +// +// fps.increment(); +// if (fps.elapsed() >= 2.0f) { +// qDebug() << "FPS: " << fps.rate() * 2.0f; // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? +// fps.reset(); +// } +//} + int main(int argc, char** argv) { QGuiApplication app(argc, argv); QTestWindow window; From ba8a15b8931e01fb99dc965193131f61cd1591de Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Wed, 5 Aug 2015 20:02:22 -0700 Subject: [PATCH 07/24] Added primitives (geometryCache) --- tests/gpu-test/CMakeLists.txt | 4 +- tests/gpu-test/src/gputest_simple_frag.h | 105 ++++++++++++++++++ tests/gpu-test/src/gputest_simple_vert.h | 113 +++++++++++++++++++ tests/gpu-test/src/main.cpp | 132 ++++++++++++----------- tests/gpu-test/src/simple.slf | 29 +++++ tests/gpu-test/src/simple.slv | 36 +++++++ 6 files changed, 357 insertions(+), 62 deletions(-) create mode 100644 tests/gpu-test/src/gputest_simple_frag.h create mode 100644 tests/gpu-test/src/gputest_simple_vert.h create mode 100644 tests/gpu-test/src/simple.slf create mode 100644 tests/gpu-test/src/simple.slv diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index c4aaf73eb8..faedca537e 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_NAME gpu-test) -AUTOSCRIBE_SHADER_LIB(gpu) +AUTOSCRIBE_SHADER_LIB(gpu model render gpu-test) # This is not a testcase -- just set it up as a regular hifi project setup_hifi_project(Quick Gui OpenGL) @@ -10,6 +10,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") #include_oglplus() # link in the shared libraries -link_hifi_libraries(render-utils gpu shared) +link_hifi_libraries(render-utils gpu shared networking fbx model animation) copy_dlls_beside_windows_executable() \ No newline at end of file diff --git a/tests/gpu-test/src/gputest_simple_frag.h b/tests/gpu-test/src/gputest_simple_frag.h new file mode 100644 index 0000000000..324e26b082 --- /dev/null +++ b/tests/gpu-test/src/gputest_simple_frag.h @@ -0,0 +1,105 @@ +// File generated by Scribe Wed Aug 5 16:50:24 2015 +#ifndef scribe_simple_frag_h +#define scribe_simple_frag_h + +const char simple_frag[] = R"SCRIBE(#version 410 core +// Generated on Wed Aug 5 16:50:24 2015 +// +// 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 +// + +layout(location = 0) out vec4 _fragColor0; +layout(location = 1) out vec4 _fragColor1; +layout(location = 2) out vec4 _fragColor2; + +// the glow intensity +uniform float glowIntensity; + +// the alpha threshold +uniform float alphaThreshold; + +float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { + return mix(alpha * glowIntensity, 1.0 - alpha * glowIntensity, step(mapAlpha, alphaThreshold)); +} + +const vec3 DEFAULT_SPECULAR = vec3(0.1); +const float DEFAULT_SHININESS = 10; + +void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { + if (alpha != glowIntensity) { + discard; + } + _fragColor0 = vec4(diffuse.rgb, alpha); + _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); + _fragColor2 = vec4(specular, shininess / 128.0); +} + +void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { + if (alpha != glowIntensity) { + discard; + } + + _fragColor0 = vec4(diffuse.rgb, alpha); + //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); + _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); + _fragColor2 = vec4(emissive, shininess / 128.0); +} + +void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { + if (alpha <= alphaThreshold) { + discard; + } + + _fragColor0 = vec4(diffuse.rgb, alpha); + // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); + // _fragColor2 = vec4(specular, shininess / 128.0); +} + + + + + +struct Material { + vec4 _diffuse; + vec4 _specular; + vec4 _emissive; + vec4 _spare; +}; + +uniform materialBuffer { + Material _mat; +}; + +Material getMaterial() { + return _mat; +} + +float getMaterialOpacity(Material m) { return m._diffuse.a; } +vec3 getMaterialDiffuse(Material m) { return m._diffuse.rgb; } +vec3 getMaterialSpecular(Material m) { return m._specular.rgb; } +float getMaterialShininess(Material m) { return m._specular.a; } + + +// 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); +} + +)SCRIBE"; + +#endif diff --git a/tests/gpu-test/src/gputest_simple_vert.h b/tests/gpu-test/src/gputest_simple_vert.h new file mode 100644 index 0000000000..419c91b7c2 --- /dev/null +++ b/tests/gpu-test/src/gputest_simple_vert.h @@ -0,0 +1,113 @@ +// File generated by Scribe Wed Aug 5 16:50:23 2015 +#ifndef scribe_simple_vert_h +#define scribe_simple_vert_h + +const char simple_vert[] = R"SCRIBE(#version 410 core +// Generated on Wed Aug 5 16:50:23 2015 +// +// 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 +// + +in vec4 inPosition; +in vec4 inNormal; +in vec4 inColor; +in vec4 inTexCoord0; +in vec4 inTangent; +in vec4 inSkinClusterIndex; +in vec4 inSkinClusterWeight; +in vec4 inTexCoord1; + + + + + + + + + + + + + + + + + + + + + + +struct TransformObject { + mat4 _model; + mat4 _modelInverse; +}; + +struct TransformCamera { + mat4 _view; + mat4 _viewInverse; + mat4 _projectionViewUntranslated; + mat4 _projection; + mat4 _projectionInverse; + vec4 _viewport; +}; + +uniform transformObjectBuffer { + TransformObject _object; +}; +TransformObject getTransformObject() { + return _object; +} + +uniform transformCameraBuffer { + TransformCamera _camera; +}; +TransformCamera getTransformCamera() { + return _camera; +} + + +// 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 + vec4 _eyepos = (obj._model * inPosition) + vec4(-inPosition.w * cam._viewInverse[3].xyz, 0.0); + gl_Position = cam._projectionViewUntranslated * _eyepos; + } + + + { // transformModelToEyeDir + vec3 mr0 = vec3(obj._modelInverse[0].x, obj._modelInverse[1].x, obj._modelInverse[2].x); + vec3 mr1 = vec3(obj._modelInverse[0].y, obj._modelInverse[1].y, obj._modelInverse[2].y); + vec3 mr2 = vec3(obj._modelInverse[0].z, obj._modelInverse[1].z, obj._modelInverse[2].z); + + vec3 mvc0 = vec3(dot(cam._viewInverse[0].xyz, mr0), dot(cam._viewInverse[0].xyz, mr1), dot(cam._viewInverse[0].xyz, mr2)); + vec3 mvc1 = vec3(dot(cam._viewInverse[1].xyz, mr0), dot(cam._viewInverse[1].xyz, mr1), dot(cam._viewInverse[1].xyz, mr2)); + vec3 mvc2 = vec3(dot(cam._viewInverse[2].xyz, mr0), dot(cam._viewInverse[2].xyz, mr1), dot(cam._viewInverse[2].xyz, mr2)); + + _normal = vec3(dot(mvc0, inNormal.xyz), dot(mvc1, inNormal.xyz), dot(mvc2, inNormal.xyz)); + } + +} +)SCRIBE"; + +#endif diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 86f0c86bf1..126c9dd952 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -43,7 +43,8 @@ #include #include "gputest_shaders.h" - +#include "gputest_simple_frag.h" +#include "gputest_simple_vert.h" class RateCounter { std::vector times; @@ -313,6 +314,8 @@ public: _cubeModel = makeCube(); + DependencyManager::set(); + // makeCurrent(); // _context->syncCache(); @@ -355,19 +358,52 @@ void renderTestScene (gpu::Batch & batch) { gpu::PipelinePointer pipeline { nullptr }; std::call_once(initFlag, [&](){ - + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert))); + auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag))); + auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); + + gpu::Shader::BindingSet bindings; + 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(); + state->setMultisampleEnable(true); + state->setDepthTest({ true }); + pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state)); }); - + batch.setPipeline(pipeline); auto geometryCache = DependencyManager::get(); - geometryCache->renderGrid(batch, 4, 4, { 0.2f, 0.3f, 0.7f, 1.0f }); + float scale = 80.0f; + + batch.setModelTransform(Transform(glm::angleAxis(40.0f, glm::vec3{ 0.0f, 1.0f, 0.0f}), glm::vec3 { scale }, glm::vec3 { -50.0f, -50.0f, 0.0f })); +// geometryCache->renderGrid(batch, 800, 800, { 0.35f, 0.25f, 0.15f, 1.0f }); +// geometryCache->renderGrid(batch, 200, 200, { 0.4f, 0.4f, 0.9f, 1.0f }); - - - -} + 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 }); + } + + 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 }); +// geometryCache->renderWireCube(batch, 1.0f, { 0.2f, 0.2f, 0.2f, 1.0f }); +} void QTestWindow::draw() { if (!isVisible()) { @@ -383,61 +419,37 @@ void QTestWindow::draw() { float ks = glm::sin(glm::pi() * 2.0f * k); batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); + batch.clearDepthFramebuffer(100.0f); batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); +// 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::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 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, 10.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; + Transform cam_transform { cam_rotation, unitscale, cam_pos }; + + + float fov_degrees = 60; +// float aspect_ratio = _size.height() / (_size.width() || 1.0f); + float aspect_ratio = (float)_size.width() / _size.height(); +// float aspect_ratio = 16.0f / 9.0f; + float near_clip = 0.1f; + float far_clip = 1000.0f; + auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); + + batch.setProjectionTransform(projection); + + +// batch.setViewTransform(Transform().setTranslation({ 1.5f * sin(t), 0.5f, 1.0f })); + batch.setViewTransform(cam_transform); + renderTestScene(batch); -// -// -// // camera at x: 5 * sin(t) -// // y: 1, -// // z: +10 -// // obj at (0, 0, 0) -// // camera is looking at obj (using glm::lookAt) -// -// glm::vec3 up { 0.0f, 1.0f, 0.0f }; -// glm::vec3 unitscale { 1.0f }; -// -// float cube_angle = 0.0f; -// // glm::vec3 cube_pos { -// // 0.0f, -// // 0.0f, -// // 0.0f -// // }; -// glm::vec3 cube_pos { -// 20.0f * cos(t * 5.0f), -// 10.0f * sin(t * 2.5f) + 1.0f, -// -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3 -// }; -// -// // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f; -// // glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up); -// glm::quat cube_rotation; -// Transform cube_transform { cube_rotation, unitscale, cube_pos }; -// -// // glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f }; -// glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f }; -// glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up)); -// cam_rotation.w = -cam_rotation.w; -// Transform cam_transform { cam_rotation, unitscale, cam_pos }; -// -// float fov_degrees = 120.0f; -// // float aspect_ratio = _size.height() / (_size.width() || 1.0f); -// float aspect_ratio = 16.0f / 9.0f; -// float near_clip = 0.1f; -// float far_clip = 1000.0f; -// auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); -// -// batch.setProjectionTransform(projection); -// batch.setViewTransform(cam_transform); -// batch.setModelTransform(cube_transform); -// -// batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f})); -// // batch.setPipeline(_pipeline); -// // batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); -// // batch.setInputFormat(_format); -// // batch.draw(gpu::TRIANGLES, 3); -// -// renderCube(batch, *_cubeModel); _context->render(batch); _qGlContext->swapBuffers(this); diff --git a/tests/gpu-test/src/simple.slf b/tests/gpu-test/src/simple.slf new file mode 100644 index 0000000000..31d33a73e4 --- /dev/null +++ b/tests/gpu-test/src/simple.slf @@ -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); +} diff --git a/tests/gpu-test/src/simple.slv b/tests/gpu-test/src/simple.slv new file mode 100644 index 0000000000..99f404eaec --- /dev/null +++ b/tests/gpu-test/src/simple.slv @@ -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)$> +} \ No newline at end of file From dbf94d673be4b128ce510d45fcada3c27b1567e5 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Fri, 7 Aug 2015 12:01:58 -0700 Subject: [PATCH 08/24] Cleanup --- tests/gpu-test/src/main.cpp | 335 ++++++++++-------------------------- 1 file changed, 89 insertions(+), 246 deletions(-) diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 126c9dd952..7cc6adbd50 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -24,16 +24,9 @@ #include #include #include -//#include - #include -//#include #include -//#include -//#include -//#include -//#include #include #include #include @@ -82,18 +75,6 @@ public: } }; - -const QString& getQmlDir() { - static QString dir; - if (dir.isEmpty()) { - QDir path(__FILE__); - path.cdUp(); - dir = path.cleanPath(path.absoluteFilePath("../../../interface/resources/qml/")) + "/"; - qDebug() << "Qml Path: " << dir; - } - return dir; -} - #define MOVE_PARAM(name) decltype(name) && name struct BasicModel { @@ -262,7 +243,21 @@ void renderCube(gpu::Batch & batch, const BasicModel & cube) { batch.draw(gpu::TRIANGLES, 24); } -// Create a simple OpenGL window that renders text in various ways + +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 @@ -271,9 +266,10 @@ class QTestWindow : public QWindow { gpu::ContextPointer _context; gpu::PipelinePointer _pipeline; - BasicModelPointer _cubeModel; - //TextRenderer* _textRenderer[4]; + glm::mat4 _projectionMatrix; +// BasicModelPointer _cubeModel; RateCounter fps; + QTime _time; protected: void renderText(); @@ -307,26 +303,88 @@ public: gpu::Context::init(); _context = std::make_shared(); + auto shader = makeShader(simple_vert, simple_frag, gpu::Shader::BindingSet {}); + auto state = std::make_shared(); + 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(); +// _cubeModel = makeCube(); DependencyManager::set(); - -// makeCurrent(); -// _context->syncCache(); setFramePosition(QPoint(-1000, 0)); resize(QSize(800, 600)); + + _time.start(); } virtual ~QTestWindow() { } - void draw(); + 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(); + + // 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); } @@ -334,234 +392,19 @@ public: protected: void resizeEvent(QResizeEvent* ev) override { resizeWindow(ev->size()); - } -}; - -#ifndef SERIF_FONT_FAMILY -#define SERIF_FONT_FAMILY "Times New Roman" -#endif - -//static const wchar_t* EXAMPLE_TEXT = L"Hello"; -//static const wchar_t* EXAMPLE_TEXT = L"\xC1y Hello 1.0\ny\xC1 line 2\n\xC1y"; -static const glm::uvec2 QUAD_OFFSET(10, 10); - -static const glm::vec3 COLORS[4] = { - { 1.0, 1.0, 1.0 }, - { 0.5, 1.0, 0.5 }, - { 1.0, 0.5, 0.5 }, - { 0.5, 0.5, 1.0 } -}; - - -void renderTestScene (gpu::Batch & batch) { - std::once_flag initFlag; - gpu::PipelinePointer pipeline { nullptr }; - - std::call_once(initFlag, [&](){ - auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(simple_vert))); - auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(simple_frag))); - auto shader = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); - gpu::Shader::BindingSet bindings; - 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(); - state->setMultisampleEnable(true); - state->setDepthTest({ true }); - pipeline = gpu::PipelinePointer(gpu::Pipeline::create(shader, state)); - }); - batch.setPipeline(pipeline); - auto geometryCache = DependencyManager::get(); - - float scale = 80.0f; - - batch.setModelTransform(Transform(glm::angleAxis(40.0f, glm::vec3{ 0.0f, 1.0f, 0.0f}), glm::vec3 { scale }, glm::vec3 { -50.0f, -50.0f, 0.0f })); -// geometryCache->renderGrid(batch, 800, 800, { 0.35f, 0.25f, 0.15f, 1.0f }); -// geometryCache->renderGrid(batch, 200, 200, { 0.4f, 0.4f, 0.9f, 1.0f }); - - - 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 }); - } - - 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 }); -// geometryCache->renderWireCube(batch, 1.0f, { 0.2f, 0.2f, 0.2f, 1.0f }); -} - -void QTestWindow::draw() { - if (!isVisible()) { - return; - } - makeCurrent(); - gpu::Batch batch; - static int frameNum = 0; - frameNum++; - float t = frameNum / 120.0f; - - float k = (frameNum % 120) / 120; - float ks = glm::sin(glm::pi() * 2.0f * k); - - batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); - batch.clearDepthFramebuffer(100.0f); - batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); - -// 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::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 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, 10.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; - Transform cam_transform { cam_rotation, unitscale, cam_pos }; - - - float fov_degrees = 60; -// float aspect_ratio = _size.height() / (_size.width() || 1.0f); - float aspect_ratio = (float)_size.width() / _size.height(); -// float aspect_ratio = 16.0f / 9.0f; + float fov_degrees = 60.0f; + float aspect_ratio = (float)_size.width() / _size.height(); float near_clip = 0.1f; float far_clip = 1000.0f; - auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); - - batch.setProjectionTransform(projection); - - -// batch.setViewTransform(Transform().setTranslation({ 1.5f * sin(t), 0.5f, 1.0f })); - batch.setViewTransform(cam_transform); - - renderTestScene(batch); - - _context->render(batch); - _qGlContext->swapBuffers(this); - - fps.increment(); - if (fps.elapsed() >= 2.0f) { - qDebug() << "FPS: " << fps.rate() * 2.0f; // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? - fps.reset(); + _projectionMatrix = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); } -} - - - - - - -//void QTestWindow::draw() { -// if (!isVisible()) { -// return; -// } -// -// makeCurrent(); -// -// gpu::Batch batch; -// static int frameNum = 0; -// frameNum++; -// float t = frameNum / 120.0f; -// -// float k = (frameNum % 120) / 120; -// float ks = glm::sin(glm::pi() * 2.0f * k); -// -// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 0.1, 0.1, 0.1, 1.0 }); -//// batch.clearDepthFramebuffer(-10000.0f); -//// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLORS, { 1.0, float(frameNum % 60)/60.0f, 0.5, 1.0 }); -// -// batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); -// -// -// -// // camera at x: 5 * sin(t) -// // y: 1, -// // z: +10 -// // obj at (0, 0, 0) -// // camera is looking at obj (using glm::lookAt) -// -// glm::vec3 up { 0.0f, 1.0f, 0.0f }; -// glm::vec3 unitscale { 1.0f }; -// -// float cube_angle = 0.0f; -//// glm::vec3 cube_pos { -//// 0.0f, -//// 0.0f, -//// 0.0f -//// }; -// glm::vec3 cube_pos { -// 20.0f * cos(t * 5.0f), -// 10.0f * sin(t * 2.5f) + 1.0f, -// -15.0f + float(int(t * int(1e3)) % int(1e4)) / 1e3 -// }; -// -// // float cube_angle = 360.0f * k * 1.25 + 120.0f * k * 0.1f; -//// glm::quat cube_rotation = glm::angleAxis(glm::radians(cube_angle), up); -// glm::quat cube_rotation; -// Transform cube_transform { cube_rotation, unitscale, cube_pos }; -// -//// glm::vec3 cam_pos { 0.0f, 0.0f, -10.0f }; -// glm::vec3 cam_pos { 5.0f * sin(t * 0.1f), 1.0f, -10.0f }; -// glm::quat cam_rotation = glm::quat_cast(glm::lookAt(cam_pos, cube_pos, up)); -// cam_rotation.w = -cam_rotation.w; -// Transform cam_transform { cam_rotation, unitscale, cam_pos }; -// -// float fov_degrees = 120.0f; -//// float aspect_ratio = _size.height() / (_size.width() || 1.0f); -// float aspect_ratio = 16.0f / 9.0f; -// float near_clip = 0.1f; -// float far_clip = 1000.0f; -// auto projection = glm::perspective(glm::radians(fov_degrees), aspect_ratio, near_clip, far_clip); -// -// batch.setProjectionTransform(projection); -// batch.setViewTransform(cam_transform); -// batch.setModelTransform(cube_transform); -// -// batch.setModelTransform(Transform().setTranslation({ 20.0f * cos(t * 5.0f), 10.0f * sin(t * 2.5f + 1.0f), -15.0f + float(int(t * 1000) % 10000) / 1e3f})); -//// batch.setPipeline(_pipeline); -//// batch.setInputBuffer(gpu::Stream::POSITION, _buffer, 0, 3); -//// batch.setInputFormat(_format); -//// batch.draw(gpu::TRIANGLES, 3); -// -// renderCube(batch, *_cubeModel); -// -// DependencyManager::get()->renderGrid(batch, 4, 4, glm::vec4 { 0.3f, 0.3f, 0.3f, 1.0f }); -// _context->render(batch); -//// -////// gpu::Stream::Format format; -////// format.setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::Vec3, gpu::FLOAT, gpu::XYZ)); -////// batch.setInputBuffer(gpu::Stream::POSITION, _trianglePosBuffer, ) -// -// _qGlContext->swapBuffers(this); -// // glFinish(); -// -// fps.increment(); -// if (fps.elapsed() >= 2.0f) { -// qDebug() << "FPS: " << fps.rate() * 2.0f; // This prints out the frames per 2 secs (ie. half of the actual fps) bug...? -// fps.reset(); -// } -//} +}; int main(int argc, char** argv) { QGuiApplication app(argc, argv); QTestWindow window; QTimer timer; -// timer.setInterval(1000 / 120.0f); timer.setInterval(0); app.connect(&timer, &QTimer::timeout, &app, [&] { window.draw(); From 14a76525b18e686d3c14c9c84f2bc0fa5c71df2a Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Fri, 21 Aug 2015 16:56:26 -0700 Subject: [PATCH 09/24] script dependency...? (GeometryCache -> AnimationCache -> networking, fbx, model, animation, script... >.>) --- tests/gpu-test/CMakeLists.txt | 2 +- tests/gpu-test/src/main.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index faedca537e..944c54a810 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -10,6 +10,6 @@ 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) +link_hifi_libraries(render-utils gpu shared networking fbx model animation script) copy_dlls_beside_windows_executable() \ No newline at end of file diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 7cc6adbd50..1a95d08902 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -243,7 +243,6 @@ void renderCube(gpu::Batch & batch, const BasicModel & cube) { 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)); From e601484b17ff8219ab94ce79410a8cb6e7864c3a Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Fri, 21 Aug 2015 17:24:34 -0700 Subject: [PATCH 10/24] ... --- tests/gpu-test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index 944c54a810..19a41df776 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -4,12 +4,12 @@ set(TARGET_NAME gpu-test) AUTOSCRIBE_SHADER_LIB(gpu model render gpu-test) # This is not a testcase -- just set it up as a regular hifi project -setup_hifi_project(Quick Gui OpenGL) +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) +link_hifi_libraries(render-utils gpu shared networking fbx model animation script-engine) copy_dlls_beside_windows_executable() \ No newline at end of file From 691cb48a08af1f36aeb0707aac17e2c0d27d5fac Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Mon, 24 Aug 2015 11:26:56 -0700 Subject: [PATCH 11/24] Fixed to use standard shaders from render-utils --- tests/gpu-test/src/gputest_shaders.h | 124 ----------------------- tests/gpu-test/src/gputest_simple_frag.h | 105 ------------------- tests/gpu-test/src/gputest_simple_vert.h | 113 --------------------- tests/gpu-test/src/main.cpp | 9 +- tests/gpu-test/src/simple.slf | 29 ------ tests/gpu-test/src/simple.slv | 36 ------- 6 files changed, 4 insertions(+), 412 deletions(-) delete mode 100644 tests/gpu-test/src/gputest_shaders.h delete mode 100644 tests/gpu-test/src/gputest_simple_frag.h delete mode 100644 tests/gpu-test/src/gputest_simple_vert.h delete mode 100644 tests/gpu-test/src/simple.slf delete mode 100644 tests/gpu-test/src/simple.slv diff --git a/tests/gpu-test/src/gputest_shaders.h b/tests/gpu-test/src/gputest_shaders.h deleted file mode 100644 index 376ed3c3f3..0000000000 --- a/tests/gpu-test/src/gputest_shaders.h +++ /dev/null @@ -1,124 +0,0 @@ -// -// gputest_shaders.h -// hifi -// -// Created by Seiji Emery on 8/3/15. -// -// - -#ifndef hifi_gputest_shaders_h -#define hifi_gputest_shaders_h - - -const std::string & standardVertexShader() { - static std::string src = R"( - - in vec4 inPosition; - in vec4 inNormal; - in vec4 inColor; - in vec4 inTexCoord0; - in vec4 inTangent; - in vec4 inSkinClusterIndex; - in vec4 inSkinClusterWeight; - in vec4 inTexCoord1; - - struct TransformObject { - mat4 _model; - mat4 _modelInverse; - }; - - struct TransformCamera { - mat4 _view; - mat4 _viewInverse; - mat4 _projectionViewUntranslated; - mat4 _projection; - mat4 _projectionInverse; - vec4 _viewport; - }; - - uniform transformObjectBuffer { - TransformObject _object; - }; - TransformObject getTransformObject() { - return _object; - } - - uniform transformCameraBuffer { - TransformCamera _camera; - }; - TransformCamera getTransformCamera() { - return _camera; - } - - - const int MAX_TEXCOORDS = 2; - - uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - - out vec4 _position; - out vec3 _normal; - out vec3 _color; - out vec2 _texCoord0; - - )"; - return src; -} - - - - - -const std::string & basicVertexShader () { - static std::string src = R"( - // Basic forward-rendered shading w/ a single directional light source. - - #version 410 - - // I/O - layout (location = 0) in vec3 vertexPosition; - layout (location = 1) in vec3 vertexNormal; - - out vec3 outColor; - - // Light info - uniform vec4 lightPosition; - uniform vec3 kd; // diffuse reflectivity - uniform vec3 ld; // light source intensity - - // Model transforms - uniform mat4 modelViewMatrix; - uniform mat3 normalMatrix; - uniform mat4 projectionMatrix; - uniform mat4 mvp; - - void main (void) { - vec3 norm = normalize(normalMatrix * vertexNormal); - vec4 eyePos = modelViewMatrix * vec4(vertexPosition, 0); - vec3 s = normalize(vec3(lightPosition - eyePos)); - - outColor = ld * kd * max(dot(s, norm), 0.0); - - gl_Position = mvp * vec4(vertexPosition, 1.0); - } - - )"; - return src; -} - -const std::string & basicFragmentShader () { - static std::string src = R"( - #version 410 - - // Just pass interpolated color value along - in vec3 outColor; - - layout (location = 0) out vec4 fragColor; - - void main(void) { - fragColor = vec4(outColor, 1.0); - } - - )"; - return src; -} -#endif diff --git a/tests/gpu-test/src/gputest_simple_frag.h b/tests/gpu-test/src/gputest_simple_frag.h deleted file mode 100644 index 324e26b082..0000000000 --- a/tests/gpu-test/src/gputest_simple_frag.h +++ /dev/null @@ -1,105 +0,0 @@ -// File generated by Scribe Wed Aug 5 16:50:24 2015 -#ifndef scribe_simple_frag_h -#define scribe_simple_frag_h - -const char simple_frag[] = R"SCRIBE(#version 410 core -// Generated on Wed Aug 5 16:50:24 2015 -// -// 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 -// - -layout(location = 0) out vec4 _fragColor0; -layout(location = 1) out vec4 _fragColor1; -layout(location = 2) out vec4 _fragColor2; - -// the glow intensity -uniform float glowIntensity; - -// the alpha threshold -uniform float alphaThreshold; - -float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { - return mix(alpha * glowIntensity, 1.0 - alpha * glowIntensity, step(mapAlpha, alphaThreshold)); -} - -const vec3 DEFAULT_SPECULAR = vec3(0.1); -const float DEFAULT_SHININESS = 10; - -void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { - if (alpha != glowIntensity) { - discard; - } - _fragColor0 = vec4(diffuse.rgb, alpha); - _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - _fragColor2 = vec4(specular, shininess / 128.0); -} - -void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { - if (alpha != glowIntensity) { - discard; - } - - _fragColor0 = vec4(diffuse.rgb, alpha); - //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); - _fragColor2 = vec4(emissive, shininess / 128.0); -} - -void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { - if (alpha <= alphaThreshold) { - discard; - } - - _fragColor0 = vec4(diffuse.rgb, alpha); - // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - // _fragColor2 = vec4(specular, shininess / 128.0); -} - - - - - -struct Material { - vec4 _diffuse; - vec4 _specular; - vec4 _emissive; - vec4 _spare; -}; - -uniform materialBuffer { - Material _mat; -}; - -Material getMaterial() { - return _mat; -} - -float getMaterialOpacity(Material m) { return m._diffuse.a; } -vec3 getMaterialDiffuse(Material m) { return m._diffuse.rgb; } -vec3 getMaterialSpecular(Material m) { return m._specular.rgb; } -float getMaterialShininess(Material m) { return m._specular.a; } - - -// 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); -} - -)SCRIBE"; - -#endif diff --git a/tests/gpu-test/src/gputest_simple_vert.h b/tests/gpu-test/src/gputest_simple_vert.h deleted file mode 100644 index 419c91b7c2..0000000000 --- a/tests/gpu-test/src/gputest_simple_vert.h +++ /dev/null @@ -1,113 +0,0 @@ -// File generated by Scribe Wed Aug 5 16:50:23 2015 -#ifndef scribe_simple_vert_h -#define scribe_simple_vert_h - -const char simple_vert[] = R"SCRIBE(#version 410 core -// Generated on Wed Aug 5 16:50:23 2015 -// -// 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 -// - -in vec4 inPosition; -in vec4 inNormal; -in vec4 inColor; -in vec4 inTexCoord0; -in vec4 inTangent; -in vec4 inSkinClusterIndex; -in vec4 inSkinClusterWeight; -in vec4 inTexCoord1; - - - - - - - - - - - - - - - - - - - - - - -struct TransformObject { - mat4 _model; - mat4 _modelInverse; -}; - -struct TransformCamera { - mat4 _view; - mat4 _viewInverse; - mat4 _projectionViewUntranslated; - mat4 _projection; - mat4 _projectionInverse; - vec4 _viewport; -}; - -uniform transformObjectBuffer { - TransformObject _object; -}; -TransformObject getTransformObject() { - return _object; -} - -uniform transformCameraBuffer { - TransformCamera _camera; -}; -TransformCamera getTransformCamera() { - return _camera; -} - - -// 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 - vec4 _eyepos = (obj._model * inPosition) + vec4(-inPosition.w * cam._viewInverse[3].xyz, 0.0); - gl_Position = cam._projectionViewUntranslated * _eyepos; - } - - - { // transformModelToEyeDir - vec3 mr0 = vec3(obj._modelInverse[0].x, obj._modelInverse[1].x, obj._modelInverse[2].x); - vec3 mr1 = vec3(obj._modelInverse[0].y, obj._modelInverse[1].y, obj._modelInverse[2].y); - vec3 mr2 = vec3(obj._modelInverse[0].z, obj._modelInverse[1].z, obj._modelInverse[2].z); - - vec3 mvc0 = vec3(dot(cam._viewInverse[0].xyz, mr0), dot(cam._viewInverse[0].xyz, mr1), dot(cam._viewInverse[0].xyz, mr2)); - vec3 mvc1 = vec3(dot(cam._viewInverse[1].xyz, mr0), dot(cam._viewInverse[1].xyz, mr1), dot(cam._viewInverse[1].xyz, mr2)); - vec3 mvc2 = vec3(dot(cam._viewInverse[2].xyz, mr0), dot(cam._viewInverse[2].xyz, mr1), dot(cam._viewInverse[2].xyz, mr2)); - - _normal = vec3(dot(mvc0, inNormal.xyz), dot(mvc1, inNormal.xyz), dot(mvc2, inNormal.xyz)); - } - -} -)SCRIBE"; - -#endif diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 1a95d08902..9d2a3327d7 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -35,9 +35,8 @@ #include #include -#include "gputest_shaders.h" -#include "gputest_simple_frag.h" -#include "gputest_simple_vert.h" +#include "../../libraries/render-utils/simple_frag.h" +#include "../../libraries/render-utils/simple_vert.h" class RateCounter { std::vector times; @@ -200,8 +199,8 @@ BasicModelPointer makeCube () { gpu::BufferView normalView { normalBuffer, normalElement }; // Create shaders - auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(basicVertexShader())); - auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(basicFragmentShader())); + 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; diff --git a/tests/gpu-test/src/simple.slf b/tests/gpu-test/src/simple.slf deleted file mode 100644 index 31d33a73e4..0000000000 --- a/tests/gpu-test/src/simple.slf +++ /dev/null @@ -1,29 +0,0 @@ -<@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); -} diff --git a/tests/gpu-test/src/simple.slv b/tests/gpu-test/src/simple.slv deleted file mode 100644 index 99f404eaec..0000000000 --- a/tests/gpu-test/src/simple.slv +++ /dev/null @@ -1,36 +0,0 @@ -<@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)$> -} \ No newline at end of file From bd18951be81cc33b608f0c4255639f42b066a19d Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Mon, 24 Aug 2015 13:13:24 -0700 Subject: [PATCH 12/24] fixed AUTOSCRIBE_SHADER_LIB to work for targets outside of libraries/ --- cmake/macros/SetupHifiProject.cmake | 2 +- tests/gpu-test/CMakeLists.txt | 2 +- tests/gpu-test/src/main.cpp | 4 ++-- tests/gpu-test/src/simple.slf | 29 +++++++++++++++++++++++ tests/gpu-test/src/simple.slv | 36 +++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 tests/gpu-test/src/simple.slf create mode 100644 tests/gpu-test/src/simple.slv diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 1ed0d8a202..18a3a73588 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -23,7 +23,7 @@ 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) diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index 19a41df776..abdbfc07f9 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_NAME gpu-test) -AUTOSCRIBE_SHADER_LIB(gpu model render 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) diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 9d2a3327d7..758d9b29bb 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -35,8 +35,8 @@ #include #include -#include "../../libraries/render-utils/simple_frag.h" -#include "../../libraries/render-utils/simple_vert.h" +#include "simple_frag.h" +#include "simple_vert.h" class RateCounter { std::vector times; diff --git a/tests/gpu-test/src/simple.slf b/tests/gpu-test/src/simple.slf new file mode 100644 index 0000000000..31d33a73e4 --- /dev/null +++ b/tests/gpu-test/src/simple.slf @@ -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); +} diff --git a/tests/gpu-test/src/simple.slv b/tests/gpu-test/src/simple.slv new file mode 100644 index 0000000000..99f404eaec --- /dev/null +++ b/tests/gpu-test/src/simple.slv @@ -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)$> +} \ No newline at end of file From 6f14eb22066897dc8c7ff73fcb691d5dc6f4a737 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 25 Aug 2015 12:35:34 -0700 Subject: [PATCH 13/24] fix for 0 entity avg ping --- interface/src/ui/Stats.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 74e3a8f44f..048f0d0ef9 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -129,8 +129,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) { @@ -143,6 +143,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); From 316ddd68ef6b7b2d355dae0982aa0a44d3688326 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 25 Aug 2015 13:46:50 -0700 Subject: [PATCH 14/24] force cmake autoscribe to use full paths --- cmake/macros/AutoScribeShader.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 51b6b205e8..bec80d55b7 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -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}) From 3d59f8d7e8279c673272df4bca1b7a74339bfe7b Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 25 Aug 2015 14:40:52 -0700 Subject: [PATCH 15/24] changed setup_project to only use the generated shader source files --- cmake/macros/SetupHifiProject.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 18a3a73588..9475daef8f 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -23,7 +23,7 @@ macro(SETUP_HIFI_PROJECT) endforeach() # add the executable, include additional optional sources - add_executable(${TARGET_NAME} ${TARGET_SRCS} "${AUTOMTC_SRC}" "${AUTOSCRIBE_SHADER_LIB_SRC}") + add_executable(${TARGET_NAME} ${TARGET_SRCS} "${AUTOMTC_SRC}" "${AUTOSCRIBE_SHADER_SRC}") set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core) From 62dc83fa32ac1fb9b8bfdcfaf6870348b4adf9dc Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 25 Aug 2015 15:00:21 -0700 Subject: [PATCH 16/24] test --- cmake/macros/SetupHifiProject.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 9475daef8f..2741af0ca4 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -25,6 +25,10 @@ macro(SETUP_HIFI_PROJECT) # add the executable, include additional optional sources add_executable(${TARGET_NAME} ${TARGET_SRCS} "${AUTOMTC_SRC}" "${AUTOSCRIBE_SHADER_SRC}") + if ("${AUTOSCRIBE_SHADER_SRC}" STRGREATER "") + message("Adding autoscribe files to target '${TARGET_NAME}': ${AUTOSCRIBE_SHADER_SRC}") + endif () + set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core) From 248d0729a62834f9560ea280df39f8847508b8b9 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 25 Aug 2015 15:29:36 -0700 Subject: [PATCH 17/24] test --- cmake/macros/SetupHifiProject.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 2741af0ca4..824ca495d5 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -27,6 +27,13 @@ macro(SETUP_HIFI_PROJECT) if ("${AUTOSCRIBE_SHADER_SRC}" STRGREATER "") message("Adding autoscribe files to target '${TARGET_NAME}': ${AUTOSCRIBE_SHADER_SRC}") + + file(GLOB LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/*.h") + if ("${LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR}" STRGREATER "") + message("directory '${CMAKE_CURRENT_BINARY_DIR}' contains files: ${LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR}") + else () + message("directory '${CMAKE_CURRENT_BINARY_DIR}' does not contain any header files") + endif () endif () set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) From 9d3d104ec3aad16415db6edff73edadf4ea707e4 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 25 Aug 2015 16:13:36 -0700 Subject: [PATCH 18/24] Add Desktop object to JavaScript with width and height properties --- interface/src/Application.cpp | 4 +++ .../scripting/DesktopScriptingInterface.cpp | 27 +++++++++++++++++ .../src/scripting/DesktopScriptingInterface.h | 29 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 interface/src/scripting/DesktopScriptingInterface.cpp create mode 100644 interface/src/scripting/DesktopScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c59c24de71..716fd97c78 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -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(); auto bandwidthRecorder = DependencyManager::set(); auto resourceCacheSharedItems = DependencyManager::set(); + auto desktopScriptingInterface = DependencyManager::set(); auto entityScriptingInterface = DependencyManager::set(); auto windowScriptingInterface = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) @@ -3970,6 +3972,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); + scriptEngine->registerGlobalObject("Desktop", DependencyManager::get().data()); + QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get().data()); scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, LocationScriptingInterface::locationSetter, windowValue); diff --git a/interface/src/scripting/DesktopScriptingInterface.cpp b/interface/src/scripting/DesktopScriptingInterface.cpp new file mode 100644 index 0000000000..746cdaf36f --- /dev/null +++ b/interface/src/scripting/DesktopScriptingInterface.cpp @@ -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 +#include + +#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(); +} diff --git a/interface/src/scripting/DesktopScriptingInterface.h b/interface/src/scripting/DesktopScriptingInterface.h new file mode 100644 index 0000000000..be4eaadbfb --- /dev/null +++ b/interface/src/scripting/DesktopScriptingInterface.h @@ -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 + +#include + +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 From 140edd0589e331f46bbdae88441f92bfb28e5938 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 25 Aug 2015 16:21:38 -0700 Subject: [PATCH 19/24] try removing quotes... --- cmake/macros/SetupHifiProject.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 824ca495d5..90d9f4c8ba 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -23,10 +23,10 @@ macro(SETUP_HIFI_PROJECT) endforeach() # add the executable, include additional optional sources - add_executable(${TARGET_NAME} ${TARGET_SRCS} "${AUTOMTC_SRC}" "${AUTOSCRIBE_SHADER_SRC}") + add_executable(${TARGET_NAME} ${TARGET_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC}) - if ("${AUTOSCRIBE_SHADER_SRC}" STRGREATER "") - message("Adding autoscribe files to target '${TARGET_NAME}': ${AUTOSCRIBE_SHADER_SRC}") + if ("${AUTOSCRIBE_SHADER_LIB_SRC}" STRGREATER "") + message("Adding autoscribe files to target '${TARGET_NAME}': ${AUTOSCRIBE_SHADER_LIB_SRC}") file(GLOB LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/*.h") if ("${LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR}" STRGREATER "") From d29a36868839eeec72cacde2a93d16a86ee86c96 Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 25 Aug 2015 16:50:09 -0700 Subject: [PATCH 20/24] removed debug --- cmake/macros/SetupHifiProject.cmake | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cmake/macros/SetupHifiProject.cmake b/cmake/macros/SetupHifiProject.cmake index 90d9f4c8ba..bd6cbef9dc 100644 --- a/cmake/macros/SetupHifiProject.cmake +++ b/cmake/macros/SetupHifiProject.cmake @@ -24,17 +24,6 @@ macro(SETUP_HIFI_PROJECT) # add the executable, include additional optional sources add_executable(${TARGET_NAME} ${TARGET_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC}) - - if ("${AUTOSCRIBE_SHADER_LIB_SRC}" STRGREATER "") - message("Adding autoscribe files to target '${TARGET_NAME}': ${AUTOSCRIBE_SHADER_LIB_SRC}") - - file(GLOB LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/*.h") - if ("${LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR}" STRGREATER "") - message("directory '${CMAKE_CURRENT_BINARY_DIR}' contains files: ${LIST_OF_HEADER_FILES_IN_CURRENT_BUILD_DIR}") - else () - message("directory '${CMAKE_CURRENT_BINARY_DIR}' does not contain any header files") - endif () - endif () set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core) From 0aaa07a2ded462426c26175db133072f03c87916 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 24 Aug 2015 22:55:40 -0700 Subject: [PATCH 21/24] Remove items from the QML version of the menu when they are removed from the main menu --- interface/resources/qml/VrMenu.qml | 22 ++++++ interface/src/Menu.cpp | 3 + libraries/ui/src/VrMenu.cpp | 115 +++++++++++------------------ libraries/ui/src/VrMenu.h | 2 - 4 files changed, 68 insertions(+), 74 deletions(-) diff --git a/interface/resources/qml/VrMenu.qml b/interface/resources/qml/VrMenu.qml index f0b7bf9fd3..ef7ae852d4 100644 --- a/interface/resources/qml/VrMenu.qml +++ b/interface/resources/qml/VrMenu.qml @@ -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); + } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 1c2cdbaa26..9d47df1c73 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -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) { diff --git a/libraries/ui/src/VrMenu.cpp b/libraries/ui/src/VrMenu.cpp index ce4aba83d3..1ede74fc86 100644 --- a/libraries/ui/src/VrMenu.cpp +++ b/libraries/ui/src/VrMenu.cpp @@ -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(); - 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(returnedValue); - return result; -} - -const QObject* VrMenu::findMenuObject(const QString& menuOption) const { - if (menuOption.isEmpty()) { - return _rootMenu; - } - const QObject* result = _rootMenu->findChild(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(); + 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(); 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 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(); - 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(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(); 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 } diff --git a/libraries/ui/src/VrMenu.h b/libraries/ui/src/VrMenu.h index 06a16588af..38e3b54739 100644 --- a/libraries/ui/src/VrMenu.h +++ b/libraries/ui/src/VrMenu.h @@ -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; From f176003dadba3c6eee27e427955391afca1e0c7b Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 24 Aug 2015 23:07:21 -0700 Subject: [PATCH 22/24] Fixing aspect ratio on stereo plugins --- interface/src/Application.cpp | 2 +- .../display-plugins/src/display-plugins/DisplayPlugin.h | 7 ++++++- .../src/display-plugins/stereo/StereoDisplayPlugin.cpp | 6 ++++++ .../src/display-plugins/stereo/StereoDisplayPlugin.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c59c24de71..c2ab150091 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1269,7 +1269,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)); } diff --git a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h index 8ee2d698a6..0696cc6229 100644 --- a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h @@ -8,12 +8,12 @@ #pragma once #include "plugins/Plugin.h" - #include #include #include #include "gpu/GPUConfig.h" +#include "GLMHelpers.h" #include #include @@ -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; diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp index 43c3b727c4..df691f06f3 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp @@ -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()); +} diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h index 2009c32e1c..86f35c1260 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h @@ -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; From 073567558ea3728ed691f6491a9e0c37610cb6e3 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 25 Aug 2015 16:40:13 -0700 Subject: [PATCH 23/24] Fix UserInputMapper event generation --- .../input-plugins/src/input-plugins/UserInputMapper.cpp | 5 ++++- libraries/input-plugins/src/input-plugins/UserInputMapper.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index b7533f39ec..fabb488ab4 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -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 diff --git a/libraries/input-plugins/src/input-plugins/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h index 184b8d4776..464c39b64c 100755 --- a/libraries/input-plugins/src/input-plugins/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -248,6 +248,7 @@ protected: std::vector _actionStates = std::vector(NUM_ACTIONS, 0.0f); std::vector _actionScales = std::vector(NUM_ACTIONS, 1.0f); + std::vector _lastActionStates = std::vector(NUM_ACTIONS, 0.0f); std::vector _poseStates = std::vector(NUM_ACTIONS); glm::mat4 _sensorToWorldMat; From d311e4f2ea3a2f08cf9c05d60314125a9298ccd9 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 24 Aug 2015 12:37:52 -0700 Subject: [PATCH 24/24] Fixing problems reported by static analysis tool --- .../src/AssignmentActionFactory.cpp | 3 +-- .../octree/OctreeInboundPacketProcessor.cpp | 3 --- assignment-client/src/octree/OctreeServer.cpp | 8 +++---- interface/src/Application.cpp | 1 - interface/src/GLCanvas.cpp | 2 +- interface/src/ModelSelector.cpp | 5 ++--- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/ui/OctreeStatsDialog.cpp | 1 - libraries/animation/src/JointState.h | 3 ++- libraries/audio/src/AudioBuffer.h | 6 ++--- libraries/audio/src/AudioFilterBank.h | 4 ++-- libraries/audio/src/AudioRingBuffer.h | 2 +- libraries/fbx/src/FBXReader.cpp | 1 + libraries/gpu/src/gpu/Framebuffer.h | 2 +- .../input-plugins/ViveControllerManager.cpp | 6 ++--- libraries/octree/src/CoverageMap.cpp | 2 +- libraries/octree/src/Octree.cpp | 3 ++- libraries/render-utils/src/TextureCache.cpp | 1 + libraries/script-engine/src/WebSocketClass.h | 4 +++- libraries/shared/src/Extents.cpp | 4 ++-- libraries/shared/src/Extents.h | 11 +++++----- libraries/shared/src/GLMHelpers.cpp | 18 +++++++++++++++ libraries/shared/src/GLMHelpers.h | 22 +++++++++++++++++++ libraries/shared/src/LogHandler.cpp | 12 +++++----- libraries/shared/src/LogHandler.h | 8 +++---- libraries/shared/src/RingBufferHistory.h | 2 +- libraries/shared/src/Transform.cpp | 2 +- tools/scribe/src/TextTemplate.cpp | 4 ++-- 28 files changed, 89 insertions(+), 53 deletions(-) diff --git a/assignment-client/src/AssignmentActionFactory.cpp b/assignment-client/src/AssignmentActionFactory.cpp index 7c404cbd97..f99e712b72 100644 --- a/assignment-client/src/AssignmentActionFactory.cpp +++ b/assignment-client/src/AssignmentActionFactory.cpp @@ -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, diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index fe61a3945c..06dcee0a41 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -131,9 +131,6 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer 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(); diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 062fe39dbd..a0350622db 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -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; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c59c24de71..47ec83d268 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1425,7 +1425,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) { diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index bfa2dacf3a..66aae5343b 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -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(); } } diff --git a/interface/src/ModelSelector.cpp b/interface/src/ModelSelector.cpp index 8e130cec1a..c4922bdd70 100644 --- a/interface/src/ModelSelector.cpp +++ b/interface/src/ModelSelector.cpp @@ -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() { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 1fec536082..eb72ddd2fd 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -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; diff --git a/interface/src/ui/OctreeStatsDialog.cpp b/interface/src/ui/OctreeStatsDialog.cpp index 89e5899acd..7e6111bd83 100644 --- a/interface/src/ui/OctreeStatsDialog.cpp +++ b/interface/src/ui/OctreeStatsDialog.cpp @@ -437,7 +437,6 @@ void OctreeStatsDialog::showOctreeServersOfType(int& serverCount, NodeType_t ser case MOST: { extraDetails << "
" ; - 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; diff --git a/libraries/animation/src/JointState.h b/libraries/animation/src/JointState.h index 694700338d..8d2c1a7cd0 100644 --- a/libraries/animation/src/JointState.h +++ b/libraries/animation/src/JointState.h @@ -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(); diff --git a/libraries/audio/src/AudioBuffer.h b/libraries/audio/src/AudioBuffer.h index d2f7c50c91..558d686861 100644 --- a/libraries/audio/src/AudioBuffer.h +++ b/libraries/audio/src/AudioBuffer.h @@ -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]; } } diff --git a/libraries/audio/src/AudioFilterBank.h b/libraries/audio/src/AudioFilterBank.h index a581b79b98..4ea5a3568a 100644 --- a/libraries/audio/src/AudioFilterBank.h +++ b/libraries/audio/src/AudioFilterBank.h @@ -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); } } diff --git a/libraries/audio/src/AudioRingBuffer.h b/libraries/audio/src/AudioRingBuffer.h index cc8743de16..e4391d6029 100644 --- a/libraries/audio/src/AudioRingBuffer.h +++ b/libraries/audio/src/AudioRingBuffer.h @@ -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; } diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index f0d13f8792..8bbe8dafd8 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -2003,6 +2003,7 @@ FBXGeometry* extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping material._material = make_shared(); 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 { diff --git a/libraries/gpu/src/gpu/Framebuffer.h b/libraries/gpu/src/gpu/Framebuffer.h index 6f2b762bb0..310255af9f 100755 --- a/libraries/gpu/src/gpu/Framebuffer.h +++ b/libraries/gpu/src/gpu/Framebuffer.h @@ -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. diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp index e76983cce9..3aef37e502 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp @@ -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); diff --git a/libraries/octree/src/CoverageMap.cpp b/libraries/octree/src/CoverageMap.cpp index b1feaff6c0..626d4bcf1a 100644 --- a/libraries/octree/src/CoverageMap.cpp +++ b/libraries/octree/src/CoverageMap.cpp @@ -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? diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 267769ad49..93933c5301 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -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())); diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index deeec58f49..c4fb4c9989 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -621,6 +621,7 @@ QSharedPointer 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))); diff --git a/libraries/script-engine/src/WebSocketClass.h b/libraries/script-engine/src/WebSocketClass.h index 8ba8ecf362..dbc9729c61 100644 --- a/libraries/script-engine/src/WebSocketClass.h +++ b/libraries/script-engine/src/WebSocketClass.h @@ -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; } diff --git a/libraries/shared/src/Extents.cpp b/libraries/shared/src/Extents.cpp index ad00683cf2..10f97cc337 100644 --- a/libraries/shared/src/Extents.cpp +++ b/libraries/shared/src/Extents.cpp @@ -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 { diff --git a/libraries/shared/src/Extents.h b/libraries/shared/src/Extents.h index 3d5a2dbcec..07fad60a04 100644 --- a/libraries/shared/src/Extents.h +++ b/libraries/shared/src/Extents.h @@ -18,14 +18,15 @@ #include #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) { diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 138d3f2c20..8c58928de5 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -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_MIN }; +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) diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index 79addbc5f1..4b03ed2525 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -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. diff --git a/libraries/shared/src/LogHandler.cpp b/libraries/shared/src/LogHandler.cpp index 60cddb5cfe..d1f23531cb 100644 --- a/libraries/shared/src/LogHandler.cpp +++ b/libraries/shared/src/LogHandler.cpp @@ -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: diff --git a/libraries/shared/src/LogHandler.h b/libraries/shared/src/LogHandler.h index 914cad212d..6af721f96c 100644 --- a/libraries/shared/src/LogHandler.h +++ b/libraries/shared/src/LogHandler.h @@ -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 }; diff --git a/libraries/shared/src/RingBufferHistory.h b/libraries/shared/src/RingBufferHistory.h index c0bd1e2a6e..c5222b9c39 100644 --- a/libraries/shared/src/RingBufferHistory.h +++ b/libraries/shared/src/RingBufferHistory.h @@ -174,7 +174,7 @@ public: } bool operator<=(const Iterator& rhs) { - return age() < rhs.age(); + return age() <= rhs.age(); } bool operator>=(const Iterator& rhs) { diff --git a/libraries/shared/src/Transform.cpp b/libraries/shared/src/Transform.cpp index a00761fd50..4b2a481f41 100644 --- a/libraries/shared/src/Transform.cpp +++ b/libraries/shared/src/Transform.cpp @@ -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 diff --git a/tools/scribe/src/TextTemplate.cpp b/tools/scribe/src/TextTemplate.cpp index c468df278b..e7537508bc 100755 --- a/tools/scribe/src/TextTemplate.cpp +++ b/tools/scribe/src/TextTemplate.cpp @@ -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();