mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 15:22:09 +02:00
fixing _glColor4f
This commit is contained in:
parent
c47351c4f2
commit
ccda630a3a
9 changed files with 65 additions and 65 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <DependencyManager.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <graphics/ShaderConstants.h>
|
||||
|
||||
#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<TextureCache>()->getWhiteTexture());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<MAX_NUM_ATTRIBUTES> ActivationCache;
|
||||
ActivationCache _attributeActivation{ 0 };
|
||||
ActivationCache _attributeActivation { 0 };
|
||||
|
||||
typedef std::bitset<MAX_NUM_INPUT_BUFFERS> BuffersState;
|
||||
|
||||
BuffersState _invalidBuffers{ 0 };
|
||||
BuffersState _attribBindingBuffers{ 0 };
|
||||
BuffersState _invalidBuffers { 0 };
|
||||
BuffersState _attribBindingBuffers { 0 };
|
||||
|
||||
std::array<BufferReference, MAX_NUM_INPUT_BUFFERS> _buffers{};
|
||||
std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferOffsets{};
|
||||
std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferStrides{};
|
||||
std::array<GLuint, MAX_NUM_INPUT_BUFFERS> _bufferVBOs{};
|
||||
std::array<BufferReference, MAX_NUM_INPUT_BUFFERS> _buffers;
|
||||
std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferOffsets;
|
||||
std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferStrides;
|
||||
std::array<GLuint, MAX_NUM_INPUT_BUFFERS> _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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue