diff --git a/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp b/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp index 171594cca3..9d337a0c47 100644 --- a/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp @@ -231,7 +231,7 @@ Item::Bound GizmoEntityRenderer::getBound(RenderArgs* args) { } ShapeKey GizmoEntityRenderer::getShapeKey() { - auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias(); + auto builder = render::ShapeKey::Builder().withDepthBias(); updateShapeKeyBuilderFromMaterials(builder); return builder.build(); } diff --git a/libraries/entities-renderer/src/RenderableImageEntityItem.cpp b/libraries/entities-renderer/src/RenderableImageEntityItem.cpp index 587b20543c..65d1d42068 100644 --- a/libraries/entities-renderer/src/RenderableImageEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableImageEntityItem.cpp @@ -10,6 +10,7 @@ #include #include +#include #include "RenderPipelines.h" @@ -100,7 +101,7 @@ Item::Bound ImageEntityRenderer::getBound(RenderArgs* args) { } ShapeKey ImageEntityRenderer::getShapeKey() { - auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias(); + auto builder = render::ShapeKey::Builder().withDepthBias(); updateShapeKeyBuilderFromMaterials(builder); return builder.build(); } @@ -134,7 +135,6 @@ void ImageEntityRenderer::doRender(RenderArgs* args) { transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode, args->_renderMode == RenderArgs::RenderMode::SHADOW_RENDER_MODE ? BillboardModeHelpers::getPrimaryViewFrustumPosition() : args->getViewFrustum().getPosition())); - batch->setModelTransform(transform); float imageWidth = _texture->getWidth(); @@ -184,5 +184,8 @@ void ImageEntityRenderer::doRender(RenderArgs* args) { color, _geometryId ); - batch->setResourceTexture(0, nullptr); + if (pipelineType == Pipeline::SIMPLE) { + // we have to reset this to white for other simple shapes + batch->setResourceTexture(graphics::slot::texture::Texture::MaterialAlbedo, DependencyManager::get()->getWhiteTexture()); + } } diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 01eff4cd06..a6f94beb99 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -123,7 +123,7 @@ ItemKey TextEntityRenderer::getKey() { } ShapeKey TextEntityRenderer::getShapeKey() { - auto builder = render::ShapeKey::Builder(); + auto builder = render::ShapeKey::Builder().withDepthBias(); updateShapeKeyBuilderFromMaterials(builder); return builder.build(); } diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp index 8126988294..dd30727523 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp @@ -840,10 +840,7 @@ void GLBackend::do_glColor4f(const Batch& batch, size_t paramOffset) { if (_input._colorAttribute != newColor) { _input._colorAttribute = newColor; glVertexAttrib4fv(gpu::Stream::COLOR, &_input._colorAttribute.r); - // Color has been changed and is not white. To prevent colors from bleeding - // between different objects, we need to set the _hadColorAttribute flag - // as if a previous render call had potential colors - _input._hadColorAttribute = (newColor != glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); + _input._hasColorAttribute = true; } (void)CHECK_GL_ERROR(); } diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index 0c8676493b..2947649ce7 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -348,36 +348,37 @@ protected: virtual void updateInput() = 0; struct InputStageState { - bool _invalidFormat{ true }; - bool _lastUpdateStereoState{ false }; - bool _hadColorAttribute{ true }; - FormatReference _format{ GPU_REFERENCE_INIT_VALUE }; + bool _invalidFormat { true }; + bool _lastUpdateStereoState { false }; + bool _hasColorAttribute { false }; + bool _hadColorAttribute { false }; + FormatReference _format { GPU_REFERENCE_INIT_VALUE }; std::string _formatKey; typedef std::bitset ActivationCache; - ActivationCache _attributeActivation{ 0 }; + ActivationCache _attributeActivation { 0 }; typedef std::bitset BuffersState; - BuffersState _invalidBuffers{ 0 }; - BuffersState _attribBindingBuffers{ 0 }; + BuffersState _invalidBuffers { 0 }; + BuffersState _attribBindingBuffers { 0 }; - std::array _buffers{}; - std::array _bufferOffsets{}; - std::array _bufferStrides{}; - std::array _bufferVBOs{}; + std::array _buffers; + std::array _bufferOffsets; + std::array _bufferStrides; + std::array _bufferVBOs; - glm::vec4 _colorAttribute{ 0.0f }; + glm::vec4 _colorAttribute { 1.0f }; - BufferReference _indexBuffer{}; - Offset _indexBufferOffset{ 0 }; - Type _indexBufferType{ UINT32 }; + BufferReference _indexBuffer; + Offset _indexBufferOffset { 0 }; + Type _indexBufferType { UINT32 }; - BufferReference _indirectBuffer{}; - Offset _indirectBufferOffset{ 0 }; - Offset _indirectBufferStride{ 0 }; + BufferReference _indirectBuffer; + Offset _indirectBufferOffset { 0 }; + Offset _indirectBufferStride { 0 }; - GLuint _defaultVAO{ 0 }; + GLuint _defaultVAO { 0 }; } _input; virtual void initTransform() = 0; diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendInput.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendInput.cpp index 85e6ba5382..1bfc27f0d2 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendInput.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendInput.cpp @@ -103,6 +103,9 @@ void GLBackend::resetInputStage() { reset(_input._format); _input._formatKey.clear(); _input._invalidFormat = false; + _input._hasColorAttribute = false; + _input._hadColorAttribute = false; + _input._colorAttribute = vec4(1.0f); _input._attributeActivation.reset(); for (uint32_t i = 0; i < _input._buffers.size(); i++) { @@ -159,15 +162,15 @@ void GLBackend::updateInput() { _input._invalidFormat |= (isStereoNow != _input._lastUpdateStereoState); #endif _input._lastUpdateStereoState = isStereoNow; - + + bool hasColorAttribute = _input._hasColorAttribute; + if (_input._invalidFormat) { InputStageState::ActivationCache newActivation; // Assign the vertex format required auto format = acquire(_input._format); if (format) { - bool hasColorAttribute{ false }; - _input._attribBindingBuffers.reset(); const auto& attributes = format->getAttributes(); @@ -186,12 +189,12 @@ void GLBackend::updateInput() { uint8_t locationCount = attrib._element.getLocationCount(); GLenum type = gl::ELEMENT_TYPE_TO_GL[attrib._element.getType()]; - GLuint offset = (GLuint)attrib._offset;; + GLuint offset = (GLuint)attrib._offset; GLboolean isNormalized = attrib._element.isNormalized(); GLenum perLocationSize = attrib._element.getLocationSize(); - hasColorAttribute = hasColorAttribute || (slot == Stream::COLOR); + hasColorAttribute |= slot == Stream::COLOR; for (GLuint locNum = 0; locNum < locationCount; ++locNum) { GLuint attriNum = (GLuint)(slot + locNum); @@ -224,14 +227,11 @@ void GLBackend::updateInput() { #endif } - if (_input._hadColorAttribute && !hasColorAttribute) { - // The previous input stage had a color attribute but this one doesn't so reset - // color to pure white. - const auto white = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - glVertexAttrib4fv(Stream::COLOR, &white.r); - _input._colorAttribute = white; + if (!hasColorAttribute && _input._hadColorAttribute) { + // The last stage had a color attribute but this one doens't, so reset the color to pure white. + _input._colorAttribute = glm::vec4(1.0f); + glVertexAttrib4fv(Stream::COLOR, &_input._colorAttribute.r); } - _input._hadColorAttribute = hasColorAttribute; } // Manage Activation what was and what is expected now @@ -253,6 +253,9 @@ void GLBackend::updateInput() { _stats._ISNumFormatChanges++; } + _input._hadColorAttribute = hasColorAttribute; + _input._hasColorAttribute = false; + if (_input._invalidBuffers.any()) { auto vbo = _input._bufferVBOs.data(); auto offset = _input._bufferOffsets.data(); @@ -276,4 +279,3 @@ void GLBackend::updateInput() { (void)CHECK_GL_ERROR(); } } - diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendInput.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendInput.cpp index 2b985c122e..0a3d2d7a16 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendInput.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendInput.cpp @@ -33,6 +33,8 @@ void GL41Backend::updateInput() { #endif _input._lastUpdateStereoState = isStereoNow; + bool hasColorAttribute = _input._hasColorAttribute; + if (_input._invalidFormat || _input._invalidBuffers.any()) { auto format = acquire(_input._format); @@ -71,8 +73,6 @@ void GL41Backend::updateInput() { // now we need to bind the buffers and assign the attrib pointers if (format) { - bool hasColorAttribute{ false }; - const auto& buffers = _input._buffers; const auto& offsets = _input._bufferOffsets; const auto& strides = _input._bufferStrides; @@ -110,7 +110,7 @@ void GL41Backend::updateInput() { uintptr_t pointer = (uintptr_t)(attrib._offset + offsets[bufferNum]); GLboolean isNormalized = attrib._element.isNormalized(); - hasColorAttribute = hasColorAttribute || (slot == Stream::COLOR); + hasColorAttribute |= slot == Stream::COLOR; for (size_t locNum = 0; locNum < locationCount; ++locNum) { if (attrib._element.isInteger()) { @@ -132,17 +132,16 @@ void GL41Backend::updateInput() { } } - if (_input._hadColorAttribute && !hasColorAttribute) { - // The previous input stage had a color attribute but this one doesn't so reset - // color to pure white. - const auto white = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - glVertexAttrib4fv(Stream::COLOR, &white.r); - _input._colorAttribute = white; + if (!hasColorAttribute && _input._hadColorAttribute) { + // The last stage had a color attribute but this one doens't, so reset the color to pure white. + _input._colorAttribute = glm::vec4(1.0f); + glVertexAttrib4fv(Stream::COLOR, &_input._colorAttribute.r); } - _input._hadColorAttribute = hasColorAttribute; } // everything format related should be in sync now _input._invalidFormat = false; } -} + _input._hadColorAttribute = hasColorAttribute; + _input._hasColorAttribute = false; +} diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp index 5285e62d3e..2f0b140e0b 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendInput.cpp @@ -35,14 +35,14 @@ void GL45Backend::updateInput() { #endif _input._lastUpdateStereoState = isStereoNow; + bool hasColorAttribute = _input._hasColorAttribute; + if (_input._invalidFormat) { InputStageState::ActivationCache newActivation; // Assign the vertex format required auto format = acquire(_input._format); if (format) { - bool hasColorAttribute{ false }; - _input._attribBindingBuffers.reset(); const auto& attributes = format->getAttributes(); @@ -61,12 +61,12 @@ void GL45Backend::updateInput() { uint8_t locationCount = attrib._element.getLocationCount(); GLenum type = gl::ELEMENT_TYPE_TO_GL[attrib._element.getType()]; - GLuint offset = (GLuint)attrib._offset;; + GLuint offset = (GLuint)attrib._offset; GLboolean isNormalized = attrib._element.isNormalized(); GLenum perLocationSize = attrib._element.getLocationSize(); - hasColorAttribute = hasColorAttribute || (slot == Stream::COLOR); + hasColorAttribute |= slot == Stream::COLOR; for (GLuint locNum = 0; locNum < locationCount; ++locNum) { GLuint attriNum = (GLuint)(slot + locNum); @@ -99,14 +99,11 @@ void GL45Backend::updateInput() { #endif } - if (_input._hadColorAttribute && !hasColorAttribute) { - // The previous input stage had a color attribute but this one doesn't so reset - // color to pure white. - const auto white = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); - glVertexAttrib4fv(Stream::COLOR, &white.r); - _input._colorAttribute = white; + if (!hasColorAttribute && _input._hadColorAttribute) { + // The last stage had a color attribute but this one doens't, so reset the color to pure white. + _input._colorAttribute = glm::vec4(1.0f); + glVertexAttrib4fv(Stream::COLOR, &_input._colorAttribute.r); } - _input._hadColorAttribute = hasColorAttribute; } // Manage Activation what was and what is expected now @@ -128,6 +125,9 @@ void GL45Backend::updateInput() { _stats._ISNumFormatChanges++; } + _input._hadColorAttribute = hasColorAttribute; + _input._hasColorAttribute = false; + if (_input._invalidBuffers.any()) { auto vbo = _input._bufferVBOs.data(); auto offset = _input._bufferOffsets.data(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 325e228120..af33899617 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -821,14 +821,12 @@ void GeometryCache::renderWireShape(gpu::Batch& batch, Shape shape) { void GeometryCache::renderShape(gpu::Batch& batch, Shape shape, const glm::vec4& color) { batch.setInputFormat(getSolidStreamFormat()); - // Color must be set after input format batch._glColor4f(color.r, color.g, color.b, color.a); _shapes[shape].draw(batch); } void GeometryCache::renderWireShape(gpu::Batch& batch, Shape shape, const glm::vec4& color) { batch.setInputFormat(getWireStreamFormat()); - // Color must be set after input format batch._glColor4f(color.r, color.g, color.b, color.a); _shapes[shape].drawWire(batch); }