fix simpleCpu and ptexViewer to be compilable with new patch tables.

This commit is contained in:
Takahito Tejima 2013-05-09 13:48:00 -07:00
parent 3eaf0362bd
commit 7b6630cf40
6 changed files with 74 additions and 96 deletions

View File

@ -58,7 +58,7 @@
if( OPENGL_FOUND AND (GLEW_FOUND AND GLFW_FOUND) OR (APPLE AND GLFW_FOUND))
add_subdirectory(glViewer)
# add_subdirectory(glBatchViewer)
# add_subdirectory(simpleCpu)
add_subdirectory(simpleCpu)
# add_subdirectory(evalTest)
# add_subdirectory(limitEval)
if(NOT APPLE)
@ -67,7 +67,7 @@ if( OPENGL_FOUND AND (GLEW_FOUND AND GLFW_FOUND) OR (APPLE AND GLFW_FOUND))
endif()
if(PTEX_FOUND AND (NOT APPLE))
# the ptexViewer example requires GL functionality not available on OSX
# add_subdirectory(ptexViewer)
add_subdirectory(ptexViewer)
endif()
else()
set(MISSING "")

View File

@ -1226,7 +1226,7 @@ display() {
*/
// patch drawing
int patchCount[10][5][4]; // [Type][Pattern][Rotation] (see far/patchTables.h)
int patchCount[10][6][4]; // [Type][Pattern][Rotation] (see far/patchTables.h)
memset(patchCount, 0, sizeof(patchCount));
// primitive counting
@ -1329,9 +1329,7 @@ display() {
glDisable(GL_CULL_FACE);
}
int numIndices = patch.GetNumPatches() * patch.GetDescriptor().GetNumControlVertices();
glDrawElements(primType, numIndices, GL_UNSIGNED_INT,
glDrawElements(primType, patch.GetNumIndices(), GL_UNSIGNED_INT,
(void *)(patch.GetVertIndex() * sizeof(unsigned int)));
if (g_wire == 0) {
glEnable(GL_CULL_FACE);

View File

@ -59,7 +59,6 @@
//--------------------------------------------------------------
// Common
//--------------------------------------------------------------
uniform isamplerBuffer g_ptexIndicesBuffer;
uniform int nonAdaptiveLevel;
uniform float displacementScale = 1.0;
uniform float bumpScale = 1.0;

View File

@ -699,7 +699,7 @@ union Effect {
}
};
typedef std::pair<OpenSubdiv::OsdPatchDescriptor, Effect> EffectDesc;
typedef std::pair<OpenSubdiv::OsdDrawContext::PatchDescriptor, Effect> EffectDesc;
class EffectDrawRegistry : public OpenSubdiv::OsdGLDrawRegistry<EffectDesc> {
@ -732,16 +732,7 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc)
#endif
bool quad = true;
if (desc.first.type != OpenSubdiv::kNonPatch) {
quad = false;
sconfig->tessEvalShader.source = g_shaderSource + sconfig->tessEvalShader.source;
sconfig->tessEvalShader.version = glslVersion;
if (effect.displacement and (not effect.normal))
sconfig->geometryShader.AddDefine("FLAT_NORMALS");
if (effect.displacement)
sconfig->tessEvalShader.AddDefine("USE_PTEX_DISPLACEMENT");
} else {
if (desc.first.GetType() == OpenSubdiv::FarPatchTables::QUADS) {
sconfig->vertexShader.source = g_shaderSource;
sconfig->vertexShader.version = glslVersion;
sconfig->vertexShader.AddDefine("VERTEX_SHADER");
@ -749,6 +740,14 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc)
sconfig->geometryShader.AddDefine("USE_PTEX_DISPLACEMENT");
sconfig->geometryShader.AddDefine("FLAT_NORMALS");
}
} else {
quad = false;
sconfig->tessEvalShader.source = g_shaderSource + sconfig->tessEvalShader.source;
sconfig->tessEvalShader.version = glslVersion;
if (effect.displacement and (not effect.normal))
sconfig->geometryShader.AddDefine("FLAT_NORMALS");
if (effect.displacement)
sconfig->tessEvalShader.AddDefine("USE_PTEX_DISPLACEMENT");
}
assert(sconfig);
@ -829,11 +828,8 @@ EffectDrawRegistry::_CreateDrawConfig(
if ((loc = glGetUniformLocation(config->program, "g_QuadOffsetBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 2); // GL_TEXTURE2
}
if ((loc = glGetUniformLocation(config->program, "g_patchLevelBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 3); // GL_TEXTURE3
}
if ((loc = glGetUniformLocation(config->program, "g_ptexIndicesBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 4); // GL_TEXTURE4
glProgramUniform1i(config->program, loc, 3); // GL_TEXTURE3
}
#else
glUseProgram(config->program);
@ -846,11 +842,8 @@ EffectDrawRegistry::_CreateDrawConfig(
if ((loc = glGetUniformLocation(config->program, "g_QuadOffsetBuffer")) != -1) {
glUniform1i(loc, 2); // GL_TEXTURE2
}
if ((loc = glGetUniformLocation(config->program, "g_patchLevelBuffer")) != -1) {
glUniform1i(loc, 3); // GL_TEXTURE3
}
if ((loc = glGetUniformLocation(config->program, "g_ptexIndicesBuffer")) != -1) {
glUniform1i(loc, 4); // GL_TEXTURE4
glUniform1i(loc, 4); // GL_TEXTURE3
}
#endif
@ -860,11 +853,9 @@ EffectDrawRegistry::_CreateDrawConfig(
EffectDrawRegistry effectRegistry;
EffectDrawRegistry::ConfigType *
getInstance(Effect effect, OpenSubdiv::OsdPatchDescriptor const & patchDesc) {
getInstance(Effect effect, OpenSubdiv::OsdDrawContext::PatchDescriptor const & patchDesc) {
EffectDesc desc;
desc.first = patchDesc;
desc.second = effect;
EffectDesc desc(patchDesc, effect);
EffectDrawRegistry::ConfigType * config =
effectRegistry.GetDrawConfig(desc);
@ -1244,9 +1235,9 @@ applyImageShader() {
//------------------------------------------------------------------------------
static GLuint
bindProgram(Effect effect, OpenSubdiv::OsdPatchArray const & patch)
bindProgram(Effect effect, OpenSubdiv::OsdDrawContext::PatchArray const & patch)
{
OpenSubdiv::OsdPatchDescriptor const & desc = patch.desc;
OpenSubdiv::OsdDrawContext::PatchDescriptor const & desc = patch.GetDescriptor();
EffectDrawRegistry::ConfigType *
config = getInstance(effect, desc);
@ -1390,24 +1381,24 @@ drawModel() {
g_mesh->BindVertexBuffer();
#endif
OpenSubdiv::OsdPatchArrayVector const & patches = g_mesh->GetDrawContext()->patchArrays;
OpenSubdiv::OsdDrawContext::PatchArrayVector const & patches = g_mesh->GetDrawContext()->patchArrays;
GLenum primType = GL_LINES_ADJACENCY;
glBindVertexArray(g_vao);
// patch drawing
for (int i=0; i<(int)patches.size(); ++i) {
OpenSubdiv::OsdPatchArray const & patch = patches[i];
OpenSubdiv::OsdDrawContext::PatchArray const & patch = patches[i];
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
OpenSubdiv::OsdPatchType patchType = patch.desc.type;
int patchPattern = patch.desc.pattern;
//int patchRotation = patch.desc.rotation;
OpenSubdiv::OsdDrawContext::PatchDescriptor desc = patch.GetDescriptor();
OpenSubdiv::FarPatchTables::Type patchType = desc.GetType();
int patchPattern = desc.GetPattern() - 1;
if (g_mesh->GetDrawContext()->IsAdaptive()) {
primType = GL_PATCHES;
glPatchParameteri(GL_PATCH_VERTICES, patch.desc.GetPatchSize());
glPatchParameteri(GL_PATCH_VERTICES, desc.GetNumControlVertices());
if (g_mesh->GetDrawContext()->vertexTextureBuffer) {
glActiveTexture(GL_TEXTURE0);
@ -1427,20 +1418,15 @@ drawModel() {
glBindTexture(GL_TEXTURE_BUFFER,
g_mesh->GetDrawContext()->quadOffsetTextureBuffer);
}
if (g_mesh->GetDrawContext()->patchLevelTextureBuffer) {
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_BUFFER,
g_mesh->GetDrawContext()->patchLevelTextureBuffer);
}
if (g_mesh->GetDrawContext()->ptexCoordinateTextureBuffer) {
glActiveTexture(GL_TEXTURE4);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_BUFFER,
g_mesh->GetDrawContext()->ptexCoordinateTextureBuffer);
}
glActiveTexture(GL_TEXTURE0);
} else {
if (g_mesh->GetDrawContext()->ptexCoordinateTextureBuffer) {
glActiveTexture(GL_TEXTURE4);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_BUFFER,
g_mesh->GetDrawContext()->ptexCoordinateTextureBuffer);
}
@ -1488,50 +1474,40 @@ drawModel() {
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
GLuint overrideColorEnable = glGetUniformLocation(program, "overrideColorEnable");
GLuint overrideColor = glGetUniformLocation(program, "overrideColor");
switch(patchType) {
case OpenSubdiv::kRegular:
glProgramUniform4f(program, overrideColor, 1.0f, 1.0f, 1.0f, 1);
break;
case OpenSubdiv::kBoundary:
glProgramUniform4f(program, overrideColor, 0.8f, 0.0f, 0.0f, 1);
break;
case OpenSubdiv::kCorner:
glProgramUniform4f(program, overrideColor, 0, 1.0, 0, 1);
break;
case OpenSubdiv::kGregory:
glProgramUniform4f(program, overrideColor, 1.0f, 1.0f, 0.0f, 1);
break;
case OpenSubdiv::kBoundaryGregory:
glProgramUniform4f(program, overrideColor, 1.0f, 0.5f, 0.0f, 1);
break;
case OpenSubdiv::kTransitionRegular:
switch (patchPattern) {
case 0:
glProgramUniform4f(program, overrideColor, 0, 1.0f, 1.0f, 1);
break;
case 1:
glProgramUniform4f(program, overrideColor, 0, 0.5f, 1.0f, 1);
break;
case 2:
glProgramUniform4f(program, overrideColor, 0, 0.5f, 0.5f, 1);
break;
case 3:
glProgramUniform4f(program, overrideColor, 0.5f, 0, 1.0f, 1);
break;
case 4:
glProgramUniform4f(program, overrideColor, 1.0f, 0.5f, 1.0f, 1);
break;
GLfloat patchColor[10][4] = {
{ 1.0f, 1.0f, 1.0f, 1.0f }, // NON_PATCH
{ 1.0f, 1.0f, 1.0f, 1.0f }, // POLYGON
{ 1.0f, 1.0f, 1.0f, 1.0f }, // QUADS
{ 1.0f, 1.0f, 1.0f, 1.0f }, // TRIANGLES
{ 1.0f, 1.0f, 1.0f, 1.0f }, // LOOP
{ 1.0f, 1.0f, 1.0f, 1.0f }, // REGULAR
{ 0.8f, 0.0f, 0.0f, 1.0f }, // BOUNDARY
{ 0.0f, 1.0f, 0.0f, 1.0f }, // CORNER
{ 1.0f, 1.0f, 0.0f, 1.0f }, // GREGORY
{ 1.0f, 0.5f, 0.0f, 1.0f }, // GREGORY_BOUNDARY
};
GLfloat regularTransitionColor[6][4] = {
{ 1.0f, 1.0f, 1.0f, 1.0f }, // NON_TRANSITION
{ 0.0f, 1.0f, 1.0f, 1.0f }, // PATTERN0
{ 0.0f, 0.5f, 1.0f, 1.0f }, // PATTERN1
{ 0.0f, 0.5f, 0.5f, 1.0f }, // PATTERN2
{ 0.5f, 0.0f, 1.0f, 1.0f }, // PATTERN3
{ 1.0f, 0.5f, 1.0f, 1.0f }, // PATTERN4
};
if (patchPattern == OpenSubdiv::FarPatchTables::NON_TRANSITION) {
glProgramUniform4fv(program, overrideColor, 1, patchColor[patchType]);
} else {
if (patchType == OpenSubdiv::FarPatchTables::REGULAR) {
glProgramUniform4fv(program, overrideColor, 1, regularTransitionColor[patchPattern]);
} else if (patchType == OpenSubdiv::FarPatchTables::BOUNDARY) {
glProgramUniform4f(program, overrideColor, 0, 0, 0.5f, 1);
} else if (patchType == OpenSubdiv::FarPatchTables::CORNER) {
glProgramUniform4f(program, overrideColor, 0, 0, 0.5f, 1);
} else {
glProgramUniform4f(program, overrideColor, 0.4f, 0.4f, 0.8f, 1);
}
break;
case OpenSubdiv::kTransitionBoundary:
glProgramUniform4f(program, overrideColor, 0, 0, 0.5f, 1);
break;
case OpenSubdiv::kTransitionCorner:
glProgramUniform4f(program, overrideColor, 0, 0, 0.5f, 1);
break;
default:
glProgramUniform4f(program, overrideColor, 0.4f, 0.4f, 0.8f, 1);
break;
}
if (g_displayPatchColor or g_wire == 2) {
@ -1548,12 +1524,12 @@ drawModel() {
GLuint uniformGregoryQuadOffset = glGetUniformLocation(program, "GregoryQuadOffsetBase");
GLuint uniformLevelBase = glGetUniformLocation(program, "LevelBase");
glProgramUniform1i(program, uniformGregoryQuadOffset, patch.gregoryQuadOffsetBase);
glProgramUniform1i(program, uniformLevelBase, patch.levelBase);
glProgramUniform1i(program, uniformGregoryQuadOffset, patch.GetQuadOffsetIndex());
glProgramUniform1i(program, uniformLevelBase, patch.GetPatchIndex());
glDrawElements(primType,
patch.numIndices, GL_UNSIGNED_INT,
(void *)(patch.firstIndex * sizeof(unsigned int)));
patch.GetNumIndices(), GL_UNSIGNED_INT,
(void *)(patch.GetVertIndex() * sizeof(unsigned int)));
if (g_wire == 0) {
glEnable(GL_CULL_FACE);
}

View File

@ -544,16 +544,16 @@ display()
//
glBindBuffer(GL_ARRAY_BUFFER, g_vertexBuffer->BindVBO());
OpenSubdiv::OsdPatchArrayVector const & patches = g_drawContext->patchArrays;
OpenSubdiv::OsdDrawContext::PatchArrayVector const & patches = g_drawContext->patchArrays;
for (int i=0; i<(int)patches.size(); ++i) {
OpenSubdiv::OsdPatchArray const & patch = patches[i];
OpenSubdiv::OsdDrawContext::PatchArray const & patch = patches[i];
//
// Bind the solid shaded program and draw elements based on the buffer contents
//
bindProgram(g_quadFillProgram);
glDrawElements(GL_LINES_ADJACENCY, patch.numIndices,
glDrawElements(GL_LINES_ADJACENCY, patch.GetNumIndices(),
GL_UNSIGNED_INT, NULL);
//
@ -562,7 +562,7 @@ display()
bindProgram(g_quadLineProgram);
glUniform4f(glGetUniformLocation(g_quadLineProgram, "fragColor"),
0, 0, 0.5, 1);
glDrawElements(GL_LINES_ADJACENCY, patch.numIndices,
glDrawElements(GL_LINES_ADJACENCY, patch.GetNumIndices(),
GL_UNSIGNED_INT, NULL);
}

View File

@ -157,6 +157,11 @@ public:
return _range.npatches;
}
/// Returns the number of patch indices in the array
unsigned int GetNumIndices() const {
return _range.npatches * _desc.GetNumControlVertices();
}
unsigned int GetQuadOffsetIndex() const {
return _range.quadOffsetIndex;
}