From 6f1c5922a7d31989893fe24e0d2195a22aa13909 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Thu, 25 Feb 2016 10:14:32 +0100 Subject: [PATCH] UPBGE: Fix color in wireframe render. Previously the vertex color pointer was alwyas set in VBO and VA mode and the dummy instancing fragment shader was useing a white color. To fix this we changed the color in the shader to vec4(0, 0, 0, 1). About VA and VBO we add condition to set the vertex color pointer, if it's in wireframe it does nothing. For the VBO is reqested a new argument in function Bind and Unbind to now the drawing mode. --- .../gpu_shader_basic_instancing_frag.glsl | 2 +- .../RAS_OpenGLRasterizer.cpp | 9 ++++++++ .../RAS_OpenGLRasterizer/RAS_StorageVA.cpp | 19 +++++----------- .../RAS_OpenGLRasterizer/RAS_StorageVBO.cpp | 22 +++++++++++++------ .../RAS_OpenGLRasterizer/RAS_StorageVBO.h | 5 +++-- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/source/blender/gpu/shaders/gpu_shader_basic_instancing_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_instancing_frag.glsl index 8bd9162cc7ed..da5c89f3a192 100644 --- a/source/blender/gpu/shaders/gpu_shader_basic_instancing_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_basic_instancing_frag.glsl @@ -1,4 +1,4 @@ void main() { - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); + gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 8ce858e16b2b..e89666c70b07 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -874,6 +874,7 @@ void RAS_OpenGLRasterizer::DrawDerivedMesh(RAS_MeshSlot *ms) SetLines(true); } + bool wireframe = (m_drawingmode == RAS_WIREFRAME); if (current_polymat->GetFlag() & RAS_BLENDERGLSL) { // GetMaterialIndex return the original mface material index, // increment by 1 to match what derived mesh is doing @@ -887,12 +888,20 @@ void RAS_OpenGLRasterizer::DrawDerivedMesh(RAS_MeshSlot *ms) memset(¤t_gpu_attribs, 0, sizeof(current_gpu_attribs)); // DM draw can mess up blending mode, restore at the end int current_blend_mode = GPU_get_material_alpha_blend(); + + if (wireframe) { + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + } ms->m_pDerivedMesh->drawFacesGLSL(ms->m_pDerivedMesh, CheckMaterialDM); GPU_set_material_alpha_blend(current_blend_mode); } else { //ms->m_pDerivedMesh->drawMappedFacesTex(ms->m_pDerivedMesh, CheckTexfaceDM, mcol); current_blmat_nr = current_mesh->GetBlenderMaterialId(current_bucket->GetPolyMaterial()); current_image = current_polymat->GetBlenderImage(); + + if (wireframe) { + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + } ms->m_pDerivedMesh->drawFacesTex(ms->m_pDerivedMesh, CheckTexDM, NULL, NULL, DM_DRAW_USE_ACTIVE_UV); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp index 2d2a79a4deb7..a0b3e2ba1d12 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp @@ -127,13 +127,13 @@ void RAS_StorageVA::BindPrimitives(RAS_DisplayArrayBucket *arrayBucket) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, stride, vertexarray->getXYZ()); glNormalPointer(GL_FLOAT, stride, vertexarray->getNormal()); - glColorPointer(4, GL_UNSIGNED_BYTE, stride, vertexarray->getRGBA()); if (!wireframe) { + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_UNSIGNED_BYTE, stride, vertexarray->getRGBA()); TexCoordPtr(vertexarray); } @@ -180,18 +180,9 @@ void RAS_StorageVA::IndexPrimitives(RAS_MeshSlot *ms) RAS_IPolyMaterial *material = ms->m_bucket->GetPolyMaterial(); // colors - if (!wireframe) { - if (material->UsesObjectColor()) { - const MT_Vector4& rgba = ms->m_RGBAcolor; - - glDisableClientState(GL_COLOR_ARRAY); - glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]); - } - else { - glColor4f(0.0f, 0.0f, 0.0f, 1.0f); - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_UNSIGNED_BYTE, stride, vertexarray->getRGBA()); - } + if (!wireframe && material->UsesObjectColor()) { + const MT_Vector4& rgba = ms->m_RGBAcolor; + glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]); } else glColor4f(0.0f, 0.0f, 0.0f, 1.0f); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp index b9208d9f0ef6..8ef71ccc5190 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp @@ -76,8 +76,10 @@ void VBO::UpdateIndices() m_data->m_index.data(), GL_STATIC_DRAW); } -void VBO::Bind(int texco_num, RAS_IRasterizer::TexCoGen *texco, int attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer) +void VBO::Bind(int texco_num, RAS_IRasterizer::TexCoGen *texco, int attrib_num, RAS_IRasterizer::TexCoGen *attrib, + int *attrib_layer, RAS_IRasterizer::DrawType drawingmode) { + bool wireframe = (drawingmode == RAS_IRasterizer::RAS_WIREFRAME); int unit; // Bind buffers @@ -93,8 +95,10 @@ void VBO::Bind(int texco_num, RAS_IRasterizer::TexCoGen *texco, int attrib_num, glNormalPointer(GL_FLOAT, m_stride, m_normal_offset); // Colors - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_UNSIGNED_BYTE, m_stride, m_color_offset); + if (!wireframe) { + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_UNSIGNED_BYTE, m_stride, m_color_offset); + } for (unit = 0; unit < texco_num; ++unit) { glClientActiveTexture(GL_TEXTURE0_ARB + unit); @@ -165,11 +169,15 @@ void VBO::Bind(int texco_num, RAS_IRasterizer::TexCoGen *texco, int attrib_num, } } -void VBO::Unbind(int attrib_num, int texco_num) +void VBO::Unbind(int attrib_num, int texco_num, RAS_IRasterizer::DrawType drawingmode) { + bool wireframe = (drawingmode == RAS_IRasterizer::RAS_WIREFRAME); + glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); + if (!wireframe) { + glDisableClientState(GL_COLOR_ARRAY); + } glDisableClientState(GL_TEXTURE_COORD_ARRAY); for (unsigned int unit = 0; unit < texco_num; ++unit) { @@ -234,13 +242,13 @@ VBO *RAS_StorageVBO::GetVBO(RAS_DisplayArrayBucket *arrayBucket) void RAS_StorageVBO::BindPrimitives(RAS_DisplayArrayBucket *arrayBucket) { VBO *vbo = GetVBO(arrayBucket); - vbo->Bind(*m_texco_num, m_texco, *m_attrib_num, m_attrib, m_attrib_layer); + vbo->Bind(*m_texco_num, m_texco, *m_attrib_num, m_attrib, m_attrib_layer, m_drawingmode); } void RAS_StorageVBO::UnbindPrimitives(RAS_DisplayArrayBucket *arrayBucket) { VBO *vbo = GetVBO(arrayBucket); - vbo->Unbind(*m_attrib_num, *m_texco_num); + vbo->Unbind(*m_attrib_num, *m_texco_num, m_drawingmode); } void RAS_StorageVBO::IndexPrimitives(RAS_MeshSlot *ms) diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h index cdef26a9e047..dcb54de51df0 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h @@ -41,8 +41,9 @@ class VBO : public RAS_IStorageInfo VBO(RAS_DisplayArray *data, unsigned int indices); virtual ~VBO(); - void Bind(int texco_num, RAS_IRasterizer::TexCoGen *texco, int attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer); - void Unbind(int attrib_num, int texco_num); + void Bind(int texco_num, RAS_IRasterizer::TexCoGen *texco, int attrib_num, RAS_IRasterizer::TexCoGen *attrib, + int *attrib_layer, RAS_IRasterizer::DrawType drawingmode); + void Unbind(int attrib_num, int texco_num, RAS_IRasterizer::DrawType drawingmode); void Draw(); void DrawInstancing(unsigned int numinstance);