From a626191f42176cb23974c4c7dfb448433dd9bc10 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 22 Jul 2015 11:44:24 -0700 Subject: [PATCH 1/6] merging correctly --- .../render-utils/src/FramebufferCache.cpp | 144 ++++++++++++++++++ libraries/render-utils/src/FramebufferCache.h | 67 ++++++++ libraries/render-utils/src/stars.slv | 32 ++++ libraries/render-utils/src/starsGrid.slf | 63 ++++++++ 4 files changed, 306 insertions(+) create mode 100644 libraries/render-utils/src/FramebufferCache.cpp create mode 100644 libraries/render-utils/src/FramebufferCache.h create mode 100644 libraries/render-utils/src/stars.slv create mode 100644 libraries/render-utils/src/starsGrid.slf diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp new file mode 100644 index 0000000000..8e16eeec62 --- /dev/null +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -0,0 +1,144 @@ +// +// FramebufferCache.cpp +// interface/src/renderer +// +// Created by Andrzej Kapolka on 8/6/13. +// Copyright 2013 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 "FramebufferCache.h" + +#include + +#include + +#include +#include +#include +#include +#include "RenderUtilsLogging.h" + +static QQueue _cachedFramebuffers; + +FramebufferCache::FramebufferCache() { +} + +FramebufferCache::~FramebufferCache() { + _cachedFramebuffers.clear(); +} + +void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { + //If the size changed, we need to delete our FBOs + if (_frameBufferSize != frameBufferSize) { + _frameBufferSize = frameBufferSize; + _primaryFramebuffer.reset(); + _primaryDepthTexture.reset(); + _primaryColorTexture.reset(); + _primaryNormalTexture.reset(); + _primarySpecularTexture.reset(); + _cachedFramebuffers.clear(); + } +} + +void FramebufferCache::createPrimaryFramebuffer() { + _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + + auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); + auto width = _frameBufferSize.width(); + auto height = _frameBufferSize.height(); + + auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); + _primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); + + _primaryFramebuffer->setRenderBuffer(0, _primaryColorTexture); + _primaryFramebuffer->setRenderBuffer(1, _primaryNormalTexture); + _primaryFramebuffer->setRenderBuffer(2, _primarySpecularTexture); + + + auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); + _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); + + _primaryFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); +} + +gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { + if (!_primaryFramebuffer) { + createPrimaryFramebuffer(); + } + return _primaryFramebuffer; +} + + + +gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { + if (!_primaryDepthTexture) { + createPrimaryFramebuffer(); + } + return _primaryDepthTexture; +} + +gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { + if (!_primaryColorTexture) { + createPrimaryFramebuffer(); + } + return _primaryColorTexture; +} + +gpu::TexturePointer FramebufferCache::getPrimaryNormalTexture() { + if (!_primaryNormalTexture) { + createPrimaryFramebuffer(); + } + return _primaryNormalTexture; +} + +gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { + if (!_primarySpecularTexture) { + createPrimaryFramebuffer(); + } + return _primarySpecularTexture; +} + +void FramebufferCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { + GLenum buffers[3]; + int bufferCount = 0; + if (color) { + buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; + } + if (normal) { + buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; + } + if (specular) { + buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; + } + batch._glDrawBuffers(bufferCount, buffers); +} + + +gpu::FramebufferPointer FramebufferCache::getFramebuffer() { + if (_cachedFramebuffers.isEmpty()) { + _cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height()))); + } + gpu::FramebufferPointer result = _cachedFramebuffers.front(); + _cachedFramebuffers.pop_front(); + return result; +} + + +void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) { + if (QSize(framebuffer->getSize().x, framebuffer->getSize().y) == _frameBufferSize) { + _cachedFramebuffers.push_back(framebuffer); + } +} + +gpu::FramebufferPointer FramebufferCache::getShadowFramebuffer() { + if (!_shadowFramebuffer) { + const int SHADOW_MAP_SIZE = 2048; + _shadowFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(SHADOW_MAP_SIZE)); + } + return _shadowFramebuffer; +} diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h new file mode 100644 index 0000000000..348c4818f9 --- /dev/null +++ b/libraries/render-utils/src/FramebufferCache.h @@ -0,0 +1,67 @@ +// +// Created by Bradley Austin Davis on 2015/07/20 +// 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_FramebufferCache_h +#define hifi_FramebufferCache_h + +#include + +#include +#include + +namespace gpu { +class Batch; +} + +/// Stores cached textures, including render-to-texture targets. +class FramebufferCache : public Dependency { + SINGLETON_DEPENDENCY + +public: + /// Sets the desired texture resolution for the framebuffer objects. + void setFrameBufferSize(QSize frameBufferSize); + const QSize& getFrameBufferSize() const { return _frameBufferSize; } + + /// Returns a pointer to the primary framebuffer object. This render target includes a depth component, and is + /// used for scene rendering. + gpu::FramebufferPointer getPrimaryFramebuffer(); + + gpu::TexturePointer getPrimaryDepthTexture(); + gpu::TexturePointer getPrimaryColorTexture(); + gpu::TexturePointer getPrimaryNormalTexture(); + gpu::TexturePointer getPrimarySpecularTexture(); + + /// Returns the framebuffer object used to render shadow maps; + gpu::FramebufferPointer getShadowFramebuffer(); + + /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. + void setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal = false, bool specular = false); + + /// Returns a free framebuffer with a single color attachment for temp or intra-frame operations + gpu::FramebufferPointer getFramebuffer(); + // TODO add sync functionality to the release, so we don't reuse a framebuffer being read from + /// Releases a free framebuffer back for reuse + void releaseFramebuffer(const gpu::FramebufferPointer& framebuffer); + +private: + FramebufferCache(); + virtual ~FramebufferCache(); + + void createPrimaryFramebuffer(); + + gpu::FramebufferPointer _primaryFramebuffer; + gpu::TexturePointer _primaryDepthTexture; + gpu::TexturePointer _primaryColorTexture; + gpu::TexturePointer _primaryNormalTexture; + gpu::TexturePointer _primarySpecularTexture; + + gpu::FramebufferPointer _shadowFramebuffer; + QSize _frameBufferSize{ 100, 100 }; +}; + +#endif // hifi_FramebufferCache_h diff --git a/libraries/render-utils/src/stars.slv b/libraries/render-utils/src/stars.slv new file mode 100644 index 0000000000..98241321fa --- /dev/null +++ b/libraries/render-utils/src/stars.slv @@ -0,0 +1,32 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// standardTransformPNTC.slv +// vertex shader +// +// Created by Sam Gateau on 6/10/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 gpu/Transform.slh@> + +<$declareStandardTransform()$> + +varying vec3 varPosition; +varying vec4 varColor; + + +void main(void) { + varColor = gl_Color.rgba; + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToClipPos(cam, obj, gl_Vertex, gl_Position)$> + varPosition = gl_Vertex.xyz; + gl_PointSize = gl_Color.a; +} \ No newline at end of file diff --git a/libraries/render-utils/src/starsGrid.slf b/libraries/render-utils/src/starsGrid.slf new file mode 100644 index 0000000000..12dfd0317c --- /dev/null +++ b/libraries/render-utils/src/starsGrid.slf @@ -0,0 +1,63 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +#line __LINE__ +// Generated on <$_SCRIBE_DATE$> +// stars.frag +// fragment shader +// +// Created by Bradley Austin Davis on 2015/06/19 + +varying vec2 varTexcoord; +varying vec3 varNomral; +varying vec3 varPosition; + +uniform float iGlobalTime; + +const float PI = 3.14159; +const float TAU = 3.14159 * 2.0; +const int latitudeCount = 5; +const float latitudeDist = PI / 2.0 / float(latitudeCount); +const int meridianCount = 4; +const float merdianDist = PI / float(meridianCount); + + +float clampLine(float val, float target) { + return clamp((1.0 - abs((val - target)) - 0.998) * 500.0, 0.0, 1.0); +} + +float latitude(vec2 pos, float angle) { + float result = clampLine(pos.y, angle); + if (angle != 0.0) { + result += clampLine(pos.y, -angle); + } + return result; +} + +float meridian(vec2 pos, float angle) { + return clampLine(pos.x, angle) + clampLine(pos.x + PI, angle); +} + +vec2 toPolar(in vec3 dir) { + vec2 polar = vec2(atan(dir.z, dir.x), asin(dir.y)); + return polar; +} + +void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 fragRayDir ) +{ + vec2 polar = toPolar(fragRayDir); + //polar.x += mod(iGlobalTime / 12.0, PI / 4.0) - PI / 4.0; + float c = 0.0; + for (int i = 0; i < latitudeCount - 1; ++i) { + c += latitude(polar, float(i) * latitudeDist); + } + for (int i = 0; i < meridianCount; ++i) { + c += meridian(polar, float(i) * merdianDist); + } + const vec3 col_lines = vec3(102.0 / 255.0, 136.0 / 255.0, 221.0 / 255.0); + fragColor = vec4(c * col_lines, 0.2); +} + +void main(void) { + mainVR(gl_FragColor, gl_FragCoord.xy, vec3(0.0), normalize(varPosition)); +} + From d9bf3ddb796865076d854644e0dfdaa5b2d3649a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 26 Jul 2015 23:04:03 -0700 Subject: [PATCH 2/6] Merge clean --- .../render-utils/src/FramebufferCache.cpp | 59 +------------------ libraries/render-utils/src/FramebufferCache.h | 19 +----- 2 files changed, 3 insertions(+), 75 deletions(-) diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index be7e794bbb..2c7f99040a 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -34,31 +34,22 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { //If the size changed, we need to delete our FBOs if (_frameBufferSize != frameBufferSize) { _frameBufferSize = frameBufferSize; -<<<<<<< HEAD - _primaryFramebuffer.reset(); -======= + _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 _primaryDepthTexture.reset(); _primaryColorTexture.reset(); _primaryNormalTexture.reset(); _primarySpecularTexture.reset(); -<<<<<<< HEAD -======= _selfieFramebuffer.reset(); ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 _cachedFramebuffers.clear(); } } void FramebufferCache::createPrimaryFramebuffer() { -<<<<<<< HEAD - _primaryFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); -======= + _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto width = _frameBufferSize.width(); @@ -69,34 +60,16 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); _primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler)); -<<<<<<< HEAD - _primaryFramebuffer->setRenderBuffer(0, _primaryColorTexture); - _primaryFramebuffer->setRenderBuffer(1, _primaryNormalTexture); - _primaryFramebuffer->setRenderBuffer(2, _primarySpecularTexture); - -======= _primaryFramebufferFull->setRenderBuffer(0, _primaryColorTexture); _primaryFramebufferFull->setRenderBuffer(1, _primaryNormalTexture); _primaryFramebufferFull->setRenderBuffer(2, _primarySpecularTexture); _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); -<<<<<<< HEAD - _primaryFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); -} -gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { - if (!_primaryFramebuffer) { - createPrimaryFramebuffer(); - } - return _primaryFramebuffer; -} - -======= _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); @@ -119,8 +92,6 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { } return _primaryFramebufferDepthColor; } ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 - gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { if (!_primaryDepthTexture) { @@ -150,25 +121,6 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } -<<<<<<< HEAD -void FramebufferCache::setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal, bool specular) { - GLenum buffers[3]; - int bufferCount = 0; - if (color) { - buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; - } - if (normal) { - buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; - } - if (specular) { - buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; - } - batch._glDrawBuffers(bufferCount, buffers); -} - - -======= ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 gpu::FramebufferPointer FramebufferCache::getFramebuffer() { if (_cachedFramebuffers.isEmpty()) { _cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height()))); @@ -178,10 +130,6 @@ gpu::FramebufferPointer FramebufferCache::getFramebuffer() { return result; } -<<<<<<< HEAD - -======= ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) { if (QSize(framebuffer->getSize().x, framebuffer->getSize().y) == _frameBufferSize) { _cachedFramebuffers.push_back(framebuffer); @@ -195,8 +143,6 @@ gpu::FramebufferPointer FramebufferCache::getShadowFramebuffer() { } return _shadowFramebuffer; } -<<<<<<< HEAD -======= gpu::FramebufferPointer FramebufferCache::getSelfieFramebuffer() { if (!_selfieFramebuffer) { @@ -204,4 +150,3 @@ gpu::FramebufferPointer FramebufferCache::getSelfieFramebuffer() { } return _selfieFramebuffer; } ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index d025622cb9..e9a1bbf8e8 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -30,10 +30,7 @@ public: /// Returns a pointer to the primary framebuffer object. This render target includes a depth component, and is /// used for scene rendering. gpu::FramebufferPointer getPrimaryFramebuffer(); -<<<<<<< HEAD -======= gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 gpu::TexturePointer getPrimaryDepthTexture(); gpu::TexturePointer getPrimaryColorTexture(); @@ -43,20 +40,12 @@ public: /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); -<<<<<<< HEAD - /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. - void setPrimaryDrawBuffers(gpu::Batch& batch, bool color, bool normal = false, bool specular = false); - - /// Returns a free framebuffer with a single color attachment for temp or intra-frame operations - gpu::FramebufferPointer getFramebuffer(); -======= /// Returns the framebuffer object used to render selfie maps; gpu::FramebufferPointer getSelfieFramebuffer(); /// Returns a free framebuffer with a single color attachment for temp or intra-frame operations gpu::FramebufferPointer getFramebuffer(); ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 // TODO add sync functionality to the release, so we don't reuse a framebuffer being read from /// Releases a free framebuffer back for reuse void releaseFramebuffer(const gpu::FramebufferPointer& framebuffer); @@ -67,24 +56,18 @@ private: void createPrimaryFramebuffer(); -<<<<<<< HEAD - gpu::FramebufferPointer _primaryFramebuffer; -======= gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 + gpu::TexturePointer _primaryDepthTexture; gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; gpu::FramebufferPointer _shadowFramebuffer; -<<<<<<< HEAD -======= gpu::FramebufferPointer _selfieFramebuffer; ->>>>>>> f66492b4448218a241b19f0803ab5d6dde499113 QSize _frameBufferSize{ 100, 100 }; }; From d2a6841333b006dcd19b89811b020d06d6e6f98b Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Sun, 26 Jul 2015 23:08:10 -0700 Subject: [PATCH 3/6] merge back clean removing useless changes --- libraries/render-utils/src/FramebufferCache.cpp | 4 +--- libraries/render-utils/src/FramebufferCache.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 2c7f99040a..601d99108d 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -34,7 +34,6 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { //If the size changed, we need to delete our FBOs if (_frameBufferSize != frameBufferSize) { _frameBufferSize = frameBufferSize; - _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); _primaryDepthTexture.reset(); @@ -47,7 +46,6 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { } void FramebufferCache::createPrimaryFramebuffer() { - _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); @@ -69,7 +67,6 @@ void FramebufferCache::createPrimaryFramebuffer() { auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); - _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); @@ -93,6 +90,7 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { return _primaryFramebufferDepthColor; } + gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { if (!_primaryDepthTexture) { createPrimaryFramebuffer(); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index e9a1bbf8e8..c2274a77e8 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -58,7 +58,6 @@ private: gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; - gpu::TexturePointer _primaryDepthTexture; gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryNormalTexture; From 32c253453bd1e05a5714b36a11bae00c423db4a4 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 3 Aug 2015 12:47:51 -0700 Subject: [PATCH 4/6] REsolving the input --- libraries/gpu/src/gpu/GLBackendInput.cpp | 93 +++--------------------- libraries/gpu/src/gpu/GPUConfig.h | 6 +- 2 files changed, 12 insertions(+), 87 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 9a99a912a4..352cb0e7a0 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -57,47 +57,30 @@ void GLBackend::do_setInputBuffer(Batch& batch, uint32 paramOffset) { } } -#if (GPU_FEATURE_PROFILE == GPU_CORE) -#define SUPPORT_VAO -#endif - -#if defined(SUPPORT_VAO) +#if (GPU_INPUT_PROFILE == GPU_CORE_41) +#define NO_SUPPORT_VERTEX_ATTRIB_FORMAT #else +#define SUPPORT_VERTEX_ATTRIB_FORMAT +#endif -#define SUPPORT_LEGACY_OPENGL -#if defined(SUPPORT_LEGACY_OPENGL) -static const int NUM_CLASSIC_ATTRIBS = Stream::TANGENT; -static const GLenum attributeSlotToClassicAttribName[NUM_CLASSIC_ATTRIBS] = { - GL_VERTEX_ARRAY, - GL_NORMAL_ARRAY, - GL_COLOR_ARRAY, - GL_TEXTURE_COORD_ARRAY -}; -#endif -#endif void GLBackend::initInput() { -#if defined(SUPPORT_VAO) if(!_input._defaultVAO) { glGenVertexArrays(1, &_input._defaultVAO); } glBindVertexArray(_input._defaultVAO); (void) CHECK_GL_ERROR(); -#endif } void GLBackend::killInput() { -#if defined(SUPPORT_VAO) glBindVertexArray(0); if(_input._defaultVAO) { glDeleteVertexArrays(1, &_input._defaultVAO); } (void) CHECK_GL_ERROR(); -#endif } void GLBackend::syncInputStateCache() { -#if defined(SUPPORT_VAO) for (int i = 0; i < _input._attributeActivation.size(); i++) { GLint active = 0; glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &active); @@ -105,23 +88,10 @@ void GLBackend::syncInputStateCache() { } //_input._defaultVAO glBindVertexArray(_input._defaultVAO); -#else - size_t i = 0; -#if defined(SUPPORT_LEGACY_OPENGL) - for (; i < NUM_CLASSIC_ATTRIBS; i++) { - _input._attributeActivation[i] = glIsEnabled(attributeSlotToClassicAttribName[i]); - } -#endif - for (; i < _input._attributeActivation.size(); i++) { - GLint active = 0; - glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &active); - _input._attributeActivation[i] = active; - } -#endif } void GLBackend::updateInput() { -#if defined(SUPPORT_VAO) +#if defined(SUPPORT_VERTEX_ATTRIB_FORMAT) if (_input._invalidFormat) { InputStageState::ActivationCache newActivation; @@ -198,16 +168,7 @@ void GLBackend::updateInput() { for (unsigned int i = 0; i < newActivation.size(); i++) { bool newState = newActivation[i]; if (newState != _input._attributeActivation[i]) { -#if defined(SUPPORT_LEGACY_OPENGL) - if (i < NUM_CLASSIC_ATTRIBS) { - if (newState) { - glEnableClientState(attributeSlotToClassicAttribName[i]); - } else { - glDisableClientState(attributeSlotToClassicAttribName[i]); - } - } else -#endif - { + if (newState) { glEnableVertexAttribArray(i); } else { @@ -254,30 +215,9 @@ void GLBackend::updateInput() { GLenum type = _elementTypeToGLType[attrib._element.getType()]; GLuint stride = strides[bufferNum]; GLuint pointer = attrib._offset + offsets[bufferNum]; -#if defined(SUPPORT_LEGACY_OPENGL) - const bool useClientState = slot < NUM_CLASSIC_ATTRIBS; - if (useClientState) { - switch (slot) { - case Stream::POSITION: - glVertexPointer(count, type, stride, reinterpret_cast(pointer)); - break; - case Stream::NORMAL: - glNormalPointer(type, stride, reinterpret_cast(pointer)); - break; - case Stream::COLOR: - glColorPointer(count, type, stride, reinterpret_cast(pointer)); - break; - case Stream::TEXCOORD: - glTexCoordPointer(count, type, stride, reinterpret_cast(pointer)); - break; - }; - } else -#endif - { - GLboolean isNormalized = attrib._element.isNormalized(); - glVertexAttribPointer(slot, count, type, isNormalized, stride, + GLboolean isNormalized = attrib._element.isNormalized(); + glVertexAttribPointer(slot, count, type, isNormalized, stride, reinterpret_cast(pointer)); - } (void) CHECK_GL_ERROR(); } } @@ -298,28 +238,13 @@ void GLBackend::resetInputStage() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); (void) CHECK_GL_ERROR(); - -#if defined(SUPPORT_VAO) - // TODO -#else glBindBuffer(GL_ARRAY_BUFFER, 0); - size_t i = 0; -#if defined(SUPPORT_LEGACY_OPENGL) - for (; i < NUM_CLASSIC_ATTRIBS; i++) { - glDisableClientState(attributeSlotToClassicAttribName[i]); - } - glVertexPointer(4, GL_FLOAT, 0, 0); - glNormalPointer(GL_FLOAT, 0, 0); - glColorPointer(4, GL_FLOAT, 0, 0); - glTexCoordPointer(4, GL_FLOAT, 0, 0); -#endif - for (; i < _input._attributeActivation.size(); i++) { + for (int i = 0; i < _input._attributeActivation.size(); i++) { glDisableVertexAttribArray(i); glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, 0, 0); } -#endif // Reset vertex buffer and format _input._format.reset(); diff --git a/libraries/gpu/src/gpu/GPUConfig.h b/libraries/gpu/src/gpu/GPUConfig.h index 5de41c1d13..f63474e13d 100644 --- a/libraries/gpu/src/gpu/GPUConfig.h +++ b/libraries/gpu/src/gpu/GPUConfig.h @@ -22,14 +22,14 @@ #include "../GL/glew.h" #define GPU_FEATURE_PROFILE GPU_CORE -#define GPU_TRANSFORM_PROFILE GPU_CORE +#define GPU_INPUT_PROFILE GPU_CORE_41 #elif defined(WIN32) #include "../GL/glew.h" #include "../GL/wglew.h" #define GPU_FEATURE_PROFILE GPU_CORE -#define GPU_TRANSFORM_PROFILE GPU_CORE +#define GPU_INPUT_PROFILE GPU_CORE_41 #elif defined(ANDROID) @@ -38,7 +38,7 @@ #include "../GL/glew.h" #define GPU_FEATURE_PROFILE GPU_CORE -#define GPU_TRANSFORM_PROFILE GPU_CORE +#define GPU_INPUT_PROFILE GPU_CORE_41 #endif From f23df03ea9d9d47ae0d78f08cd61ef99a0936b51 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 3 Aug 2015 13:10:06 -0700 Subject: [PATCH 5/6] REsolve the bracket issue, --- libraries/gpu/src/gpu/GLBackendInput.cpp | 9 ++++----- libraries/gpu/src/gpu/GPUConfig.h | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 352cb0e7a0..eccd9dda49 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -169,11 +169,10 @@ void GLBackend::updateInput() { bool newState = newActivation[i]; if (newState != _input._attributeActivation[i]) { - if (newState) { - glEnableVertexAttribArray(i); - } else { - glDisableVertexAttribArray(i); - } + if (newState) { + glEnableVertexAttribArray(i); + } else { + glDisableVertexAttribArray(i); } (void) CHECK_GL_ERROR(); diff --git a/libraries/gpu/src/gpu/GPUConfig.h b/libraries/gpu/src/gpu/GPUConfig.h index f63474e13d..5ef17f3aeb 100644 --- a/libraries/gpu/src/gpu/GPUConfig.h +++ b/libraries/gpu/src/gpu/GPUConfig.h @@ -22,6 +22,7 @@ #include "../GL/glew.h" #define GPU_FEATURE_PROFILE GPU_CORE +#define GPU_TRANSFORM_PROFILE GPU_CORE #define GPU_INPUT_PROFILE GPU_CORE_41 #elif defined(WIN32) @@ -29,6 +30,7 @@ #include "../GL/wglew.h" #define GPU_FEATURE_PROFILE GPU_CORE +#define GPU_TRANSFORM_PROFILE GPU_CORE #define GPU_INPUT_PROFILE GPU_CORE_41 #elif defined(ANDROID) @@ -38,6 +40,7 @@ #include "../GL/glew.h" #define GPU_FEATURE_PROFILE GPU_CORE +#define GPU_TRANSFORM_PROFILE GPU_CORE #define GPU_INPUT_PROFILE GPU_CORE_41 #endif From 647abe50098df020c293157f78113042b57b599d Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 3 Aug 2015 13:41:02 -0700 Subject: [PATCH 6/6] Replace the glCOlor4f by a glVertexAttribute4f on the color slot instead --- libraries/gpu/src/gpu/GLBackend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 32c7f6987d..e2dac0df72 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -488,7 +488,8 @@ void Batch::_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) DO_IT_NOW(_glColor4f, 4); } void GLBackend::do_glColor4f(Batch& batch, uint32 paramOffset) { - glColor4f( + // TODO Replace this with a proper sticky Input attribute buffer with frequency 0 + glVertexAttrib4f( gpu::Stream::COLOR, batch._params[paramOffset + 3]._float, batch._params[paramOffset + 2]._float, batch._params[paramOffset + 1]._float,