Skip to content

Commit

Permalink
BaseVertex for alpharef textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlj committed Jun 30, 2014
1 parent 3035c56 commit ffd876f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 23 deletions.
8 changes: 8 additions & 0 deletions src/graphics/glwrap.cpp
Expand Up @@ -508,6 +508,7 @@ class VBOGatherer
public:
VBOGatherer();
std::pair<unsigned, unsigned> getBase(scene::IMeshBuffer *);
unsigned getVBO(video::E_VERTEX_TYPE type) { return vbo[getVTXTYPE(type)]; }
unsigned getVAO(video::E_VERTEX_TYPE type) { return vao[getVTXTYPE(type)]; }
void reset() {
for (unsigned i = 0; i < VTXTYPE_COUNT; i++)
Expand Down Expand Up @@ -698,6 +699,13 @@ std::pair<unsigned, unsigned> getVAOOffsetAndBase(scene::IMeshBuffer *mb)
return gatherersingleton->getBase(mb);
}

unsigned getVBO(video::E_VERTEX_TYPE type)
{
if (gatherersingleton)
return gatherersingleton->getVBO(type);
return 0;
}

unsigned getVAO(video::E_VERTEX_TYPE type)
{
if (gatherersingleton)
Expand Down
1 change: 1 addition & 0 deletions src/graphics/glwrap.hpp
Expand Up @@ -236,6 +236,7 @@ void saveCompressedTexture(const std::string& compressed_tex);

std::pair<unsigned, unsigned> getVAOOffsetAndBase(scene::IMeshBuffer *mb);
unsigned getVAO(video::E_VERTEX_TYPE type);
unsigned getVBO(video::E_VERTEX_TYPE type);
void resetVAO();

void draw3DLine(const core::vector3df& start,
Expand Down
1 change: 1 addition & 0 deletions src/graphics/render.cpp
Expand Up @@ -615,6 +615,7 @@ void IrrDriver::renderSolidSecondPass()
drawObjectPass2(*GroupedSM<SM_DEFAULT>::MeshSet[i], GroupedSM<SM_DEFAULT>::MVPSet[i], GroupedSM<SM_DEFAULT>::MeshSet[i]->TextureMatrix);

glUseProgram(MeshShader::ObjectRefPass2Shader::Program);
glBindVertexArray(getVAO(EVT_STANDARD));
for (unsigned i = 0; i < GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet.size(); i++)
drawObjectRefPass2(*GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet[i], GroupedSM<SM_ALPHA_REF_TEXTURE>::MVPSet[i], GroupedSM<SM_ALPHA_REF_TEXTURE>::MeshSet[i]->TextureMatrix);

Expand Down
24 changes: 22 additions & 2 deletions src/graphics/stkanimatedmesh.cpp
Expand Up @@ -103,6 +103,18 @@ void STKAnimatedMesh::render()
initvaostate(mesh, GeometricType, ShadedType);
GeometricMesh[GeometricType].push_back(&mesh);
ShadedMesh[ShadedType].push_back(&mesh);
glBindVertexArray(0);
switch (ShadedType)
{
case SM_ALPHA_REF_TEXTURE: {
std::pair<unsigned, unsigned> p = getVAOOffsetAndBase(mb);
mesh.vaoBaseVertex = p.first;
mesh.vaoOffset = p.second;
break;
}
default:
break;
}
}
}
}
Expand All @@ -117,8 +129,16 @@ void STKAnimatedMesh::render()
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
{
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, mb->getVertexCount() * GLmeshes[i].Stride, mb->getVertices());
if (MaterialTypeToShadedMaterial(mb->getMaterial().MaterialType, GLmeshes[i].textures) == SM_ALPHA_REF_TEXTURE)
{
glBindBuffer(GL_ARRAY_BUFFER, getVBO(video::EVT_STANDARD));
glBufferSubData(GL_ARRAY_BUFFER, GLmeshes[i].vaoBaseVertex * GLmeshes[i].Stride, mb->getVertexCount() * GLmeshes[i].Stride, mb->getVertices());
}
else
{
glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, mb->getVertexCount() * GLmeshes[i].Stride, mb->getVertices());
}
}
}
if (mb)
Expand Down
37 changes: 17 additions & 20 deletions src/graphics/stkmesh.cpp
Expand Up @@ -360,28 +360,25 @@ void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionM
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
irr_driver->IncreaseObjectCount();
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;

compressTexture(mesh.textures[0], true);
setTexture(MeshShader::ObjectRefPass2Shader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;

MeshShader::ObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix);
compressTexture(mesh.textures[0], true);
setTexture(MeshShader::ObjectRefPass2Shader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}

assert(mesh.vao);
glBindVertexArray(mesh.vao);
glDrawElements(ptype, count, itype, 0);
MeshShader::ObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix);
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
}

static video::ITexture *CausticTex = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/graphics/stkmeshscenenode.cpp
Expand Up @@ -74,7 +74,8 @@ void STKMeshSceneNode::setFirstTimeMaterial()
switch (ShadedType)
{
case SM_SPLATTING:
case SM_SPHEREMAP: {
case SM_SPHEREMAP:
case SM_ALPHA_REF_TEXTURE: {
std::pair<unsigned, unsigned> p = getVAOOffsetAndBase(mb);
mesh.vaoBaseVertex = p.first;
mesh.vaoOffset = p.second;
Expand Down

0 comments on commit ffd876f

Please sign in to comment.