diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index beeaab8567..1dd9d35b66 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -22,6 +22,11 @@ else () set(BUILD_SEQ "dev") endif () +if (WIN32) + add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h + add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines +endif() + configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h") macro(GroupSources curdir) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0ce7698afe..192db1afd4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -993,11 +993,12 @@ void Application::paintGL() { } displaySide(&renderArgs, _myCamera); - renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; - if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { + + if (_myCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { + renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; renderRearViewMirror(&renderArgs, _mirrorViewRect); + renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; } - renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; { auto geometryCache = DependencyManager::get(); @@ -3113,19 +3114,7 @@ void Application::updateShadowMap(RenderArgs* renderArgs) { #endif } -static gpu::Light defaultLight{ - vec3( 0.525f, 0.525f, 0.6f), // ambient - vec3( 0.6f, 0.525f, 0.525f), // diffuse - vec4(0.08f, 0.08f, 0.08f, 1.0f), // specular - vec4( 0, 0, 0, 0 ), // position - 96 // shininess -}; - void Application::setupWorldLight(RenderArgs* renderArgs) { - gpu::Batch batch; - defaultLight._position = vec4(getSunDirection(), 0); - batch.setLight(0, defaultLight); - renderArgs->_context->render(batch); } bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { @@ -3624,9 +3613,8 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { } void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) { + auto originalViewport = renderArgs->_viewport; // Grab current viewport to reset it at the end - int viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); float aspect = (float)region.width() / region.height(); float fov = MIRROR_FIELD_OF_VIEW; @@ -3663,35 +3651,45 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)); _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); + // set the bounds of rear mirror view + gpu::Vec4i viewport; if (billboard) { QSize size = DependencyManager::get()->getFrameBufferSize(); - glViewport(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); - glScissor(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); - renderArgs->_viewport = glm::ivec4(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); + viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); } else { // if not rendering the billboard, the region is in device independent coordinates; must convert to device QSize size = DependencyManager::get()->getFrameBufferSize(); float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio; - glViewport(x, size.height() - y - height, width, height); - glScissor(x, size.height() - y - height, width, height); - - renderArgs->_viewport = glm::ivec4(x, size.height() - y - height, width, height); + viewport = gpu::Vec4i(x, size.height() - y - height, width, height); } + renderArgs->_viewport = viewport; + + { + gpu::Batch batch; + batch.setViewportTransform(viewport); + batch.setStateScissorRect(viewport); + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_COLOR0 | + gpu::Framebuffer::BUFFER_COLOR1 | + gpu::Framebuffer::BUFFER_COLOR2 | + gpu::Framebuffer::BUFFER_DEPTH, + vec4(vec3(0), 1), 1.0, 0.0, true); + // Viewport is assigned to the size of the framebuffer + renderArgs->_context->render(batch); + } + bool updateViewFrustum = false; updateProjectionMatrix(_mirrorCamera, updateViewFrustum); - glEnable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // render rear mirror view displaySide(renderArgs, _mirrorCamera, true, billboard); - - // reset Viewport and projection matrix - renderArgs->_viewport = glm::ivec4(viewport[0], viewport[1], viewport[2], viewport[3]); - glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); - glDisable(GL_SCISSOR_TEST); - updateProjectionMatrix(_myCamera, updateViewFrustum); + //{ + // gpu::Batch batch; + // renderArgs->_viewport = originalViewport; + // batch.setViewportTransform(originalViewport); + // renderArgs->_context->render(batch); + //} } void Application::resetSensors() { diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index f8d530bb74..01c3c4ade7 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -13,6 +13,9 @@ #include +#include + + #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" @@ -301,13 +304,3 @@ void push_back(Batch::Params& params, const vec4& v) { params.push_back(v.z); params.push_back(v.a); } - -void Batch::setLight(uint8_t index, const Light& light) { - ADD_COMMAND(setLight); - _params.push_back(index); - push_back(_params, light._ambientColor); - push_back(_params, light._diffuseColor); - push_back(_params, light._position); - push_back(_params, light._specularColor); - _params.push_back(light._shininess); -} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 3954127783..2f1d2e8ece 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -14,7 +14,6 @@ #include #include "Framebuffer.h" -#include "Light.h" #include "Pipeline.h" #include "Query.h" #include "Stream.h" @@ -77,8 +76,6 @@ public: void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset); void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView - void setLight(uint8_t index, const Light& light); - // Transform Stage // Vertex position is transformed by ModelTransform from object space to world space // Then by the inverse of the ViewTransform from world space to eye space @@ -172,8 +169,6 @@ public: COMMAND_setInputBuffer, COMMAND_setIndexBuffer, - COMMAND_setLight, - COMMAND_setModelTransform, COMMAND_setViewTransform, COMMAND_setProjectionTransform, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index f6b9bb8706..adebee2f20 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -26,8 +26,6 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setInputBuffer), (&::gpu::GLBackend::do_setIndexBuffer), - (&::gpu::GLBackend::do_setLight), - (&::gpu::GLBackend::do_setModelTransform), (&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setProjectionTransform), diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index eab880f14d..60c01a815c 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -253,8 +253,6 @@ protected: void do_setInputBuffer(Batch& batch, uint32 paramOffset); void do_setIndexBuffer(Batch& batch, uint32 paramOffset); - void do_setLight(Batch& batch, uint32 paramOffset); - void initInput(); void killInput(); void syncInputStateCache(); diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 59719bd000..229b29cd43 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -305,24 +305,3 @@ void popParam(Batch::Params& params, uint32& paramOffset, V& v) { v[i] = params[paramOffset++]._float; } } - -void GLBackend::do_setLight(Batch& batch, uint32 paramOffset) { - int index = batch._params[paramOffset++]._uint; - gpu::Light light; - popParam(batch._params, paramOffset, light._ambientColor); - popParam(batch._params, paramOffset, light._diffuseColor); - popParam(batch._params, paramOffset, light._position); - popParam(batch._params, paramOffset, light._specularColor); - light._shininess = batch._params[paramOffset++]._int; - - // Setup 3D lights (after the camera transform, so that they are positioned in world space) - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - glLightfv(GL_LIGHT0 + index, GL_POSITION, &light._position.x); - glLightfv(GL_LIGHT0 + index, GL_AMBIENT, &light._ambientColor.r); - glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, &light._diffuseColor.r); - glLightfv(GL_LIGHT0 + index, GL_SPECULAR, &light._specularColor.r); - glMaterialfv(GL_FRONT + index, GL_SPECULAR, &light._specularColor.r); - glMateriali(GL_FRONT + index, GL_SHININESS, light._shininess); -} - diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu/src/gpu/GLBackendTransform.cpp index 01229cb317..2378edb095 100755 --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu/src/gpu/GLBackendTransform.cpp @@ -32,6 +32,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) { void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) { memcpy(&_transform._viewport, batch.editData(batch._params[paramOffset]._uint), sizeof(Vec4i)); + glViewport(_transform._viewport.x, _transform._viewport.y, _transform._viewport.z, _transform._viewport.w); _transform._invalidViewport = true; } diff --git a/libraries/gpu/src/gpu/Light.h b/libraries/gpu/src/gpu/Light.h deleted file mode 100644 index 6ce8eb637f..0000000000 --- a/libraries/gpu/src/gpu/Light.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by Bradley Austin Davis 2015/07/18 -// 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 -// -#pragma once -#ifndef hifi_gpu_Light_h -#define hifi_gpu_Light_h - -#include - -namespace gpu { - -struct Light { - Light() {} - Light(const vec3& ambient, const vec3& diffuse, const vec4& position, const vec4& specular = vec4(), int shininess = 0) : - _ambientColor(ambient), _diffuseColor(diffuse), _position(position), _specularColor(specular), _shininess(shininess) { - - } - vec3 _ambientColor; - vec3 _diffuseColor; - vec4 _position; - vec4 _specularColor; - int _shininess{0}; -}; - -} - -#endif