Skip to content

Commit

Permalink
UPBGE: Fix color in wireframe render.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
panzergame committed Feb 25, 2016
1 parent 3ffb941 commit 6f1c592
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -887,12 +888,20 @@ void RAS_OpenGLRasterizer::DrawDerivedMesh(RAS_MeshSlot *ms)
memset(&current_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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6f1c592

Please sign in to comment.