From a6bf1693445262f5a42ed1bd6d75506cf8de0fca Mon Sep 17 00:00:00 2001 From: Takahito Tejima Date: Tue, 4 Jun 2013 11:02:27 -0700 Subject: [PATCH 01/32] Fix fvardata interpolation on adaptive patches. --- examples/mayaViewer/OpenSubdivShader.cpp | 125 +++++++++++------------ examples/mayaViewer/OpenSubdivShader.h | 2 +- examples/mayaViewer/shader.glsl | 3 +- opensubdiv/osd/glDrawContext.h | 5 + opensubdiv/osd/glslPatchCommon.glsl | 2 + 5 files changed, 69 insertions(+), 68 deletions(-) diff --git a/examples/mayaViewer/OpenSubdivShader.cpp b/examples/mayaViewer/OpenSubdivShader.cpp index a38aa34e..d59f253f 100644 --- a/examples/mayaViewer/OpenSubdivShader.cpp +++ b/examples/mayaViewer/OpenSubdivShader.cpp @@ -131,13 +131,11 @@ static const char *defaultShaderSource = // Draw styles for EffectDrawRegistry enum Effect { - kQuadFill = 0, - kQuadLine = 1, - kTriFill = 2, - kTriLine = 3, - kPoint = 4, + kFill = 0, + kLine = 1, + kPoint = 2, }; -typedef std::pair EffectDesc; +typedef std::pair EffectDesc; // #### Override of OpenSubdiv::OsdGLDrawRegistry // @@ -214,17 +212,20 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc) SourceConfigType * sconfig = BaseRegistry::_CreateDrawSourceConfig(desc.first); - if (desc.first.type != OpenSubdiv::kNonPatch) { - // Per-vertex descriptors are use for uniform refinement - if (effect == kQuadFill) effect = kTriFill; - if (effect == kQuadLine) effect = kTriLine; - sconfig->geometryShader.AddDefine("SMOOTH_NORMALS"); - - } else { + bool quad = false; + if (desc.first.GetType() == OpenSubdiv::FarPatchTables::QUADS) { // Configuration for adaptive refinement sconfig->vertexShader.version = "#version 410\n"; sconfig->vertexShader.source = _shaderSource; sconfig->vertexShader.AddDefine("VERTEX_SHADER"); + quad = true; + } else if (desc.first.GetType() == OpenSubdiv::FarPatchTables::TRIANGLES) { + sconfig->vertexShader.version = "#version 410\n"; + sconfig->vertexShader.source = _shaderSource; + sconfig->vertexShader.AddDefine("VERTEX_SHADER"); + } else { + // adaptive patches + sconfig->geometryShader.AddDefine("SMOOTH_NORMALS"); } assert(sconfig); @@ -254,29 +255,20 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc) sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER"); // Set up directives according to draw style + if (quad) { + sconfig->geometryShader.AddDefine("PRIM_QUAD"); + sconfig->fragmentShader.AddDefine("PRIM_QUAD"); + } else { + sconfig->geometryShader.AddDefine("PRIM_TRI"); + sconfig->fragmentShader.AddDefine("PRIM_TRI"); + } switch (effect) { - case kQuadFill: - sconfig->geometryShader.AddDefine("PRIM_QUAD"); + case kFill: sconfig->geometryShader.AddDefine("GEOMETRY_OUT_FILL"); - sconfig->fragmentShader.AddDefine("PRIM_QUAD"); sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_FILL"); break; - case kQuadLine: - sconfig->geometryShader.AddDefine("PRIM_QUAD"); + case kLine: sconfig->geometryShader.AddDefine("GEOMETRY_OUT_LINE"); - sconfig->fragmentShader.AddDefine("PRIM_QUAD"); - sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_LINE"); - break; - case kTriFill: - sconfig->geometryShader.AddDefine("PRIM_TRI"); - sconfig->geometryShader.AddDefine("GEOMETRY_OUT_FILL"); - sconfig->fragmentShader.AddDefine("PRIM_TRI"); - sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_FILL"); - break; - case kTriLine: - sconfig->geometryShader.AddDefine("PRIM_TRI"); - sconfig->geometryShader.AddDefine("GEOMETRY_OUT_LINE"); - sconfig->fragmentShader.AddDefine("PRIM_TRI"); sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_LINE"); break; case kPoint: @@ -344,7 +336,7 @@ 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) { + if ((loc = glGetUniformLocation(config->program, "g_ptexIndicesBuffer")) != -1) { glProgramUniform1i(config->program, loc, 3); // GL_TEXTURE3 } if ((loc = glGetUniformLocation(config->program, "g_uvFVarBuffer")) != -1) { @@ -668,31 +660,36 @@ OpenSubdivShader::draw(const MHWRender::MDrawContext &mDrawContext, glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, 0); glEnableVertexAttribArray(0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, osdDrawContext->patchIndexBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, osdDrawContext->GetPatchIndexBuffer()); // Get list of patches from OSD - OpenSubdiv::OsdPatchArrayVector const & patches = + OpenSubdiv::OsdDrawContext::PatchArrayVector const & patches = osdDrawContext->patchArrays; // Draw patches for (size_t i = 0; i < patches.size(); ++i) { - OpenSubdiv::OsdPatchArray const & patch = patches[i]; + OpenSubdiv::OsdDrawContext::PatchArray const & patch = patches[i]; - bindProgram(mDrawContext, osdDrawContext, patch); + GLuint program = bindProgram(mDrawContext, osdDrawContext, patch); - if (patch.desc.type != OpenSubdiv::kNonPatch) { - glPatchParameteri(GL_PATCH_VERTICES, patch.desc.GetPatchSize()); + GLuint uniformGregoryQuadOffset = glGetUniformLocation(program, "GregoryQuadOffsetBase"); + GLuint uniformLevelBase = glGetUniformLocation(program, "LevelBase"); + glProgramUniform1i(program, uniformGregoryQuadOffset, patch.GetQuadOffsetIndex()); + glProgramUniform1i(program, uniformLevelBase, patch.GetPatchIndex()); - glDrawElements(GL_PATCHES, - patch.numIndices, GL_UNSIGNED_INT, - reinterpret_cast(patch.firstIndex * - sizeof(unsigned int))); - } else { - glDrawElements(_scheme == OsdMeshData::kLoop ? GL_TRIANGLES : GL_LINES_ADJACENCY, - patch.numIndices, GL_UNSIGNED_INT, - reinterpret_cast(patch.firstIndex * - sizeof(unsigned int))); + GLenum primType = GL_PATCHES; + if (patch.GetDescriptor().GetType() == OpenSubdiv::FarPatchTables::QUADS) { + primType = GL_LINES_ADJACENCY; + } else if (patch.GetDescriptor().GetType() == OpenSubdiv::FarPatchTables::TRIANGLES) { + primType = GL_TRIANGLES; + } else if (patch.GetDescriptor().GetType() >= OpenSubdiv::FarPatchTables::REGULAR) { + glPatchParameteri(GL_PATCH_VERTICES, patch.GetDescriptor().GetNumControlVertices()); } + glDrawElements(primType, + patch.GetNumIndices(), GL_UNSIGNED_INT, + reinterpret_cast(patch.GetVertIndex() * + sizeof(unsigned int))); + CHECK_GL_ERROR("post draw\n"); } @@ -782,14 +779,14 @@ OpenSubdivShader::updateRegistry() GLuint OpenSubdivShader::bindProgram(const MHWRender::MDrawContext & mDrawContext, OpenSubdiv::OsdGLDrawContext *osdDrawContext, - const OpenSubdiv::OsdPatchArray & patch) + const OpenSubdiv::OsdDrawContext::PatchArray & patch) { CHECK_GL_ERROR("bindProgram begin\n"); // Primitives are triangles for Loop subdivision, quads otherwise - Effect effect = (_scheme == OsdMeshData::kLoop) ? kTriFill : kQuadFill; - EffectDesc effectDesc( patch.desc, effect ); + Effect effect = kFill; + EffectDesc effectDesc( patch.GetDescriptor(), effect ); // Build shader EffectDrawRegistry::ConfigType * @@ -828,13 +825,9 @@ OpenSubdivShader::bindProgram(const MHWRender::MDrawContext & mDrawContext, // Update and bind tessellation state struct Tessellation { float TessLevel; - int GregoryQuadOffsetBase; - int LevelBase; } tessellationData; tessellationData.TessLevel = static_cast(1 << _tessFactor); - tessellationData.GregoryQuadOffsetBase = patch.gregoryQuadOffsetBase; - tessellationData.LevelBase = patch.levelBase; if (!g_tessellationUB) { glGenBuffers(1, &g_tessellationUB); @@ -932,30 +925,30 @@ OpenSubdivShader::bindProgram(const MHWRender::MDrawContext & mDrawContext, // GL texture buffers. These are managed by the DrawContext // and must be bound for use by the program in addition to // any buffers used by the client/application shading code. - if (osdDrawContext->vertexTextureBuffer) { + if (osdDrawContext->GetVertexTextureBuffer()) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_BUFFER, - osdDrawContext->vertexTextureBuffer); + osdDrawContext->GetVertexTextureBuffer()); } - if (osdDrawContext->vertexValenceTextureBuffer) { + if (osdDrawContext->GetVertexValenceTextureBuffer()) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_BUFFER, - osdDrawContext->vertexValenceTextureBuffer); + osdDrawContext->GetVertexValenceTextureBuffer()); } - if (osdDrawContext->quadOffsetTextureBuffer) { + if (osdDrawContext->GetQuadOffsetsTextureBuffer()) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_BUFFER, - osdDrawContext->quadOffsetTextureBuffer); + osdDrawContext->GetQuadOffsetsTextureBuffer()); } - if (osdDrawContext->patchLevelTextureBuffer) { + if (osdDrawContext->GetPatchParamTextureBuffer()) { glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_BUFFER, - osdDrawContext->patchLevelTextureBuffer); + osdDrawContext->GetPatchParamTextureBuffer()); } - if (osdDrawContext->fvarDataTextureBuffer) { - glActiveTexture( GL_TEXTURE4 ); - glBindTexture( GL_TEXTURE_BUFFER, - osdDrawContext->fvarDataTextureBuffer ); + if (osdDrawContext->GetFvarDataTextureBuffer()) { + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_BUFFER, + osdDrawContext->GetFvarDataTextureBuffer() ); } glActiveTexture(GL_TEXTURE0); diff --git a/examples/mayaViewer/OpenSubdivShader.h b/examples/mayaViewer/OpenSubdivShader.h index 5f9d4f17..2c63840a 100644 --- a/examples/mayaViewer/OpenSubdivShader.h +++ b/examples/mayaViewer/OpenSubdivShader.h @@ -123,7 +123,7 @@ private: GLuint bindTexture(const MString& filename, int textureUnit); GLuint bindProgram(const MHWRender::MDrawContext & mDrawContext, OpenSubdiv::OsdGLDrawContext *osdDrawContext, - const OpenSubdiv::OsdPatchArray & patch); + const OpenSubdiv::OsdDrawContext::PatchArray & patch); // OSD attributes static MObject aLevel; diff --git a/examples/mayaViewer/shader.glsl b/examples/mayaViewer/shader.glsl index 300bfbb1..7bf1e46e 100644 --- a/examples/mayaViewer/shader.glsl +++ b/examples/mayaViewer/shader.glsl @@ -170,7 +170,8 @@ void emitAdaptive(int index, vec3 normal, vec2 uvs[4]) #endif // Bi-linear interpolation within the patch - vec2 st = input[index].v.patchCoord.st; + output.v.patchCoord = input[index].v.patchCoord; + vec2 st = input[index].v.tessCoord; output.v.patchCoord.st = vec2( mix( mix(uvs[0].x, uvs[1].x, st.s ), mix(uvs[3].x, uvs[2].x, st.s ), st.t), mix( mix(uvs[0].y, uvs[1].y, st.s ), mix(uvs[3].y, uvs[2].y, st.s ), st.t) ); diff --git a/opensubdiv/osd/glDrawContext.h b/opensubdiv/osd/glDrawContext.h index f0e9c263..30139952 100644 --- a/opensubdiv/osd/glDrawContext.h +++ b/opensubdiv/osd/glDrawContext.h @@ -157,6 +157,11 @@ public: return _quadOffsetsTextureBuffer; } + /// Returns the GL texture buffer containing fvar data + GLuint GetFvarDataTextureBuffer() const { + return _fvarDataTextureBuffer; + } + protected: GLuint _patchIndexBuffer; diff --git a/opensubdiv/osd/glslPatchCommon.glsl b/opensubdiv/osd/glslPatchCommon.glsl index 68c2284e..5fae99f2 100644 --- a/opensubdiv/osd/glslPatchCommon.glsl +++ b/opensubdiv/osd/glslPatchCommon.glsl @@ -82,6 +82,7 @@ struct OutputVertex { vec3 normal; vec3 tangent; centroid vec4 patchCoord; // u, v, level, faceID + centroid vec2 tessCoord; // tesscoord.st noperspective vec4 edgeDistance; #if OSD_NUM_VARYINGS > 0 float varyings[OSD_NUM_VARYINGS]; @@ -191,6 +192,7 @@ int GetPatchLevel() ivec2 p = input[0].v.ptexInfo.xy; \ int lv = input[0].v.ptexInfo.z; \ int rot = input[0].v.ptexInfo.w; \ + output.v.tessCoord.xy = uv; \ uv.xy = float(rot==0)*uv.xy \ + float(rot==1)*vec2(1.0-uv.y, uv.x) \ + float(rot==2)*vec2(1.0-uv.x, 1.0-uv.y) \ From 5fe38c3ac070671ea572d0095d54f6ef5ecd9255 Mon Sep 17 00:00:00 2001 From: manuelk Date: Tue, 4 Jun 2013 17:53:28 -0700 Subject: [PATCH 02/32] If Hbr carries no fvar data, then we shouldn't attempt to build fvar data tables in Far, where the factory requests it or not... fixes #169 --- opensubdiv/far/patchTablesFactory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opensubdiv/far/patchTablesFactory.h b/opensubdiv/far/patchTablesFactory.h index 78bc17ac..720c989c 100644 --- a/opensubdiv/far/patchTablesFactory.h +++ b/opensubdiv/far/patchTablesFactory.h @@ -705,7 +705,8 @@ FarPatchTablesFactory::Create( int maxlevel, int maxvalence, bool requireFVar iptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_patches[pa->GetVertIndex()]; pptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_paramTable[pa->GetPatchIndex()]; - if (requireFVarData) + + if (fvarwidth>0) fptrs[(int)pa->GetDescriptor().GetPattern()].getValue( *it ) = &result->_fvarTable[pa->GetPatchIndex() * 4 * fvarwidth]; } From b0e8533ef46ee64ffd369b55bd4dbc79f5dc9e77 Mon Sep 17 00:00:00 2001 From: Takahito Tejima Date: Wed, 5 Jun 2013 10:44:21 -0700 Subject: [PATCH 03/32] Fix cmakefile and #ifdefs for opencl configuration. --- examples/glBatchViewer/viewer.cpp | 4 +++- opensubdiv/osdutil/CMakeLists.txt | 9 ++++++++- opensubdiv/osdutil/batchCL.h | 4 ---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/glBatchViewer/viewer.cpp b/examples/glBatchViewer/viewer.cpp index 79104a6e..14284352 100644 --- a/examples/glBatchViewer/viewer.cpp +++ b/examples/glBatchViewer/viewer.cpp @@ -131,7 +131,9 @@ #include #include -#include +#ifdef OPENSUBDIV_HAS_OPENCL + #include +#endif #include #include #include "delegate.h" diff --git a/opensubdiv/osdutil/CMakeLists.txt b/opensubdiv/osdutil/CMakeLists.txt index 02bd8274..78a5c00b 100644 --- a/opensubdiv/osdutil/CMakeLists.txt +++ b/opensubdiv/osdutil/CMakeLists.txt @@ -66,11 +66,18 @@ include_directories( set(PUBLIC_HEADER_FILES batch.h - batchCL.h drawItem.h drawController.h ) +#------------------------------------------------------------------------------- +# OpenCL code & dependencies +if ( OPENCL_FOUND ) + list(APPEND PUBLIC_HEADER_FILES + batchCL.h + ) +endif() + #------------------------------------------------------------------------------- # platform dependent tweaks diff --git a/opensubdiv/osdutil/batchCL.h b/opensubdiv/osdutil/batchCL.h index 6661c632..a924543c 100644 --- a/opensubdiv/osdutil/batchCL.h +++ b/opensubdiv/osdutil/batchCL.h @@ -66,8 +66,6 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { -#ifdef OPENSUBDIV_HAS_OPENCL - // ---------------------------------------------------------------------------- // OsdUtilMeshBatch OpenCL specialized class // @@ -237,8 +235,6 @@ OsdUtilMeshBatch::Create(Co return batch; } -#endif /* OPENSUBDIV_HAS_OPENCL */ - } // end namespace OPENSUBDIV_VERSION using namespace OPENSUBDIV_VERSION; From 043369485c5478bf2af3bd3bd348f14e7b6af852 Mon Sep 17 00:00:00 2001 From: manuelk Date: Wed, 5 Jun 2013 11:44:30 -0700 Subject: [PATCH 04/32] - adding varying data interpolation to the EvalLimit module - minor refactoring of the LimitEvalContext to accomodate all the data buffers - pushing some minor sub-patch functionality back to FarPatchParams - extend example code with randomly generated varying vertex colors --- examples/limitEval/main.cpp | 167 +++++++++++++++------ opensubdiv/far/patchParam.h | 63 ++++++++ opensubdiv/osd/cpuEvalLimitContext.cpp | 20 +++ opensubdiv/osd/cpuEvalLimitContext.h | 175 +++++++++++++++------- opensubdiv/osd/cpuEvalLimitController.cpp | 164 ++++++++++---------- opensubdiv/osd/cpuEvalLimitController.h | 4 +- opensubdiv/osd/cpuEvalLimitKernel.cpp | 34 ++++- opensubdiv/osd/cpuEvalLimitKernel.h | 8 + opensubdiv/osd/vertexDescriptor.h | 7 +- 9 files changed, 463 insertions(+), 179 deletions(-) diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 96ca339a..04072c85 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -127,7 +127,8 @@ struct SimpleShape { std::vector g_defaultShapes; std::vector g_orgPositions, - g_positions; + g_positions, + g_varyingColors; int g_currentShape = 0, g_level = 3, @@ -137,12 +138,16 @@ std::vector g_coarseEdges; std::vector g_coarseEdgeSharpness; std::vector g_coarseVertexSharpness; +enum DrawMode { kUV=0, + kVARYING=1 }; + int g_running = 1, g_width = 1024, g_height = 1024, g_fullscreen = 0, g_drawCageEdges = 1, - g_drawCageVertices = 0, + g_drawCageVertices = 1, + g_drawMode = kUV, g_prev_x = 0, g_prev_y = 0, g_mbutton[3] = {0, 0, 0}, @@ -285,29 +290,6 @@ GLuint g_cageEdgeVAO = 0, GLhud g_hud; -//------------------------------------------------------------------------------ -static void -createCoarseMesh( OsdHbrMesh * const hmesh, int nfaces ) { - // save coarse topology (used for coarse mesh drawing) - g_coarseEdges.clear(); - g_coarseEdgeSharpness.clear(); - g_coarseVertexSharpness.clear(); - - for(int i=0; iGetFace(i); - int nv = face->GetNumVertices(); - for(int j=0; jGetVertex(j)->GetID()); - g_coarseEdges.push_back(face->GetVertex((j+1)%nv)->GetID()); - g_coarseEdgeSharpness.push_back(face->GetEdge(j)->GetSharpness()); - } - } - int nv = hmesh->GetNumVertices(); - for(int i=0; iGetVertex(i)->GetSharpness()); - } -} - //------------------------------------------------------------------------------ static int createRandomSamples( int nfaces, int nsamples, std::vector & coords ) { @@ -331,6 +313,51 @@ createRandomSamples( int nfaces, int nsamples, std::vector & coor return (int)coords.size(); } +//------------------------------------------------------------------------------ +static int +createRandomVaryingColors( int nverts, std::vector & colors ) { + + colors.resize( nverts * 3 ); + + // large Pell prime number + srand( static_cast(2147483647) ); + + for (int i=0; iGetFace(i); + int nv = face->GetNumVertices(); + for(int j=0; jGetVertex(j)->GetID()); + g_coarseEdges.push_back(face->GetVertex((j+1)%nv)->GetID()); + g_coarseEdgeSharpness.push_back(face->GetEdge(j)->GetSharpness()); + } + } + int nv = hmesh->GetNumVertices(); + for(int i=0; iGetVertex(i)->GetSharpness()); + } + + // assign a randomly generated color for each vertex ofthe mesh + createRandomVaryingColors(nv, g_varyingColors); +} + + //------------------------------------------------------------------------------ static int getNumPtexFaces( OsdHbrMesh const * hmesh, int nfaces ) { @@ -359,7 +386,8 @@ OsdCpuEvalLimitContext * g_evalCtx = 0; OsdCpuEvalLimitController g_evalCtrl; OsdVertexBufferDescriptor g_idesc( /*offset*/ 0, /*legnth*/ 3, /*stride*/ 3 ), - g_odesc( /*offset*/ 0, /*legnth*/ 3, /*stride*/ 6 ); + g_odesc( /*offset*/ 0, /*legnth*/ 3, /*stride*/ 6 ), + g_vdesc( /*offset*/ 3, /*legnth*/ 3, /*stride*/ 6 ); std::vector g_coords; @@ -395,7 +423,7 @@ updateGeom() { g_vertexData->UpdateData( &g_positions[0], 0, nverts); - g_computeCtrl.Refine( g_computeCtx, g_fmesh->GetKernelBatches(), g_vertexData ); + g_computeCtrl.Refine( g_computeCtx, g_fmesh->GetKernelBatches(), g_vertexData, g_varyingData ); s.Stop(); g_computeTime = float(s.GetElapsed() * 1000.0f); @@ -406,8 +434,6 @@ updateGeom() { s.Start(); // Reset the output buffer - float * cpubuff = g_Q->BindCpuBuffer(); - memset( cpubuff, 0, g_Q->GetNumVertices()*g_Q->GetNumElements()*sizeof(float) ); g_nsamplesFound=0; @@ -415,6 +441,13 @@ updateGeom() { // outside of the parallel loop g_evalCtx->BindVertexBuffers( g_idesc, g_vertexData, g_odesc, g_Q, g_dQu, g_dQv ); + // The varying data ends-up interleaved in the same g_Q output buffer because + // g_Q has a stride of 6 and g_vdesc sets the offset to 3, while g_odesc sets + // the offset to 0 + if (g_drawMode==kVARYING) { + g_evalCtx->BindVaryingBuffers( g_idesc, g_varyingData, g_vdesc, g_Q ); + } + #define USE_OPENMP #if defined(OPENSUBDIV_HAS_OPENMP) and defined(USE_OPENMP) #pragma omp parallel for @@ -425,13 +458,15 @@ updateGeom() { if (n) { - // point colors - float * color = cpubuff + i * 6 + 3; - - color[0] = g_coords[i].u; - color[1] = 0.0f; - color[2] = g_coords[i].v; - + // point colors + switch (g_drawMode) { + case kUV : { float * color = g_Q->BindCpuBuffer() + i * 6 + 3; + color[0] = g_coords[i].u; + color[1] = 0.0f; + color[2] = g_coords[i].v; } break; + case kVARYING : + default : break; + } #if defined(OPENSUBDIV_HAS_OPENMP) and defined(USE_OPENMP) #pragma omp atomic #endif @@ -465,8 +500,6 @@ createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { createCoarseMesh(hmesh, nfaces); - - // Create FAR mesh OsdFarMeshFactory factory( hmesh, level, /*adaptive*/ true); @@ -483,15 +516,20 @@ createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { // Create v-buffer & populate w/ colors delete g_varyingData; - g_varyingData = OsdCpuVertexBuffer::Create(3, nverts); - + + if (g_drawMode==kVARYING) { + g_varyingData = OsdCpuVertexBuffer::Create(3, nverts); + g_varyingData->UpdateData( &g_varyingColors[0], 0, nverts); + } else { + g_varyingData = 0; + } // Create a Compute context, used to "pose" the vertices delete g_computeCtx; g_computeCtx = OsdCpuComputeContext::Create(g_fmesh); - g_computeCtrl.Refine( g_computeCtx, g_fmesh->GetKernelBatches(), g_vertexData ); + g_computeCtrl.Refine( g_computeCtx, g_fmesh->GetKernelBatches(), g_vertexData, g_varyingData ); @@ -686,7 +724,20 @@ drawCageVertices() { vbo.reserve(numPoints*6); float r, g, b; for (int i = 0; i < numPoints; ++i) { - setSharpnessColor(g_coarseVertexSharpness[i], &r, &g, &b); + + switch (g_drawMode) { + + case kVARYING : { r=g_varyingColors[i*3+0]; + g=g_varyingColors[i*3+1]; + b=g_varyingColors[i*3+2]; + } break; + + case kUV : { setSharpnessColor(g_coarseVertexSharpness[i], &r, &g, &b); + } break; + + default : break; + } + vbo.push_back(g_positions[i*3+0]); vbo.push_back(g_positions[i*3+1]); vbo.push_back(g_positions[i*3+2]); @@ -957,14 +1008,42 @@ callbackFreeze(bool checked, int f) g_freeze = checked; } +//------------------------------------------------------------------------------ +static void +callbackDisplayCageVertices(bool checked, int d) +{ + g_drawCageVertices = checked; +} + +//------------------------------------------------------------------------------ +static void +callbackDisplayCageEdges(bool checked, int d) +{ + g_drawCageEdges = checked; +} + +//------------------------------------------------------------------------------ +static void +callbackDisplayVaryingColors(int mode) +{ + g_drawMode = mode; + createOsdMesh( g_defaultShapes[g_currentShape].data, g_level, g_defaultShapes[ g_currentShape ].scheme ); +} + + //------------------------------------------------------------------------------ static void initHUD() { g_hud.Init(g_width, g_height); - g_hud.AddCheckBox("Animate vertices (M)", g_moveScale != 0, 350, 20, callbackAnimate, 0, 'm'); - g_hud.AddCheckBox("Freeze (spc)", false, 350, 40, callbackFreeze, 0, ' '); + g_hud.AddCheckBox("Cage Edges (H)", true, 350, 10, callbackDisplayCageEdges, 0, 'h'); + g_hud.AddCheckBox("Cage Verts (J)", true, 350, 30, callbackDisplayCageVertices, 0, 'j'); + g_hud.AddCheckBox("Animate vertices (M)", g_moveScale != 0, 350, 50, callbackAnimate, 0, 'm'); + g_hud.AddCheckBox("Freeze (spc)", false, 350, 70, callbackFreeze, 0, ' '); + + g_hud.AddRadioButton(0, "(u,v)", true, 200, 10, callbackDisplayVaryingColors, kUV, 'k'); + g_hud.AddRadioButton(0, "varying", false, 200, 30, callbackDisplayVaryingColors, kVARYING, 'k'); for (int i = 1; i < 11; ++i) { char level[16]; diff --git a/opensubdiv/far/patchParam.h b/opensubdiv/far/patchParam.h index 701fa261..e1ee7098 100644 --- a/opensubdiv/far/patchParam.h +++ b/opensubdiv/far/patchParam.h @@ -58,6 +58,8 @@ #ifndef FAR_PATCH_PARAM_H #define FAR_PATCH_PARAM_H +#include + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { @@ -121,6 +123,29 @@ struct FarPatchParam { /// Returns the level of subdivision of the patch unsigned char GetDepth() const { return (field & 0xf); } + /// If the (u,v) pair is within the parameteric space of the sub-patch + /// described by the bitfield, then (u,v) is normalized to this sub- + /// parametric space. If the (u,v) pair was outside of the parametric + /// range, then it is unchanged and false is returned. + /// + /// @param u u parameter + /// + /// @param v v parameter + /// + /// @return true if the given (u,v) pair was within the sub-patch parametric + /// space, false if the pair was outside the sub-patch range. + /// + bool Normalize( float & u, float & v ) const; + + /// Rotate (u,v) pair to compensate for transition pattern and boundary + /// orientations. + /// + /// @param u u parameter + /// + /// @param v v parameter + /// + void Rotate( float & u, float & v ) const; + /// Resets the values to 0 void Clear() { field = 0; } @@ -149,6 +174,44 @@ struct FarPatchParam { } }; +inline bool +FarPatchParam::BitField::Normalize( float & u, float & v ) const { + + float frac; + if (NonQuadRoot()) { + frac = 1.0f / float( 1 << (GetDepth()-1) ); + } else { + frac = 1.0f / float( 1 << GetDepth() ); + } + + // Are the coordinates within the parametric space covered by the patch ? + float pu = (float)GetU()*frac; + if ( u(pu+frac) ) + return false; + + float pv = (float)GetV()*frac; + if ( v(pv+frac) ) + return false; + + // normalize u,v coordinates + u = (u - pu) / frac, + v = (v - pv) / frac; + + return true; +} + +inline void +FarPatchParam::BitField::Rotate( float & u, float & v ) const { + switch( GetRotation() ) { + case 0 : break; + case 1 : { float tmp=v; v=1.0f-u; u=tmp; } break; + case 2 : { u=1.0f-u; v=1.0f-v; } break; + case 3 : { float tmp=u; u=1.0f-v; v=tmp; } break; + default: + assert(0); + } +} + } // end namespace OPENSUBDIV_VERSION using namespace OPENSUBDIV_VERSION; diff --git a/opensubdiv/osd/cpuEvalLimitContext.cpp b/opensubdiv/osd/cpuEvalLimitContext.cpp index 3a6b7875..010fc011 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.cpp +++ b/opensubdiv/osd/cpuEvalLimitContext.cpp @@ -78,6 +78,26 @@ OsdCpuEvalLimitContext::Create(FarMesh const * farmesh) { return new OsdCpuEvalLimitContext(farmesh); } +void +OsdCpuEvalLimitContext::EvalData::Unbind() { + + _inDesc.Reset(); + _inQ=0; + + _outDesc.Reset(); + _outQ = _outdQu = _outdQv = 0; +} + +void +OsdCpuEvalLimitContext::UnbindVertexBuffers() { + _vertexData.Unbind(); +} + +void +OsdCpuEvalLimitContext::UnbindVaryingBuffers() { + _varyingData.Unbind(); +} + OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmesh) : OsdEvalLimitContext(farmesh) { diff --git a/opensubdiv/osd/cpuEvalLimitContext.h b/opensubdiv/osd/cpuEvalLimitContext.h index af3f4070..45e029ce 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.h +++ b/opensubdiv/osd/cpuEvalLimitContext.h @@ -80,8 +80,82 @@ public: /// Destructor virtual ~OsdCpuEvalLimitContext(); + /// Limit evaluation data descriptor + class EvalData { + public: + OsdVertexBufferDescriptor const & GetInputDesc() const { + return _inDesc; + } - /// Binds the data buffers. + float const * GetInputData() const { + return _inQ; + } + + OsdVertexBufferDescriptor const & GetOutputDesc() const { + return _outDesc; + } + + float const * GetOutputData(int index=0) const { + return _outQ + index * _outDesc.stride; + } + + float const * GetOutputDU(int index=0) const { + return _outdQu + index * _outDesc.stride; + } + + float const * GetOutputDV(int index=0) const { + return _outdQv + index * _outDesc.stride; + } + + bool IsBound() const { + return _inQ and _outQ; + } + + private: + friend class OsdCpuEvalLimitContext; + + OsdVertexBufferDescriptor _inDesc; // input data + float * _inQ; + + OsdVertexBufferDescriptor _outDesc; // output data + float * _outQ, + * _outdQu, // U derivative of output data + * _outdQv; // V derivative of output data + + /// Binds the data buffers. + /// + /// @param inDesc vertex / varying data descriptor shared by all input data buffers + /// + /// @param inQ input subidivision data + /// + /// @param outDesc vertex buffer data descriptor shared by all output data buffers + /// + /// @param outQ output vertex data + /// + /// @param outdQu optional output derivative along "u" of the vertex data + /// + /// @param outdQv optional output derivative along "v" of the vertex data + /// + template + void Bind( OsdVertexBufferDescriptor const & inDesc, INPUT_BUFFER *inQ, + OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ, + OUTPUT_BUFFER *outdQu=0, + OUTPUT_BUFFER *outdQv=0); + + /// Resets the descriptors & pointers + void Unbind(); + }; + + EvalData const & GetVertexData() const { + return _vertexData; + } + + EvalData const & GetVaryingData() const { + return _varyingData; + } + + + /// Binds the vertex-interpolated data buffers. /// /// @param inDesc vertex buffer data descriptor shared by all input data buffers /// @@ -100,52 +174,35 @@ public: OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ, OUTPUT_BUFFER *outdQu=0, OUTPUT_BUFFER *outdQv=0) { - _inDesc = inDesc; - _inQ = inQ ? inQ->BindCpuBuffer() : 0; - - _outDesc = outDesc; - _outQ = outQ ? outQ->BindCpuBuffer() : 0 ; - _outdQu = outdQu ? outdQu->BindCpuBuffer() : 0 ; - _outdQv = outdQv ? outdQv->BindCpuBuffer() : 0 ; + _vertexData.Bind( inDesc, inQ, outDesc, outQ, outdQu, outdQv ); } - /// Unbind the data buffers - void UnbindVertexBuffers() { - _inQ = 0; - _outQ = 0; - _outdQu = 0; - _outdQv = 0; + /// Unbind the vertex data buffers + void UnbindVertexBuffers(); + + /// Binds the varying-interpolated data buffers. + /// + /// @param inDesc varying buffer data descriptor shared by all input data buffers + /// + /// @param inQ input varying data + /// + /// @param outDesc varying buffer data descriptor shared by all output data buffers + /// + /// @param outQ output varying data + /// + /// @param outdQu optional output derivative along "u" of the varying data + /// + /// @param outdQv optional output derivative along "v" of the varying data + /// + template + void BindVaryingBuffers( OsdVertexBufferDescriptor const & inDesc, VARYING_BUFFER *inQ, + OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ) { + _varyingData.Bind( inDesc, inQ, outDesc, outQ ); } - /// Returns the input vertex buffer descriptor - const OsdVertexBufferDescriptor & GetInputDesc() const { - return _inDesc; - } + /// Unbind the varying data buffers + void UnbindVaryingBuffers(); - /// Returns the output vertex buffer descriptor - const OsdVertexBufferDescriptor & GetOutputDesc() const { - return _outDesc; - } - - /// Returns the input vertex buffer data - float const * GetInputVertexData() const { - return _inQ; - } - - /// Returns the output vertex buffer data - float * GetOutputVertexData() const { - return _outQ; - } - - /// Returns the U derivative of the output vertex buffer data - float * GetOutputVertexDataUDerivative() const { - return _outdQu; - } - - /// Returns the V derivative of the output vertex buffer data - float * GetOutputVertexDataVDerivative() const { - return _outdQv; - } /// Returns the vector of patch arrays const FarPatchTables::PatchArrayVector & GetPatchArrayVector() const { @@ -162,11 +219,12 @@ public: return _patches; } - /// XXXX + /// Returns the vertex-valence buffer used for Gregory patch computations const int * GetVertexValenceBuffer() const { return &_vertexValenceBuffer[0]; } + /// Returns the Quad-Offsets buffer used for Gregory patch computations const unsigned int *GetQuadOffsetBuffer() const { return &_quadOffsetBuffer[0]; } @@ -176,6 +234,7 @@ public: return _patchMap; } + /// Returns the highest valence of the vertices in the buffers int GetMaxValence() const { return _maxValence; } @@ -195,17 +254,31 @@ private: FarPatchTables::PatchMap * _patchMap; // map of the sub-patches given a face index - OsdVertexBufferDescriptor _inDesc, - _outDesc; - + EvalData _vertexData, + _varyingData; + int _maxValence; - - float * _inQ, // input vertex data - * _outQ, // output vertex data - * _outdQu, // U derivative of output vertex data - * _outdQv; // V derivative of output vertex data }; +template void +OsdCpuEvalLimitContext::EvalData::Bind( OsdVertexBufferDescriptor const & inDesc, + INPUT_BUFFER *inQ, + OsdVertexBufferDescriptor const & outDesc, + OUTPUT_BUFFER *outQ, + OUTPUT_BUFFER *outdQu, + OUTPUT_BUFFER *outdQv) { + _inDesc = inDesc; + _inQ = inQ ? inQ->BindCpuBuffer() : 0; + + _outDesc = outDesc; + _outQ = outQ ? outQ->BindCpuBuffer() : 0 ; + _outdQu = outdQu ? outdQu->BindCpuBuffer() : 0 ; + _outdQv = outdQv ? outdQv->BindCpuBuffer() : 0 ; +} + + + + } // end namespace OPENSUBDIV_VERSION using namespace OPENSUBDIV_VERSION; diff --git a/opensubdiv/osd/cpuEvalLimitController.cpp b/opensubdiv/osd/cpuEvalLimitController.cpp index 70f3436a..8a3f310f 100644 --- a/opensubdiv/osd/cpuEvalLimitController.cpp +++ b/opensubdiv/osd/cpuEvalLimitController.cpp @@ -68,7 +68,6 @@ OsdCpuEvalLimitController::OsdCpuEvalLimitController() { OsdCpuEvalLimitController::~OsdCpuEvalLimitController() { } - int OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & coords, OsdCpuEvalLimitContext const *context, @@ -81,109 +80,118 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c if (not context->GetPatchesMap()->GetChildPatchesHandles(coords.face, &npatches, &patchHandles)) return 0; - // Position lookup pointers at the indexed vertex - float const * inQ = context->GetInputVertexData(); - float * outQ = context->GetOutputVertexData() + index * context->GetOutputDesc().stride; - float * outdQu = context->GetOutputVertexDataUDerivative() + index * context->GetOutputDesc().stride; - float * outdQv = context->GetOutputVertexDataVDerivative() + index * context->GetOutputDesc().stride; - + OsdCpuEvalLimitContext::EvalData const & data = context->GetVertexData(); + for (int i=0; iGetPatchBitFields()[ handle.serialIndex ]; - - float frac; - if (bits.NonQuadRoot()) { - frac = 1.0f / float( 1 << (bits.GetDepth()-1) ); - } else { - frac = 1.0f / float( 1 << bits.GetDepth() ); - } - - // Are the coordinates within the parametric space covered by the patch ? - float pu = (float)bits.GetU()*frac; - if ( (coords.u < pu) or (coords.u > pu+frac) ) - continue; - - float pv = (float)bits.GetV()*frac; - if ( (coords.v < pv) or (coords.v > pv+frac) ) - continue; - assert( handle.array < context->GetPatchArrayVector().size() ); + float u=coords.u, + v=coords.v; + + // check if the patch contains the point + if (not bits.Normalize(u,v)) + continue; + + assert( (u>=0.0f) and (u<=1.0f) and (v>=0.0f) and (v<=1.0f) ); + + bits.Rotate(u, v); + FarPatchTables::PatchArray const & parray = context->GetPatchArrayVector()[ handle.array ]; unsigned int const * cvs = &context->GetControlVertices()[ parray.GetVertIndex() + handle.vertexOffset ]; - // normalize u,v coordinates - float u = (coords.u - pu) / frac, - v = (coords.v - pv) / frac; + OsdCpuEvalLimitContext::EvalData const & vertexData = context->GetVertexData(), + & varyingData = context->GetVaryingData(); - assert( (u>=0.0f) and (u<=1.0f) and (v>=0.0f) and (v<=1.0f) ); - - typedef FarPatchTables::Descriptor PD; - - // Rotate u,v to compensate for transition pattern and boundary orientations - switch( bits.GetRotation() ) { - case 0 : break; - case 1 : { float tmp=v; v=1.0f-u; u=tmp; } break; - case 2 : { u=1.0f-u; v=1.0f-v; } break; - case 3 : { float tmp=u; u=1.0f-v; v=tmp; } break; - default: - assert(0); - } + // Position lookup pointers at the indexed vertex + float const * inQ = vertexData.GetInputData(); + float * outQ = const_cast(vertexData.GetOutputData(index)); + float * outdQu = const_cast(vertexData.GetOutputDU(index)); + float * outdQv = const_cast(vertexData.GetOutputDV(index)); // Based on patch type - go execute interpolation switch( parray.GetDescriptor().GetType() ) { - case FarPatchTables::REGULAR : { evalBSpline( v, u, cvs, - context->GetInputDesc(), - inQ, - context->GetOutputDesc(), - outQ, outdQu, outdQv); - return 1; } + case FarPatchTables::REGULAR : if (vertexData.IsBound()) { + evalBSpline( v, u, cvs, + data.GetInputDesc(), + inQ, + data.GetOutputDesc(), + outQ, outdQu, outdQv ); + } break; - case FarPatchTables::BOUNDARY : { evalBoundary( v, u, cvs, - context->GetInputDesc(), + case FarPatchTables::BOUNDARY : if (vertexData.IsBound()) { + evalBoundary( v, u, cvs, + data.GetInputDesc(), + inQ, + data.GetOutputDesc(), + outQ, outdQu, outdQv ); + } break; + + case FarPatchTables::CORNER : if (vertexData.IsBound()) { + evalCorner( v, u, cvs, + data.GetInputDesc(), inQ, - context->GetOutputDesc(), + data.GetOutputDesc(), outQ, outdQu, outdQv); - return 1; } - - case FarPatchTables::CORNER : { evalCorner( v, u, cvs, - context->GetInputDesc(), - inQ, - context->GetOutputDesc(), - outQ, outdQu, outdQv); - return 1; } + } break; - case FarPatchTables::GREGORY : { evalGregory(v, u, cvs, - context->GetVertexValenceBuffer(), - context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle.vertexOffset, - context->GetMaxValence(), - context->GetInputDesc(), - inQ, - context->GetOutputDesc(), - outQ, outdQu, outdQv); - return 1; } + case FarPatchTables::GREGORY : if (vertexData.IsBound()) { + evalGregory( v, u, cvs, + context->GetVertexValenceBuffer(), + context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle.vertexOffset, + context->GetMaxValence(), + data.GetInputDesc(), + inQ, + data.GetOutputDesc(), + outQ, outdQu, outdQv); + } break; - case FarPatchTables::GREGORY_BOUNDARY : { - evalGregoryBoundary(v, u, cvs, - context->GetVertexValenceBuffer(), - context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle.vertexOffset, - context->GetMaxValence(), - context->GetInputDesc(), - inQ, - context->GetOutputDesc(), - outQ, outdQu, outdQv); - - return 1; } + case FarPatchTables::GREGORY_BOUNDARY : + if (vertexData.IsBound()) { + evalGregoryBoundary(v, u, cvs, + context->GetVertexValenceBuffer(), + context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle.vertexOffset, + context->GetMaxValence(), + data.GetInputDesc(), + inQ, + data.GetOutputDesc(), + outQ, outdQu, outdQv); + } break; default: assert(0); - } + } + if (varyingData.IsBound()) { + + static int indices[5][4] = { {5, 6,10, 9}, // regular + {1, 2, 6, 5}, // boundary + {1, 2, 5, 4}, // corner + {0, 1, 2, 3}, // gregory + {0, 1, 2, 3} };// gregory boundary + + int type = (int)(parray.GetDescriptor().GetType() - FarPatchTables::REGULAR); + + unsigned int zeroRing[4] = { cvs[indices[type][0]], + cvs[indices[type][1]], + cvs[indices[type][2]], + cvs[indices[type][3]] }; + + evalVarying( v, u, zeroRing, + varyingData.GetInputDesc(), + varyingData.GetInputData(), + varyingData.GetOutputDesc(), + const_cast(varyingData.GetOutputData(index)) ); + + } + return 1; } + return 0; } diff --git a/opensubdiv/osd/cpuEvalLimitController.h b/opensubdiv/osd/cpuEvalLimitController.h index 4da81b7c..8d7f9a1d 100644 --- a/opensubdiv/osd/cpuEvalLimitController.h +++ b/opensubdiv/osd/cpuEvalLimitController.h @@ -118,9 +118,7 @@ public: template int EvalLimitSample( OpenSubdiv::OsdEvalCoords const & coords, OsdCpuEvalLimitContext * context, - unsigned int index - ) { - + unsigned int index ) { if (not context) return 0; diff --git a/opensubdiv/osd/cpuEvalLimitKernel.cpp b/opensubdiv/osd/cpuEvalLimitKernel.cpp index 88302de6..9587e730 100644 --- a/opensubdiv/osd/cpuEvalLimitKernel.cpp +++ b/opensubdiv/osd/cpuEvalLimitKernel.cpp @@ -68,9 +68,39 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { +void +evalVarying(float u, float v, + unsigned int const * vertexIndices, + OsdVertexBufferDescriptor const & inDesc, + float const * inQ, + OsdVertexBufferDescriptor const & outDesc, + float * outQ) { + + assert( inDesc.length <= (outDesc.stride-outDesc.offset) ); + + float const * inOffset = inQ + inDesc.offset; + + float * Q = outQ + outDesc.offset; + + memset(Q, 0, inDesc.length*sizeof(float)); + + float ou = 1.0f - u, + ov = 1.0f - v, + w[4] = { ov*ou, v*ou, v*u, ov*u }; + + for (int i=0; i<4; ++i) { + + float const * in = inOffset + vertexIndices[i]*inDesc.stride; + + for (int k=0; k=length); + return (length>0) and (offset=length); } /// True if the 'other' descriptor can be used as a destination for @@ -225,6 +225,11 @@ struct OsdVertexBufferDescriptor { (other.length <= (stride-offset)); } + /// Resets the descriptor to default + void Reset() { + offset = length = stride = 0; + } + int offset; // offset to desired element data int length; // number or length of the data int stride; // stride to the next element From f0be0b57994928abc1ae341d7782060e271f2b02 Mon Sep 17 00:00:00 2001 From: Takahito Tejima Date: Thu, 6 Jun 2013 16:20:40 -0700 Subject: [PATCH 05/32] Fix bug : multi mesh wasn't working correctly. FarMultiMesh has to set meshIndex to FarKernelBatch. fixes #170 --- opensubdiv/far/multiMeshFactory.h | 1 + 1 file changed, 1 insertion(+) diff --git a/opensubdiv/far/multiMeshFactory.h b/opensubdiv/far/multiMeshFactory.h index c3c3a2f9..03981d7a 100644 --- a/opensubdiv/far/multiMeshFactory.h +++ b/opensubdiv/far/multiMeshFactory.h @@ -378,6 +378,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV for (size_t i = 0; i < meshes.size(); ++i) { for (int j = 0; j < (int)meshes[i]->_batches.size(); ++j) { FarKernelBatch batch = meshes[i]->_batches[j]; + batch._meshIndex = i; batch._vertexOffset += vertexOffsets[i]; if (batch._kernelType == FarKernelBatch::CATMARK_FACE_VERTEX or From c18cf5bff2e819365a28fd14f16e83da8a4068b5 Mon Sep 17 00:00:00 2001 From: manuelk Date: Thu, 6 Jun 2013 18:07:46 -0700 Subject: [PATCH 06/32] first pass at face-varying interpolation for CpuEvalLimit - still a couple of kinks to be worked out... --- examples/limitEval/main.cpp | 59 ++++--- opensubdiv/osd/cpuEvalLimitContext.cpp | 27 +++- opensubdiv/osd/cpuEvalLimitContext.h | 184 ++++++++++++++-------- opensubdiv/osd/cpuEvalLimitController.cpp | 41 ++++- opensubdiv/osd/cpuEvalLimitKernel.cpp | 12 +- opensubdiv/osd/cpuEvalLimitKernel.h | 12 +- regression/common/shape_utils.h | 81 ++++++++-- 7 files changed, 295 insertions(+), 121 deletions(-) diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 04072c85..168574c3 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -139,7 +139,8 @@ std::vector g_coarseEdgeSharpness; std::vector g_coarseVertexSharpness; enum DrawMode { kUV=0, - kVARYING=1 }; + kVARYING=1, + kFACEVARYING=2 }; int g_running = 1, g_width = 1024, @@ -387,7 +388,9 @@ OsdCpuEvalLimitController g_evalCtrl; OsdVertexBufferDescriptor g_idesc( /*offset*/ 0, /*legnth*/ 3, /*stride*/ 3 ), g_odesc( /*offset*/ 0, /*legnth*/ 3, /*stride*/ 6 ), - g_vdesc( /*offset*/ 3, /*legnth*/ 3, /*stride*/ 6 ); + g_vdesc( /*offset*/ 3, /*legnth*/ 3, /*stride*/ 6 ), + g_fvidesc( /*offset*/ 0, /*legnth*/ 2, /*stride*/ 2 ), + g_fvodesc( /*offset*/ 3, /*legnth*/ 2, /*stride*/ 6 ); std::vector g_coords; @@ -444,9 +447,15 @@ updateGeom() { // The varying data ends-up interleaved in the same g_Q output buffer because // g_Q has a stride of 6 and g_vdesc sets the offset to 3, while g_odesc sets // the offset to 0 - if (g_drawMode==kVARYING) { - g_evalCtx->BindVaryingBuffers( g_idesc, g_varyingData, g_vdesc, g_Q ); - } + switch (g_drawMode) { + case kVARYING : g_evalCtx->BindVaryingBuffers( g_idesc, g_varyingData, g_vdesc, g_Q ); break; + + case kFACEVARYING : g_evalCtx->BindFaceVaryingBuffers( g_fvidesc, g_fvodesc, g_Q ); + + case kUV : + + default : g_evalCtx->UnbindVaryingBuffers(); break; + } #define USE_OPENMP #if defined(OPENSUBDIV_HAS_OPENMP) and defined(USE_OPENMP) @@ -457,16 +466,19 @@ updateGeom() { int n = g_evalCtrl.EvalLimitSample( g_coords[i], g_evalCtx, i ); if (n) { + // point colors + switch (g_drawMode) { + case kUV : { float * color = g_Q->BindCpuBuffer() + i * 6 + 3; + color[0] = g_coords[i].u; + color[1] = 0.0f; + color[2] = g_coords[i].v; } break; - // point colors - switch (g_drawMode) { - case kUV : { float * color = g_Q->BindCpuBuffer() + i * 6 + 3; - color[0] = g_coords[i].u; - color[1] = 0.0f; - color[2] = g_coords[i].v; } break; - case kVARYING : - default : break; - } + case kVARYING : break; + + case kFACEVARYING : { g_Q->BindCpuBuffer()[i*6 + 5] = 0.1f; + } break; + default : break; + } #if defined(OPENSUBDIV_HAS_OPENMP) and defined(USE_OPENMP) #pragma omp atomic #endif @@ -488,7 +500,7 @@ static void createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { // Create HBR mesh - OsdHbrMesh * hmesh = simpleHbr(shape.c_str(), scheme, g_orgPositions); + OsdHbrMesh * hmesh = simpleHbr(shape.c_str(), scheme, g_orgPositions, true); g_positions.resize(g_orgPositions.size(),0.0f); @@ -504,7 +516,7 @@ createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { OsdFarMeshFactory factory( hmesh, level, /*adaptive*/ true); delete g_fmesh; - g_fmesh = factory.Create(/*fvar*/ false); + g_fmesh = factory.Create(/*fvar*/ true); int nverts = g_fmesh->GetNumVertices(); @@ -514,17 +526,13 @@ createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { delete g_vertexData; g_vertexData = OsdCpuVertexBuffer::Create(3, nverts); - // Create v-buffer & populate w/ colors - delete g_varyingData; - + // Create primvar v-buffer & populate w/ colors or (u,v) data + delete g_varyingData; g_varyingData = 0; if (g_drawMode==kVARYING) { g_varyingData = OsdCpuVertexBuffer::Create(3, nverts); - g_varyingData->UpdateData( &g_varyingColors[0], 0, nverts); - } else { - g_varyingData = 0; } - + // Create a Compute context, used to "pose" the vertices delete g_computeCtx; g_computeCtx = OsdCpuComputeContext::Create(g_fmesh); @@ -535,7 +543,7 @@ createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { // Create eval context & data buffers delete g_evalCtx; - g_evalCtx = OsdCpuEvalLimitContext::Create(g_fmesh); + g_evalCtx = OsdCpuEvalLimitContext::Create(g_fmesh, /*requireFVarData*/ true); delete g_Q; g_Q = OsdCpuGLVertexBuffer::Create(6,nsamples); @@ -780,7 +788,7 @@ drawSamples() { glBindVertexArray(g_samplesVAO); glPointSize(1.0f); - glDrawArrays( GL_POINTS, 0, (int)g_coords.size() ); + glDrawArrays( GL_POINTS, 0, g_nsamplesFound); glPointSize(1.0f); glBindVertexArray(0); @@ -1044,6 +1052,7 @@ initHUD() g_hud.AddRadioButton(0, "(u,v)", true, 200, 10, callbackDisplayVaryingColors, kUV, 'k'); g_hud.AddRadioButton(0, "varying", false, 200, 30, callbackDisplayVaryingColors, kVARYING, 'k'); + g_hud.AddRadioButton(0, "face-varying", false, 200, 50, callbackDisplayVaryingColors, kFACEVARYING, 'k'); for (int i = 1; i < 11; ++i) { char level[16]; diff --git a/opensubdiv/osd/cpuEvalLimitContext.cpp b/opensubdiv/osd/cpuEvalLimitContext.cpp index 010fc011..bd5822bb 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.cpp +++ b/opensubdiv/osd/cpuEvalLimitContext.cpp @@ -67,7 +67,7 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { OsdCpuEvalLimitContext * -OsdCpuEvalLimitContext::Create(FarMesh const * farmesh) { +OsdCpuEvalLimitContext::Create(FarMesh const * farmesh, bool requireFVarData) { assert(farmesh); @@ -75,7 +75,7 @@ OsdCpuEvalLimitContext::Create(FarMesh const * farmesh) { if (not farmesh->GetPatchTables()) return NULL; - return new OsdCpuEvalLimitContext(farmesh); + return new OsdCpuEvalLimitContext(farmesh, requireFVarData); } void @@ -85,7 +85,15 @@ OsdCpuEvalLimitContext::EvalData::Unbind() { _inQ=0; _outDesc.Reset(); - _outQ = _outdQu = _outdQv = 0; + _outQ = 0; +} + +void +OsdCpuEvalLimitContext::EvalVertexData::Unbind() { + + EvalData::Unbind(); + + _outdQu = _outdQv = 0; } void @@ -98,7 +106,12 @@ OsdCpuEvalLimitContext::UnbindVaryingBuffers() { _varyingData.Unbind(); } -OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmesh) : +void +OsdCpuEvalLimitContext::UnbindFaceVaryingBuffers() { + _faceVaryingData.Unbind(); +} + +OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmesh, bool requireFVarData) : OsdEvalLimitContext(farmesh) { FarPatchTables const * patchTables = farmesh->GetPatchTables(); @@ -137,6 +150,12 @@ OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmes } } + if (requireFVarData) { + _fvarwidth = farmesh->GetTotalFVarWidth(); + if (_fvarwidth>0) { + _fvarData = patchTables->GetFVarDataTable(); + } + } _patchMap = new FarPatchTables::PatchMap( *patchTables ); } diff --git a/opensubdiv/osd/cpuEvalLimitContext.h b/opensubdiv/osd/cpuEvalLimitContext.h index 45e029ce..c71eff00 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.h +++ b/opensubdiv/osd/cpuEvalLimitContext.h @@ -71,11 +71,18 @@ namespace OPENSUBDIV_VERSION { class OsdCpuEvalLimitContext : public OsdEvalLimitContext { public: + /// \brief Factory /// Returns an EvalLimitContext from the given farmesh. /// Note : the farmesh is expected to be feature-adaptive and have ptex /// coordinates tables. - static OsdCpuEvalLimitContext * Create(FarMesh const * farmesh); + /// + /// @param farmesh a pointer to an initialized farmesh + /// + /// @param requireFVarData flag for generating face-varying data + /// + static OsdCpuEvalLimitContext * Create(FarMesh const * farmesh, + bool requireFVarData=false); /// Destructor virtual ~OsdCpuEvalLimitContext(); @@ -99,12 +106,14 @@ public: return _outQ + index * _outDesc.stride; } - float const * GetOutputDU(int index=0) const { - return _outdQu + index * _outDesc.stride; + template + void BindInputData( BUFFER * inQ ) { + _inQ = inQ ? inQ->BindCpuBuffer() : 0; } - float const * GetOutputDV(int index=0) const { - return _outdQv + index * _outDesc.stride; + template + void BindOutputData( BUFFER * outQ ) { + _outQ = outQ ? outQ->BindCpuBuffer() : 0; } bool IsBound() const { @@ -114,46 +123,47 @@ public: private: friend class OsdCpuEvalLimitContext; + EvalData() : _inQ(0), _outQ(0) { } + OsdVertexBufferDescriptor _inDesc; // input data float * _inQ; OsdVertexBufferDescriptor _outDesc; // output data - float * _outQ, - * _outdQu, // U derivative of output data - * _outdQv; // V derivative of output data - - /// Binds the data buffers. - /// - /// @param inDesc vertex / varying data descriptor shared by all input data buffers - /// - /// @param inQ input subidivision data - /// - /// @param outDesc vertex buffer data descriptor shared by all output data buffers - /// - /// @param outQ output vertex data - /// - /// @param outdQu optional output derivative along "u" of the vertex data - /// - /// @param outdQv optional output derivative along "v" of the vertex data - /// - template - void Bind( OsdVertexBufferDescriptor const & inDesc, INPUT_BUFFER *inQ, - OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ, - OUTPUT_BUFFER *outdQu=0, - OUTPUT_BUFFER *outdQv=0); - + float * _outQ; + /// Resets the descriptors & pointers void Unbind(); }; - EvalData const & GetVertexData() const { - return _vertexData; - } + /// Limit evaluation data descriptor with derivatives + class EvalVertexData : public EvalData { + public: + float const * GetOutputDU(int index=0) const { + return _outdQu + index * _outDesc.stride; + } - EvalData const & GetVaryingData() const { - return _varyingData; - } + float const * GetOutputDV(int index=0) const { + return _outdQv + index * _outDesc.stride; + } + template + void BindOutputDerivData( BUFFER * outdQu, BUFFER * outdQv ) { + _outdQu = outdQu ? outdQu->BindCpuBuffer() : 0; + _outdQv = outdQv ? outdQv->BindCpuBuffer() : 0; + } + + private: + friend class OsdCpuEvalLimitContext; + + EvalVertexData() : _outdQu(0), _outdQv(0) { } + + /// Resets the descriptors & pointers + void Unbind(); + + float * _outdQu, // U derivative of output data + * _outdQv; // V derivative of output data + }; + /// Binds the vertex-interpolated data buffers. /// @@ -174,12 +184,24 @@ public: OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ, OUTPUT_BUFFER *outdQu=0, OUTPUT_BUFFER *outdQv=0) { - _vertexData.Bind( inDesc, inQ, outDesc, outQ, outdQu, outdQv ); + _vertexData._inDesc = inDesc; + _vertexData.BindInputData( inQ ); + _vertexData._outDesc = outDesc; + _vertexData.BindOutputData( outQ ); + _vertexData.BindOutputDerivData( outdQu, outdQv ); } /// Unbind the vertex data buffers void UnbindVertexBuffers(); + /// Returns an Eval data descriptor of the vertex-interpolated data currently + /// bound to this EvalLimitContext. + EvalVertexData const & GetVertexData() const { + return _vertexData; + } + + + /// Binds the varying-interpolated data buffers. /// /// @param inDesc varying buffer data descriptor shared by all input data buffers @@ -190,19 +212,59 @@ public: /// /// @param outQ output varying data /// - /// @param outdQu optional output derivative along "u" of the varying data - /// - /// @param outdQv optional output derivative along "v" of the varying data - /// template void BindVaryingBuffers( OsdVertexBufferDescriptor const & inDesc, VARYING_BUFFER *inQ, OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ) { - _varyingData.Bind( inDesc, inQ, outDesc, outQ ); + _varyingData._inDesc = inDesc; + _varyingData.BindInputData( inQ ); + _varyingData._outDesc = outDesc; + _varyingData.BindOutputData( outQ ); } /// Unbind the varying data buffers void UnbindVaryingBuffers(); + /// Returns an Eval data descriptor of the varying-interpolated data currently + /// bound to this EvalLimitContext. + EvalData const & GetVaryingData() const { + return _varyingData; + } + + + + /// Binds the face-varying-interpolated data buffers. + /// + /// Note : currently we only support bilinear boundary interpolation rules + /// for face-varying data. Although Hbr supports 3 addition smooth rule sets, + /// the feature-adaptive patch interpolation code currently does not support + /// them, and neither does this EvalContext + /// + /// @param inDesc varying buffer data descriptor shared by all input data buffers + /// + /// @param inQ input varying data + /// + /// @param outDesc varying buffer data descriptor shared by all output data buffers + /// + /// @param outQ output varying data + /// + template + void BindFaceVaryingBuffers( OsdVertexBufferDescriptor const & inDesc, + OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ) { + _faceVaryingData._inDesc = inDesc; + _faceVaryingData._outDesc = outDesc; + _faceVaryingData.BindOutputData( outQ ); + } + + /// Unbind the varying data buffers + void UnbindFaceVaryingBuffers(); + + /// Returns an Eval data descriptor of the face-varying-interpolated data + /// currently bound to this EvalLimitContext. + EvalData const & GetFaceVaryingData() const { + return _faceVaryingData; + } + + /// Returns the vector of patch arrays const FarPatchTables::PatchArrayVector & GetPatchArrayVector() const { @@ -228,6 +290,16 @@ public: const unsigned int *GetQuadOffsetBuffer() const { return &_quadOffsetBuffer[0]; } + + /// Returns the face-varying data patch table + FarPatchTables::FVarDataTable const & GetFVarData() const { + return _fvarData; + } + + /// Returns the number of floats in a datum of the face-varying data table + int GetFVarWidth() const { + return _fvarwidth; + } /// Returns a map object that can connect a faceId to a list of children patches const FarPatchTables::PatchMap * GetPatchesMap() const { @@ -240,7 +312,7 @@ public: } protected: - explicit OsdCpuEvalLimitContext(FarMesh const * farmesh); + explicit OsdCpuEvalLimitContext(FarMesh const * farmesh, bool requireFVarData); private: @@ -252,32 +324,18 @@ private: FarPatchTables::VertexValenceTable _vertexValenceBuffer; // extra Gregory patch data buffers FarPatchTables::QuadOffsetTable _quadOffsetBuffer; + FarPatchTables::FVarDataTable _fvarData; + FarPatchTables::PatchMap * _patchMap; // map of the sub-patches given a face index - EvalData _vertexData, - _varyingData; + EvalVertexData _vertexData; // vertex-interpolated data descriptor + EvalData _varyingData, // varying-interpolated data descriptor + _faceVaryingData; // face-varying-interpolated data descriptor - int _maxValence; + int _maxValence, + _fvarwidth; }; -template void -OsdCpuEvalLimitContext::EvalData::Bind( OsdVertexBufferDescriptor const & inDesc, - INPUT_BUFFER *inQ, - OsdVertexBufferDescriptor const & outDesc, - OUTPUT_BUFFER *outQ, - OUTPUT_BUFFER *outdQu, - OUTPUT_BUFFER *outdQv) { - _inDesc = inDesc; - _inQ = inQ ? inQ->BindCpuBuffer() : 0; - - _outDesc = outDesc; - _outQ = outQ ? outQ->BindCpuBuffer() : 0 ; - _outdQu = outdQu ? outdQu->BindCpuBuffer() : 0 ; - _outdQv = outdQv ? outdQv->BindCpuBuffer() : 0 ; -} - - - } // end namespace OPENSUBDIV_VERSION using namespace OPENSUBDIV_VERSION; diff --git a/opensubdiv/osd/cpuEvalLimitController.cpp b/opensubdiv/osd/cpuEvalLimitController.cpp index 8a3f310f..900d5207 100644 --- a/opensubdiv/osd/cpuEvalLimitController.cpp +++ b/opensubdiv/osd/cpuEvalLimitController.cpp @@ -104,9 +104,8 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c unsigned int const * cvs = &context->GetControlVertices()[ parray.GetVertIndex() + handle.vertexOffset ]; - OsdCpuEvalLimitContext::EvalData const & vertexData = context->GetVertexData(), - & varyingData = context->GetVaryingData(); - + OsdCpuEvalLimitContext::EvalVertexData const & vertexData = context->GetVertexData(); + // Position lookup pointers at the indexed vertex float const * inQ = vertexData.GetInputData(); float * outQ = const_cast(vertexData.GetOutputData(index)); @@ -167,6 +166,8 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c default: assert(0); } + + OsdCpuEvalLimitContext::EvalData const & varyingData = context->GetVaryingData(); if (varyingData.IsBound()) { static int indices[5][4] = { {5, 6,10, 9}, // regular @@ -182,13 +183,37 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c cvs[indices[type][2]], cvs[indices[type][3]] }; - evalVarying( v, u, zeroRing, - varyingData.GetInputDesc(), - varyingData.GetInputData(), - varyingData.GetOutputDesc(), - const_cast(varyingData.GetOutputData(index)) ); + evalBilinear( v, u, zeroRing, + varyingData.GetInputDesc(), + varyingData.GetInputData(), + varyingData.GetOutputDesc(), + const_cast(varyingData.GetOutputData(index)) ); } + + // Note : currently we only support bilinear boundary interpolation rules + // for face-varying data. Although Hbr supports 3 addition smooth rule sets, + // the feature-adaptive patch interpolation code currently does not support + // them, and neither does this EvalContext + OsdCpuEvalLimitContext::EvalData const & faceVaryingData = context->GetFaceVaryingData(); + if (faceVaryingData.GetOutputData()) { + + FarPatchTables::FVarDataTable const & fvarData = context->GetFVarData(); + + if (not fvarData.empty()) { + + float const * fvar = &fvarData[ handle.serialIndex * 4 * context->GetFVarWidth() ]; + + static unsigned int zeroRing[4] = {0,1,2,3}; + + evalBilinear( v, u, zeroRing, + faceVaryingData.GetInputDesc(), + fvar, + faceVaryingData.GetOutputDesc(), + const_cast(faceVaryingData.GetOutputData(index)) ); + } + } + return 1; } diff --git a/opensubdiv/osd/cpuEvalLimitKernel.cpp b/opensubdiv/osd/cpuEvalLimitKernel.cpp index 9587e730..e1c7f7db 100644 --- a/opensubdiv/osd/cpuEvalLimitKernel.cpp +++ b/opensubdiv/osd/cpuEvalLimitKernel.cpp @@ -69,12 +69,12 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { void -evalVarying(float u, float v, - unsigned int const * vertexIndices, - OsdVertexBufferDescriptor const & inDesc, - float const * inQ, - OsdVertexBufferDescriptor const & outDesc, - float * outQ) { +evalBilinear(float u, float v, + unsigned int const * vertexIndices, + OsdVertexBufferDescriptor const & inDesc, + float const * inQ, + OsdVertexBufferDescriptor const & outDesc, + float * outQ) { assert( inDesc.length <= (outDesc.stride-outDesc.offset) ); diff --git a/opensubdiv/osd/cpuEvalLimitKernel.h b/opensubdiv/osd/cpuEvalLimitKernel.h index 07b08faf..29015ca0 100644 --- a/opensubdiv/osd/cpuEvalLimitKernel.h +++ b/opensubdiv/osd/cpuEvalLimitKernel.h @@ -65,12 +65,12 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { void -evalVarying(float u, float v, - unsigned int const * vertexIndices, - OsdVertexBufferDescriptor const & inDesc, - float const * inQ, - OsdVertexBufferDescriptor const & outDesc, - float * outQ); +evalBilinear(float u, float v, + unsigned int const * vertexIndices, + OsdVertexBufferDescriptor const & inDesc, + float const * inQ, + OsdVertexBufferDescriptor const & outDesc, + float * outQ); void evalBSpline(float u, float v, diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 46691946..a9207231 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -703,7 +703,7 @@ hbrToObj( OpenSubdiv::HbrMesh * mesh ) { //------------------------------------------------------------------------------ template OpenSubdiv::HbrMesh * -createMesh( Scheme scheme=kCatmark) { +createMesh( Scheme scheme=kCatmark, int fvarwidth=0) { OpenSubdiv::HbrMesh * mesh = 0; @@ -711,10 +711,32 @@ createMesh( Scheme scheme=kCatmark) { static OpenSubdiv::HbrLoopSubdivision _loop; static OpenSubdiv::HbrCatmarkSubdivision _catmark; + static int indices[1] = { 0 }, + widths[1] = { 2 }; + + int const fvarcount = fvarwidth > 0 ? 1 : 0, + * fvarindices = fvarwidth > 0 ? indices : NULL, + * fvarwidths = fvarwidth > 0 ? widths : NULL; + + switch (scheme) { - case kBilinear : mesh = new OpenSubdiv::HbrMesh( &_bilinear ); break; - case kLoop : mesh = new OpenSubdiv::HbrMesh( &_loop ); break; - case kCatmark : mesh = new OpenSubdiv::HbrMesh( &_catmark ); break; + case kBilinear : mesh = new OpenSubdiv::HbrMesh( &_bilinear, + fvarcount, + fvarindices, + fvarwidths, + fvarwidth ); break; + + case kLoop : mesh = new OpenSubdiv::HbrMesh( &_loop, + fvarcount, + fvarindices, + fvarwidths, + fvarwidth ); break; + + case kCatmark : mesh = new OpenSubdiv::HbrMesh( &_catmark, + fvarcount, + fvarindices, + fvarwidths, + fvarwidth ); break; } return mesh; @@ -840,19 +862,55 @@ createTopology( shape const * sh, OpenSubdiv::HbrMesh * mesh, Scheme scheme) mesh->Finish(); } +//------------------------------------------------------------------------------ +template void +createFaceVaryingUV( shape const * sh, OpenSubdiv::HbrMesh * mesh) { + + if (sh->uvs.empty() or sh->faceuvs.empty()) + return; + + for (int i=0, idx=0; igetNfaces(); ++i ) { + + OpenSubdiv::HbrFace * f = mesh->GetFace(i); + + int nv = sh->nvertsPerFace[i]; + + OpenSubdiv::HbrHalfedge * e = f->GetFirstEdge(); + + for (int j=0; jGetNext()) { + + OpenSubdiv::HbrFVarData & fvt = e->GetOrgVertex()->GetFVarData(f); + + float const * fvdata = &sh->uvs[ sh->faceuvs[idx++] ]; + + if (not fvt.IsInitialized()) { + fvt.SetAllData(2, fvdata); + } else if (not fvt.CompareAll(2, fvdata)) { + OpenSubdiv::HbrFVarData & nfvt = e->GetOrgVertex()->NewFVarData(f); + nfvt.SetAllData(2, fvdata); + } + } + } +} + //------------------------------------------------------------------------------ template OpenSubdiv::HbrMesh * -simpleHbr(char const * shapestr, Scheme scheme, std::vector * verts=0) { +simpleHbr(char const * shapestr, Scheme scheme, std::vector * verts=0, bool fvar=false) { shape * sh = shape::parseShape( shapestr ); - OpenSubdiv::HbrMesh * mesh = createMesh(scheme); + int fvarwidth = fvar ? 2 : 0; + + OpenSubdiv::HbrMesh * mesh = createMesh(scheme, fvarwidth); createVertices(sh, mesh, verts); createTopology(sh, mesh, scheme); + + if (fvar) + createFaceVaryingUV(sh, mesh); - if(verts) + if (verts) copyVertexPositions(sh,mesh,*verts); delete sh; @@ -862,16 +920,21 @@ simpleHbr(char const * shapestr, Scheme scheme, std::vector * verts=0) { //------------------------------------------------------------------------------ template OpenSubdiv::HbrMesh * -simpleHbr(char const * shapestr, Scheme scheme, std::vector & verts) { +simpleHbr(char const * shapestr, Scheme scheme, std::vector & verts, bool fvar=false) { shape * sh = shape::parseShape( shapestr ); - OpenSubdiv::HbrMesh * mesh = createMesh(scheme); + int fvarwidth = fvar ? 2 : 0; + + OpenSubdiv::HbrMesh * mesh = createMesh(scheme, fvarwidth); createVertices(sh, mesh, verts); createTopology(sh, mesh, scheme); + if (fvar) + createFaceVaryingUV(sh, mesh); + copyVertexPositions(sh,mesh,verts); delete sh; From f5a7ad4cdb512a2d155164af2c207ba32a965273 Mon Sep 17 00:00:00 2001 From: manuelk Date: Fri, 7 Jun 2013 10:38:10 -0700 Subject: [PATCH 07/32] evalLimit example : make sure to reset the output buffer on creation - some of the prims may not set all the point colors (if face-varying data is missing on the test shape for instance) and we don't want random values creeping from unset memory allocations. --- examples/limitEval/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 168574c3..78bf1041 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -547,12 +547,15 @@ createOsdMesh( const std::string &shape, int level, Scheme scheme=kCatmark ) { delete g_Q; g_Q = OsdCpuGLVertexBuffer::Create(6,nsamples); + memset( g_Q->BindCpuBuffer(), 0, nsamples*6*sizeof(float)); delete g_dQu; g_dQu = OsdCpuGLVertexBuffer::Create(6,nsamples); + memset( g_dQu->BindCpuBuffer(), 0, nsamples*6*sizeof(float)); delete g_dQv; g_dQv = OsdCpuGLVertexBuffer::Create(6,nsamples); + memset( g_dQv->BindCpuBuffer(), 0, nsamples*6*sizeof(float)); updateGeom(); From 307b353b1362d9c2a4d3ffaa0ae8d038a6ff8ac3 Mon Sep 17 00:00:00 2001 From: manuelk Date: Fri, 7 Jun 2013 10:40:11 -0700 Subject: [PATCH 08/32] shape_utils : make sure we don't create a mesh with face-varying data declared if the shape does not actually contain usable face-varying data. --- regression/common/shape_utils.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index a9207231..91f04934 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -129,6 +129,8 @@ struct shape { int getNverts() const { return (int)verts.size()/3; } int getNfaces() const { return (int)nvertsPerFace.size(); } + + bool hasUV() const { return not (uvs.empty() or faceuvs.empty()); } std::vector verts; std::vector uvs; @@ -866,7 +868,7 @@ createTopology( shape const * sh, OpenSubdiv::HbrMesh * mesh, Scheme scheme) template void createFaceVaryingUV( shape const * sh, OpenSubdiv::HbrMesh * mesh) { - if (sh->uvs.empty() or sh->faceuvs.empty()) + if (not sh->hasUV()) return; for (int i=0, idx=0; igetNfaces(); ++i ) { @@ -899,7 +901,7 @@ simpleHbr(char const * shapestr, Scheme scheme, std::vector * verts=0, bo shape * sh = shape::parseShape( shapestr ); - int fvarwidth = fvar ? 2 : 0; + int fvarwidth = fvar and sh->hasUV() ? 2 : 0; OpenSubdiv::HbrMesh * mesh = createMesh(scheme, fvarwidth); @@ -924,7 +926,7 @@ simpleHbr(char const * shapestr, Scheme scheme, std::vector & verts, bool shape * sh = shape::parseShape( shapestr ); - int fvarwidth = fvar ? 2 : 0; + int fvarwidth = fvar and sh->hasUV() ? 2 : 0; OpenSubdiv::HbrMesh * mesh = createMesh(scheme, fvarwidth); From cf1b2f1334ab7e28c028d39c4095a6bb2db4a844 Mon Sep 17 00:00:00 2001 From: manuelk Date: Fri, 7 Jun 2013 14:47:41 -0700 Subject: [PATCH 09/32] - fix a face-varying bug in shape_utils : now face-varying UVs are indexed correctly coming out of our shape format - set blue component of point-cloud to 0 in face-varying mode (save a few micro-secs) --- examples/limitEval/main.cpp | 4 ++-- regression/common/shape_utils.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 78bf1041..51cc73a0 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -475,8 +475,8 @@ updateGeom() { case kVARYING : break; - case kFACEVARYING : { g_Q->BindCpuBuffer()[i*6 + 5] = 0.1f; - } break; + case kFACEVARYING : break; + default : break; } #if defined(OPENSUBDIV_HAS_OPENMP) and defined(USE_OPENMP) diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 91f04934..40f828f4 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -883,8 +883,8 @@ createFaceVaryingUV( shape const * sh, OpenSubdiv::HbrMesh * mesh) { OpenSubdiv::HbrFVarData & fvt = e->GetOrgVertex()->GetFVarData(f); - float const * fvdata = &sh->uvs[ sh->faceuvs[idx++] ]; - + float const * fvdata = &sh->uvs[ sh->faceuvs[idx++]*2 ]; + if (not fvt.IsInitialized()) { fvt.SetAllData(2, fvdata); } else if (not fvt.CompareAll(2, fvdata)) { From 419b6b9716c3a9021386ac78c82739a58d089ca3 Mon Sep 17 00:00:00 2001 From: manuelk Date: Fri, 7 Jun 2013 17:53:23 -0700 Subject: [PATCH 10/32] - add a message to limitEval when trying to display face-varying UVs on shapes that do not have that type of data - fix some regression shapes that had "empty" uv values (including some minor topo surgery that luckily appears to not break regression baselines) --- examples/limitEval/main.cpp | 7 +- regression/shapes/catmark_dart_edgecorner.h | 82 ++++++++++---------- regression/shapes/catmark_dart_edgeonly.h | 82 ++++++++++---------- regression/shapes/catmark_edgecorner.h | 6 +- regression/shapes/catmark_edgeonly.h | 6 +- regression/shapes/catmark_gregory_test3.h | 14 ---- regression/shapes/catmark_pyramid.h | 28 ++++--- regression/shapes/catmark_pyramid_creases0.h | 26 ------- regression/shapes/catmark_pyramid_creases1.h | 26 ------- regression/shapes/catmark_square_hedit0.h | 2 - regression/shapes/catmark_square_hedit1.h | 2 - regression/shapes/catmark_square_hedit2.h | 2 - regression/shapes/catmark_square_hedit3.h | 2 - regression/shapes/catmark_square_hedit4.h | 2 - 14 files changed, 107 insertions(+), 180 deletions(-) diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 51cc73a0..090c8ef8 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -849,7 +849,12 @@ display() { g_hud.DrawString(10, -60, "GPU Draw : %.3f ms", drawGpuTime); g_hud.DrawString(10, -40, "CPU Draw : %.3f ms", drawCpuTime); g_hud.DrawString(10, -20, "FPS : %3.1f", fps); - + + if (g_drawMode==kFACEVARYING and g_evalCtx->GetFVarData().empty()) { + static char msg[21] = "No Face-Varying Data"; + g_hud.DrawString(g_width/2-20/2*8, g_height/2, msg); + } + g_hud.Flush(); } diff --git a/regression/shapes/catmark_dart_edgecorner.h b/regression/shapes/catmark_dart_edgecorner.h index 3d9795e0..752b77f5 100644 --- a/regression/shapes/catmark_dart_edgecorner.h +++ b/regression/shapes/catmark_dart_edgecorner.h @@ -82,31 +82,31 @@ static const std::string catmark_dart_edgecorner = "v -1.000000 0.000000 0.000000\n" "v -0.500000 0.500000 0.000000\n" "v 0.000000 1.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" +"vt 0.000000 0.500000\n" +"vt 0.125000 0.375000\n" +"vt 0.250000 0.500000\n" +"vt 0.125000 0.625000\n" +"vt 0.875000 0.625000\n" +"vt 0.750000 0.500000\n" +"vt 0.875000 0.375000\n" +"vt 1.000000 0.500000\n" +"vt 0.625000 0.125000\n" +"vt 0.500000 0.250000\n" +"vt 0.375000 0.125000\n" +"vt 0.500000 0.000000\n" +"vt 0.750000 0.250000\n" +"vt 0.625000 0.375000\n" +"vt 0.750000 0.750000\n" +"vt 0.625000 0.625000\n" +"vt 0.375000 0.375000\n" +"vt 0.250000 0.250000\n" +"vt 0.500000 0.500000\n" +"vt 0.625000 0.875000\n" +"vt 0.500000 0.750000\n" +"vt 0.375000 0.625000\n" +"vt 0.375000 0.875000\n" +"vt 0.500000 1.000000\n" +"vt 0.250000 0.750000\n" "vn 1.000000 0.000000 0.000000\n" "vn 0.000000 0.000000 1.000000\n" "vn -0.187366 0.000000 0.982290\n" @@ -133,22 +133,22 @@ static const std::string catmark_dart_edgecorner = "vn 1.000000 0.000000 0.000000\n" "vn 0.000000 0.000000 1.000000\n" "s 1\n" -"f 4/1/1 7/7/2 23/23/3 14/14/4\n" -"f 13/13/5 19/19/6 8/8/7 2/3/8\n" -"f 10/10/9 17/17/10 5/5/11 1/4/12\n" -"f 9/9/13 18/18/14 17/17/10 10/10/9\n" -"f 8/8/7 19/19/6 18/18/14 9/9/13\n" -"f 12/12/15 22/22/16 19/19/6 13/13/5\n" -"f 17/17/10 20/20/17 6/6/18 5/5/11\n" -"f 18/18/14 21/21/19 20/20/17 17/17/10\n" -"f 19/19/6 22/22/16 21/21/19 18/18/14\n" -"f 11/11/20 25/25/21 22/22/16 12/12/15\n" -"f 20/20/17 23/23/3 7/7/2 6/6/18\n" -"f 21/21/19 24/24/22 23/23/3 20/20/17\n" -"f 22/22/16 25/25/21 24/24/22 21/21/19\n" -"f 16/16/23 25/25/21 11/11/20 3/2/24\n" -"f 15/15/25 24/24/22 25/25/21 16/16/23\n" -"f 14/14/4 23/23/3 24/24/22 15/15/25\n" +"f 4/1/1 7/2/2 23/3/3 14/4/4\n" +"f 13/5/5 19/6/6 8/7/7 2/8/8\n" +"f 10/9/9 17/10/10 5/11/11 1/12/12\n" +"f 9/13/13 18/14/14 17/10/15 10/9/16\n" +"f 8/7/17 19/6/18 18/14/19 9/13/20\n" +"f 12/15/21 22/16/22 19/6/23 13/5/24\n" +"f 17/10/25 20/17/26 6/18/27 5/11/28\n" +"f 18/14/29 21/19/30 20/17/31 17/10/32\n" +"f 19/6/33 22/16/34 21/19/35 18/14/36\n" +"f 11/20/37 25/21/38 22/16/39 12/15/40\n" +"f 20/17/41 23/3/42 7/2/43 6/18/44\n" +"f 21/19/45 24/22/46 23/3/47 20/17/48\n" +"f 22/16/49 25/21/50 24/22/51 21/19/52\n" +"f 16/23/53 25/21/54 11/20/55 3/24/56\n" +"f 15/25/57 24/22/58 25/21/59 16/23/60\n" +"f 14/4/61 23/3/62 24/22/63 15/25/64\n" "t crease 2/1/0 8 17 2.0\n" "t crease 2/1/0 17 20 2.0\n" "t interpolateboundary 1/0/0 1\n" diff --git a/regression/shapes/catmark_dart_edgeonly.h b/regression/shapes/catmark_dart_edgeonly.h index 20a5a9b6..dca47fab 100644 --- a/regression/shapes/catmark_dart_edgeonly.h +++ b/regression/shapes/catmark_dart_edgeonly.h @@ -82,31 +82,31 @@ static const std::string catmark_dart_edgeonly = "v -1.000000 0.000000 0.000000\n" "v -0.500000 0.500000 0.000000\n" "v 0.000000 1.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" -"vt 0.000000 0.000000\n" +"vt 0.000000 0.500000\n" +"vt 0.125000 0.375000\n" +"vt 0.250000 0.500000\n" +"vt 0.125000 0.625000\n" +"vt 0.875000 0.625000\n" +"vt 0.750000 0.500000\n" +"vt 0.875000 0.375000\n" +"vt 1.000000 0.500000\n" +"vt 0.625000 0.125000\n" +"vt 0.500000 0.250000\n" +"vt 0.375000 0.125000\n" +"vt 0.500000 0.000000\n" +"vt 0.750000 0.250000\n" +"vt 0.625000 0.375000\n" +"vt 0.750000 0.750000\n" +"vt 0.625000 0.625000\n" +"vt 0.375000 0.375000\n" +"vt 0.250000 0.250000\n" +"vt 0.500000 0.500000\n" +"vt 0.625000 0.875000\n" +"vt 0.500000 0.750000\n" +"vt 0.375000 0.625000\n" +"vt 0.375000 0.875000\n" +"vt 0.500000 1.000000\n" +"vt 0.250000 0.750000\n" "vn 1.000000 0.000000 0.000000\n" "vn 0.000000 0.000000 1.000000\n" "vn -0.187366 0.000000 0.982290\n" @@ -133,22 +133,22 @@ static const std::string catmark_dart_edgeonly = "vn 1.000000 0.000000 0.000000\n" "vn 0.000000 0.000000 1.000000\n" "s 1\n" -"f 4/1/1 7/7/2 23/23/3 14/14/4\n" -"f 13/13/5 19/19/6 8/8/7 2/3/8\n" -"f 10/10/9 17/17/10 5/5/11 1/4/12\n" -"f 9/9/13 18/18/14 17/17/10 10/10/9\n" -"f 8/8/7 19/19/6 18/18/14 9/9/13\n" -"f 12/12/15 22/22/16 19/19/6 13/13/5\n" -"f 17/17/10 20/20/17 6/6/18 5/5/11\n" -"f 18/18/14 21/21/19 20/20/17 17/17/10\n" -"f 19/19/6 22/22/16 21/21/19 18/18/14\n" -"f 11/11/20 25/25/21 22/22/16 12/12/15\n" -"f 20/20/17 23/23/3 7/7/2 6/6/18\n" -"f 21/21/19 24/24/22 23/23/3 20/20/17\n" -"f 22/22/16 25/25/21 24/24/22 21/21/19\n" -"f 16/16/23 25/25/21 11/11/20 3/2/24\n" -"f 15/15/25 24/24/22 25/25/21 16/16/23\n" -"f 14/14/4 23/23/3 24/24/22 15/15/25\n" +"f 4/1/1 7/2/2 23/3/3 14/4/4\n" +"f 13/5/5 19/6/6 8/7/7 2/8/8\n" +"f 10/9/9 17/10/10 5/11/11 1/12/12\n" +"f 9/13/13 18/14/14 17/10/15 10/9/16\n" +"f 8/7/17 19/6/18 18/14/19 9/13/20\n" +"f 12/15/21 22/16/22 19/6/23 13/5/24\n" +"f 17/10/25 20/17/26 6/18/27 5/11/28\n" +"f 18/14/29 21/19/30 20/17/31 17/10/32\n" +"f 19/6/33 22/16/34 21/19/35 18/14/36\n" +"f 11/20/37 25/21/38 22/16/39 12/15/40\n" +"f 20/17/41 23/3/42 7/2/43 6/18/44\n" +"f 21/19/45 24/22/46 23/3/47 20/17/48\n" +"f 22/16/49 25/21/50 24/22/51 21/19/52\n" +"f 16/23/53 25/21/54 11/20/55 3/24/56\n" +"f 15/25/57 24/22/58 25/21/59 16/23/60\n" +"f 14/4/61 23/3/62 24/22/63 15/25/64\n" "t crease 2/1/0 8 17 2.0\n" "t crease 2/1/0 17 20 2.0\n" "t interpolateboundary 1/0/0 2\n" diff --git a/regression/shapes/catmark_edgecorner.h b/regression/shapes/catmark_edgecorner.h index f6304a72..0dbf9339 100644 --- a/regression/shapes/catmark_edgecorner.h +++ b/regression/shapes/catmark_edgecorner.h @@ -62,9 +62,9 @@ static const std::string catmark_edgecorner = "v 0.0 2.0 0.0\n" "v -2.0 0.0 0.0\n" "vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" +"vt 1.0 0.0\n" +"vt 0.0 1.0\n" +"vt 1.0 1.0\n" "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" diff --git a/regression/shapes/catmark_edgeonly.h b/regression/shapes/catmark_edgeonly.h index 28bf75f3..10306528 100644 --- a/regression/shapes/catmark_edgeonly.h +++ b/regression/shapes/catmark_edgeonly.h @@ -62,9 +62,9 @@ static const std::string catmark_edgeonly = "v 0.0 2.0 0.0\n" "v -2.0 0.0 0.0\n" "vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" +"vt 1.0 0.0\n" +"vt 0.0 1.0\n" +"vt 1.0 1.0\n" "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" diff --git a/regression/shapes/catmark_gregory_test3.h b/regression/shapes/catmark_gregory_test3.h index a5e84578..c8b993e4 100644 --- a/regression/shapes/catmark_gregory_test3.h +++ b/regression/shapes/catmark_gregory_test3.h @@ -69,20 +69,6 @@ static const std::string catmark_gregory_test3 = "v -2.000000 1.000000 -0.000000\n" "v -2.000000 0.000000 0.000000\n" "v -2.000000 -1.000000 0.000000\n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" -"vt 0 0 \n" "vn 0.518841 0.518841 0.679418\n" "vn 0.606923 0.000000 0.794761\n" "vn 0.518841 -0.518841 0.679418\n" diff --git a/regression/shapes/catmark_pyramid.h b/regression/shapes/catmark_pyramid.h index 3aa1f4fd..773fbd1a 100644 --- a/regression/shapes/catmark_pyramid.h +++ b/regression/shapes/catmark_pyramid.h @@ -62,16 +62,14 @@ static const std::string catmark_pyramid = "v 2.0 0.0 0.0\n" "v 0.0 2.0 0.0\n" "v -2.0 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" +"vt 0.500000 0.000000\n" +"vt 0.000000 0.500000\n" +"vt 0.500000 1.000000\n" +"vt 1.000000 0.500000\n" +"vt 1.000000 1.000000\n" +"vt 0.000000 1.000000\n" +"vt 0.000000 0.000000\n" +"vt 1.000000 0.000000\n" "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" @@ -89,10 +87,10 @@ static const std::string catmark_pyramid = "vn 0.0 0.0 0.0\n" "vn 0.0 0.0 0.0\n" "s off\n" -"f 1/1/1 2/2/2 3/3/3\n" -"f 1/1/1 3/3/3 4/4/4\n" -"f 1/1/1 4/4/4 5/5/5\n" -"f 1/1/1 5/5/5 2/2/2\n" -"f 5/5/5 4/4/4 3/3/3 2/2/2\n" +"f 1/5/1 2/4/2 3/3/3\n" +"f 1/6/1 3/3/3 4/2/4\n" +"f 1/7/1 4/2/4 5/1/5\n" +"f 1/8/1 5/1/5 2/4/2\n" +"f 5/1/5 4/2/4 3/3/3 2/4/2\n" "\n" ; diff --git a/regression/shapes/catmark_pyramid_creases0.h b/regression/shapes/catmark_pyramid_creases0.h index 643be3aa..07916e79 100644 --- a/regression/shapes/catmark_pyramid_creases0.h +++ b/regression/shapes/catmark_pyramid_creases0.h @@ -62,32 +62,6 @@ static const std::string catmark_pyramid_creases0 = "v 2.0 0.0 0.0\n" "v 0.0 2.0 0.0\n" "v -2.0 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/2/2 3/3/3\n" "f 1/1/1 3/3/3 4/4/4\n" diff --git a/regression/shapes/catmark_pyramid_creases1.h b/regression/shapes/catmark_pyramid_creases1.h index bfa6b65f..ff0d7631 100644 --- a/regression/shapes/catmark_pyramid_creases1.h +++ b/regression/shapes/catmark_pyramid_creases1.h @@ -62,32 +62,6 @@ static const std::string catmark_pyramid_creases1 = "v 2.0 0.0 0.0\n" "v 0.0 2.0 0.0\n" "v -2.0 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/2/2 3/3/3\n" "f 1/1/1 3/3/3 4/4/4\n" diff --git a/regression/shapes/catmark_square_hedit0.h b/regression/shapes/catmark_square_hedit0.h index d6143232..32f7cf4f 100644 --- a/regression/shapes/catmark_square_hedit0.h +++ b/regression/shapes/catmark_square_hedit0.h @@ -73,8 +73,6 @@ static const std::string catmark_square_hedit0 = "v -0.333333 1 0\n" "v 0.333333 1 0\n" "v 1 1 0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/1/1 6/1/1 5/1/1\n" "f 2/1/1 3/1/1 7/1/1 6/1/1\n" diff --git a/regression/shapes/catmark_square_hedit1.h b/regression/shapes/catmark_square_hedit1.h index 65548d1c..6407611d 100644 --- a/regression/shapes/catmark_square_hedit1.h +++ b/regression/shapes/catmark_square_hedit1.h @@ -73,8 +73,6 @@ static const std::string catmark_square_hedit1 = "v -0.333333 1 0\n" "v 0.333333 1 0\n" "v 1 1 0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/1/1 6/1/1 5/1/1\n" "f 2/1/1 3/1/1 7/1/1 6/1/1\n" diff --git a/regression/shapes/catmark_square_hedit2.h b/regression/shapes/catmark_square_hedit2.h index adb21fa8..71e5824a 100644 --- a/regression/shapes/catmark_square_hedit2.h +++ b/regression/shapes/catmark_square_hedit2.h @@ -73,8 +73,6 @@ static const std::string catmark_square_hedit2 = "v -0.333333 1 0\n" "v 0.333333 1 0\n" "v 1 1 0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/1/1 6/1/1 5/1/1\n" "f 2/1/1 3/1/1 7/1/1 6/1/1\n" diff --git a/regression/shapes/catmark_square_hedit3.h b/regression/shapes/catmark_square_hedit3.h index d0552dc0..a892f903 100644 --- a/regression/shapes/catmark_square_hedit3.h +++ b/regression/shapes/catmark_square_hedit3.h @@ -73,8 +73,6 @@ static const std::string catmark_square_hedit3 = "v -0.333333 1 0\n" "v 0.333333 1 0\n" "v 1 1 0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/1/1 6/1/1 5/1/1\n" "f 2/1/1 3/1/1 7/1/1 6/1/1\n" diff --git a/regression/shapes/catmark_square_hedit4.h b/regression/shapes/catmark_square_hedit4.h index 050020e1..02e2f9b9 100644 --- a/regression/shapes/catmark_square_hedit4.h +++ b/regression/shapes/catmark_square_hedit4.h @@ -73,8 +73,6 @@ static const std::string catmark_square_hedit4 = "v -0.333333 1 0\n" "v 0.333333 1 0\n" "v 1 1 0\n" -"vt 0.0 0.0\n" -"vn 0.0 0.0 0.0\n" "s off\n" "f 1/1/1 2/1/1 6/1/1 5/1/1\n" "f 2/1/1 3/1/1 7/1/1 6/1/1\n" From 7cb2463dc74ddbf3c43ee1f662878689c5d8377d Mon Sep 17 00:00:00 2001 From: manuelk Date: Mon, 10 Jun 2013 14:36:25 -0700 Subject: [PATCH 11/32] fix FarPatchTables::IsFeatureAdaptive() : - trivial return if Gregory specific patch data is set - or iterate through the patch-arrays until an adaptive patch is found (REGULAR,...,GREGORY_BOUNDARY) fixes #173 --- opensubdiv/far/patchTables.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/opensubdiv/far/patchTables.h b/opensubdiv/far/patchTables.h index cc59467a..b3677fe8 100644 --- a/opensubdiv/far/patchTables.h +++ b/opensubdiv/far/patchTables.h @@ -531,7 +531,23 @@ FarPatchTables::FarPatchTables(PatchArrayVector const & patchArrays, inline bool FarPatchTables::IsFeatureAdaptive() const { - return ((not _vertexValenceTable.empty()) and (not _quadOffsetTable.empty())); + + // the vertex valence table is only used by Gregory patches, so the PatchTables + // contain feature adaptive patches if this is not empty. + if (not _vertexValenceTable.empty()) + return true; + + PatchArrayVector const & parrays = GetPatchArrayVector(); + + // otherwise, we have to check each patch array + for (int i=0; i<(int)parrays.size(); ++i) { + + if (parrays[i].GetDescriptor().GetType() >= REGULAR and + parrays[i].GetDescriptor().GetType() <= GREGORY_BOUNDARY) + return true; + + } + return false; } // Returns the number of control vertices expected for a patch of this type From c18596880934f65d10dba09a1e6794acc5dc56a1 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 11:48:38 -0700 Subject: [PATCH 12/32] Updated glsl code texelFetchBuffer -> texelFetch This allows us to remove unnecessary directives to require GL_EXT_gpu_shader4 --- examples/mayaViewer/shader.glsl | 20 ++-- examples/ptexViewer/shader.glsl | 2 +- opensubdiv/osd/glslPatchBoundary.glsl | 1 - opensubdiv/osd/glslPatchBoundaryGregory.glsl | 113 +++++++++---------- opensubdiv/osd/glslPatchCommon.glsl | 10 +- opensubdiv/osd/glslPatchCorner.glsl | 1 - opensubdiv/osd/glslPatchGregory.glsl | 51 ++++----- opensubdiv/osd/glslPatchRegular.glsl | 3 - opensubdiv/osd/glslPatchTransition.glsl | 3 - 9 files changed, 96 insertions(+), 108 deletions(-) diff --git a/examples/mayaViewer/shader.glsl b/examples/mayaViewer/shader.glsl index 7bf1e46e..1e4c8ffa 100644 --- a/examples/mayaViewer/shader.glsl +++ b/examples/mayaViewer/shader.glsl @@ -152,8 +152,8 @@ void emitUniform(int index, vec3 normal) int uvOffset = gl_PrimitiveID * 4; output.v.patchCoord.st = - vec2( texelFetchBuffer( g_uvFVarBuffer, (uvOffset+index)*2 ).s, - texelFetchBuffer( g_uvFVarBuffer, (uvOffset+index)*2+1 ).s ); + vec2( texelFetch( g_uvFVarBuffer, (uvOffset+index)*2 ).s, + texelFetch( g_uvFVarBuffer, (uvOffset+index)*2+1 ).s ); gl_Position = ProjectionMatrix * input[index].v.position; @@ -200,17 +200,17 @@ void main() int uvOffset = (gl_PrimitiveID+LevelBase) * 4; vec2 uvs[4]; - uvs[0] = vec2( texelFetchBuffer( g_uvFVarBuffer, (uvOffset+0)*2 ).s, - texelFetchBuffer( g_uvFVarBuffer, (uvOffset+0)*2+1 ).s ); + uvs[0] = vec2( texelFetch( g_uvFVarBuffer, (uvOffset+0)*2 ).s, + texelFetch( g_uvFVarBuffer, (uvOffset+0)*2+1 ).s ); - uvs[1] = vec2( texelFetchBuffer( g_uvFVarBuffer, (uvOffset+1)*2 ).s, - texelFetchBuffer( g_uvFVarBuffer, (uvOffset+1)*2+1 ).s ); + uvs[1] = vec2( texelFetch( g_uvFVarBuffer, (uvOffset+1)*2 ).s, + texelFetch( g_uvFVarBuffer, (uvOffset+1)*2+1 ).s ); - uvs[2] = vec2( texelFetchBuffer( g_uvFVarBuffer, (uvOffset+2)*2 ).s, - texelFetchBuffer( g_uvFVarBuffer, (uvOffset+2)*2+1 ).s ); + uvs[2] = vec2( texelFetch( g_uvFVarBuffer, (uvOffset+2)*2 ).s, + texelFetch( g_uvFVarBuffer, (uvOffset+2)*2+1 ).s ); - uvs[3] = vec2( texelFetchBuffer( g_uvFVarBuffer, (uvOffset+3)*2 ).s, - texelFetchBuffer( g_uvFVarBuffer, (uvOffset+3)*2+1 ).s ); + uvs[3] = vec2( texelFetch( g_uvFVarBuffer, (uvOffset+3)*2 ).s, + texelFetch( g_uvFVarBuffer, (uvOffset+3)*2+1 ).s ); #endif vec3 n0 = vec3(0); diff --git a/examples/ptexViewer/shader.glsl b/examples/ptexViewer/shader.glsl index dea67a17..feca0551 100644 --- a/examples/ptexViewer/shader.glsl +++ b/examples/ptexViewer/shader.glsl @@ -65,7 +65,7 @@ uniform float bumpScale = 1.0; vec4 GeneratePatchCoord(vec2 localUV) // for non-adpative { - ivec2 ptexIndex = texelFetchBuffer(g_ptexIndicesBuffer, gl_PrimitiveID).xy; + ivec2 ptexIndex = texelFetch(g_ptexIndicesBuffer, gl_PrimitiveID).xy; int faceID = ptexIndex.x; int lv = 1 << (ptexIndex.y & 0xf); int u = (ptexIndex.y >> 17) & 0x3ff; diff --git a/opensubdiv/osd/glslPatchBoundary.glsl b/opensubdiv/osd/glslPatchBoundary.glsl index 4dace5ac..cf023e8e 100644 --- a/opensubdiv/osd/glslPatchBoundary.glsl +++ b/opensubdiv/osd/glslPatchBoundary.glsl @@ -55,7 +55,6 @@ // a particular purpose and non-infringement. // -#extension GL_EXT_gpu_shader4 : require //---------------------------------------------------------- // Patches.TessVertex //---------------------------------------------------------- diff --git a/opensubdiv/osd/glslPatchBoundaryGregory.glsl b/opensubdiv/osd/glslPatchBoundaryGregory.glsl index 8be684d1..0362702d 100644 --- a/opensubdiv/osd/glslPatchBoundaryGregory.glsl +++ b/opensubdiv/osd/glslPatchBoundaryGregory.glsl @@ -55,7 +55,6 @@ // a particular purpose and non-infringement. // -#extension GL_EXT_gpu_shader4 : require //---------------------------------------------------------- // Patches.TessVertexBoundaryGregory //---------------------------------------------------------- @@ -77,7 +76,7 @@ void main() output.v.hullPosition = (ModelViewMatrix * position).xyz; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); - int valence = texelFetchBuffer(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x; + int valence = texelFetch(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x; output.v.valence = int(valence); uint ivalence = uint(abs(valence)); @@ -96,8 +95,8 @@ void main() uint ip=(i+1)%ivalence; bool isBoundaryNeighbor = false; - uint idx_neighbor = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 0 + 1)).x); - int valenceNeighbor = texelFetchBuffer(g_ValenceBuffer,int(idx_neighbor * (2 * OSD_MAX_VALENCE + 1))).x; + uint idx_neighbor = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 0 + 1)).x); + int valenceNeighbor = texelFetch(g_ValenceBuffer,int(idx_neighbor * (2 * OSD_MAX_VALENCE + 1))).x; if (valenceNeighbor < 0) { isBoundaryNeighbor = true; @@ -116,37 +115,37 @@ void main() } vec3 neighbor = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+2)).x); - uint idx_diagonal = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 1 + 1)).x); + uint idx_diagonal = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 1 + 1)).x); vec3 diagonal = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); - uint idx_neighbor_p = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*ip + 0 + 1)).x); + uint idx_neighbor_p = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*ip + 0 + 1)).x); vec3 neighbor_p = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+2)).x); - uint idx_neighbor_m = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 0 + 1)).x); + uint idx_neighbor_m = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 0 + 1)).x); vec3 neighbor_m = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+2)).x); - uint idx_diagonal_m = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 1 + 1)).x); + uint idx_diagonal_m = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 1 + 1)).x); vec3 diagonal_m = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+2)).x); f[i] = (pos * float(ivalence) + (neighbor_p + neighbor)*2.0f + diagonal) / (float(ivalence)+5.0f); @@ -184,24 +183,24 @@ void main() if (valence < 0) { if (ivalence > 2) { output.v.position = ( - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) + - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) + + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) + + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) + 4.0f * pos)/6.0f; } else { output.v.position = pos; } output.v.e0 = ( - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) - - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) - + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) )/6.0; float k = float(float(ivalence) - 1.0f); //k is the number of faces @@ -212,20 +211,20 @@ void main() float beta_0 = s/(3.0f*k + c); - int idx_diagonal = texelFetchBuffer(g_ValenceBuffer,int((vID) * (2*OSD_MAX_VALENCE+1) + 2*zerothNeighbor + 1 + 1)).x; + int idx_diagonal = texelFetch(g_ValenceBuffer,int((vID) * (2*OSD_MAX_VALENCE+1) + 2*zerothNeighbor + 1 + 1)).x; idx_diagonal = abs(idx_diagonal); vec3 diagonal = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); output.v.e1 = gamma * pos + - alpha_0k * vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) + - alpha_0k * vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) + + alpha_0k * vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) + + alpha_0k * vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) + beta_0 * diagonal; for (uint x=1; x> 17) & 0x3ff; \ diff --git a/opensubdiv/osd/glslPatchCorner.glsl b/opensubdiv/osd/glslPatchCorner.glsl index 9c4f94fa..c39761dc 100644 --- a/opensubdiv/osd/glslPatchCorner.glsl +++ b/opensubdiv/osd/glslPatchCorner.glsl @@ -55,7 +55,6 @@ // a particular purpose and non-infringement. // -#extension GL_EXT_gpu_shader4 : require //---------------------------------------------------------- // Patches.TessVertex //---------------------------------------------------------- diff --git a/opensubdiv/osd/glslPatchGregory.glsl b/opensubdiv/osd/glslPatchGregory.glsl index c7525cd8..f1beea82 100644 --- a/opensubdiv/osd/glslPatchGregory.glsl +++ b/opensubdiv/osd/glslPatchGregory.glsl @@ -55,7 +55,6 @@ // a particular purpose and non-infringement. // -#extension GL_EXT_gpu_shader4 : require //---------------------------------------------------------- // Patches.TessVertexGregory //---------------------------------------------------------- @@ -77,7 +76,7 @@ void main() output.v.hullPosition = (ModelViewMatrix * position).xyz; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); - uint valence = uint(texelFetchBuffer(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x); + uint valence = uint(texelFetch(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x); output.v.valence = int(valence); vec3 f[OSD_MAX_VALENCE]; @@ -88,40 +87,40 @@ void main() uint im=(i+valence-1)%valence; uint ip=(i+1)%valence; - uint idx_neighbor = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 0 + 1)).x); + uint idx_neighbor = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 0 + 1)).x); vec3 neighbor = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+2)).x); - uint idx_diagonal = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 1 + 1)).x); + uint idx_diagonal = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 1 + 1)).x); vec3 diagonal = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); - uint idx_neighbor_p = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*ip + 0 + 1)).x); + uint idx_neighbor_p = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*ip + 0 + 1)).x); vec3 neighbor_p = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+2)).x); - uint idx_neighbor_m = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 0 + 1)).x); + uint idx_neighbor_m = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 0 + 1)).x); vec3 neighbor_m = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+2)).x); - uint idx_diagonal_m = uint(texelFetchBuffer(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 1 + 1)).x); + uint idx_diagonal_m = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 1 + 1)).x); vec3 diagonal_m = - vec3(texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+1)).x, - texelFetchBuffer(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+2)).x); + vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+1)).x, + texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+2)).x); f[i] = (pos * float(valence) + (neighbor_p + neighbor)*2.0 + diagonal) / (float(valence)+5.0); @@ -180,8 +179,8 @@ void main() output[ID].v.position = input[ID].v.position; - uint start = texelFetchBuffer(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x & 0x00ff; - uint prev = uint(texelFetchBuffer(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00; + uint start = texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x & 0x00ff; + uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00; prev=uint(prev/256); // Control Vertices based on : @@ -214,11 +213,11 @@ void main() uint np = input[ip].v.valence; uint nm = input[im].v.valence; - uint prev_p = uint(texelFetchBuffer(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x)&0xff00; + uint prev_p = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x)&0xff00; prev_p=uint(prev_p/256); vec3 Em_ip = input[ip].v.position + input[ip].v.e0*csf(np-3,2*prev_p) +input[ip].v.e1*csf(np-3, 2*prev_p+1); - uint start_m = texelFetchBuffer(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x&0x00ff; + uint start_m = texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x&0x00ff; vec3 Ep_im = input[im].v.position + input[im].v.e0*csf(nm-3, 2*start_m) + input[im].v.e1*csf(nm-3, 2*start_m+1); float s1 = 3 - 2*csf(n-3,2)-csf(np-3,2); diff --git a/opensubdiv/osd/glslPatchRegular.glsl b/opensubdiv/osd/glslPatchRegular.glsl index 0454a859..15b6bca8 100644 --- a/opensubdiv/osd/glslPatchRegular.glsl +++ b/opensubdiv/osd/glslPatchRegular.glsl @@ -55,9 +55,6 @@ // a particular purpose and non-infringement. // -#extension GL_EXT_gpu_shader4 : require -#line 2 - //---------------------------------------------------------- // Patches.TessVertex //---------------------------------------------------------- diff --git a/opensubdiv/osd/glslPatchTransition.glsl b/opensubdiv/osd/glslPatchTransition.glsl index 0285c328..1043f352 100644 --- a/opensubdiv/osd/glslPatchTransition.glsl +++ b/opensubdiv/osd/glslPatchTransition.glsl @@ -55,9 +55,6 @@ // a particular purpose and non-infringement. // -#extension GL_EXT_gpu_shader4 : require -#line 2 - //---------------------------------------------------------- // Patches.Coefficients //---------------------------------------------------------- From e1930e58cd337795daa71388627af2899997a602 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 12:01:43 -0700 Subject: [PATCH 13/32] Fixed some glsl preprocessor tests Changed #if --> #ifdef for OSD_ENABLE_SCREENSPACE_TESSELLATION --- opensubdiv/osd/glslPatchBoundary.glsl | 2 +- opensubdiv/osd/glslPatchBoundaryGregory.glsl | 2 +- opensubdiv/osd/glslPatchCommon.glsl | 2 +- opensubdiv/osd/glslPatchCorner.glsl | 2 +- opensubdiv/osd/glslPatchGregory.glsl | 2 +- opensubdiv/osd/glslPatchRegular.glsl | 2 +- opensubdiv/osd/glslPatchTransition.glsl | 4 +--- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/opensubdiv/osd/glslPatchBoundary.glsl b/opensubdiv/osd/glslPatchBoundary.glsl index cf023e8e..3d280c07 100644 --- a/opensubdiv/osd/glslPatchBoundary.glsl +++ b/opensubdiv/osd/glslPatchBoundary.glsl @@ -129,7 +129,7 @@ void main() if (ID == 0) { OSD_PATCH_CULL(12); -#if OSD_ENABLE_SCREENSPACE_TESSELLATION +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = TessAdaptive(input[1].v.position.xyz, input[2].v.position.xyz, patchLevel); gl_TessLevelOuter[1] = diff --git a/opensubdiv/osd/glslPatchBoundaryGregory.glsl b/opensubdiv/osd/glslPatchBoundaryGregory.glsl index 0362702d..e293a552 100644 --- a/opensubdiv/osd/glslPatchBoundaryGregory.glsl +++ b/opensubdiv/osd/glslPatchBoundaryGregory.glsl @@ -408,7 +408,7 @@ void main() if (ID == 0) { OSD_PATCH_CULL(4); -#if OSD_ENABLE_SCREENSPACE_TESSELLATION +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = TessAdaptive(input[0].v.hullPosition.xyz, input[1].v.hullPosition.xyz, patchLevel); gl_TessLevelOuter[1] = diff --git a/opensubdiv/osd/glslPatchCommon.glsl b/opensubdiv/osd/glslPatchCommon.glsl index f527d2a9..d57d0256 100644 --- a/opensubdiv/osd/glslPatchCommon.glsl +++ b/opensubdiv/osd/glslPatchCommon.glsl @@ -135,7 +135,7 @@ uniform int LevelBase; float GetTessLevel(int patchLevel) { -#if OSD_ENABLE_SCREENSPACE_TESSELLATION +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION return TessLevel; #else return TessLevel / pow(2, patchLevel-1); diff --git a/opensubdiv/osd/glslPatchCorner.glsl b/opensubdiv/osd/glslPatchCorner.glsl index c39761dc..13b9d490 100644 --- a/opensubdiv/osd/glslPatchCorner.glsl +++ b/opensubdiv/osd/glslPatchCorner.glsl @@ -127,7 +127,7 @@ void main() if (ID == 0) { OSD_PATCH_CULL(9); -#if OSD_ENABLE_SCREENSPACE_TESSELLATION +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = TessAdaptive(input[2].v.position.xyz, input[5].v.position.xyz, patchLevel); diff --git a/opensubdiv/osd/glslPatchGregory.glsl b/opensubdiv/osd/glslPatchGregory.glsl index f1beea82..4c2cb32e 100644 --- a/opensubdiv/osd/glslPatchGregory.glsl +++ b/opensubdiv/osd/glslPatchGregory.glsl @@ -243,7 +243,7 @@ void main() if (ID == 0) { OSD_PATCH_CULL(4); -#if OSD_ENABLE_SCREENSPACE_TESSELLATION +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = TessAdaptive(input[0].v.hullPosition.xyz, input[1].v.hullPosition.xyz, patchLevel); gl_TessLevelOuter[1] = diff --git a/opensubdiv/osd/glslPatchRegular.glsl b/opensubdiv/osd/glslPatchRegular.glsl index 15b6bca8..c057431c 100644 --- a/opensubdiv/osd/glslPatchRegular.glsl +++ b/opensubdiv/osd/glslPatchRegular.glsl @@ -130,7 +130,7 @@ void main() if (ID == 0) { OSD_PATCH_CULL(16); -#if OSD_ENABLE_SCREENSPACE_TESSELLATION +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = TessAdaptive(input[5].v.position.xyz, input[9].v.position.xyz, patchLevel); gl_TessLevelOuter[1] = diff --git a/opensubdiv/osd/glslPatchTransition.glsl b/opensubdiv/osd/glslPatchTransition.glsl index 1043f352..a51d3233 100644 --- a/opensubdiv/osd/glslPatchTransition.glsl +++ b/opensubdiv/osd/glslPatchTransition.glsl @@ -184,8 +184,7 @@ void main() if (ID == 0) { OSD_PATCH_CULL(16); -#if OSD_ENABLE_SCREENSPACE_TESSELLATION -#line 1000 +#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION // These tables map the 9, 12, or 16 input control points onto the // canonical 16 control points for a regular patch. #if defined BOUNDARY @@ -206,7 +205,6 @@ void main() const int r[16] = int[]( 3, 7, 11, 15, 2, 6, 10, 14, 1, 5, 9, 13, 0, 4, 8, 12 ); #endif -#line 2000 // Expand and rotate control points using remapping tables above vec3 pv0 = input[p[r[0]]].v.position.xyz; vec3 pv1 = input[p[r[1]]].v.position.xyz; From 2551c3244896608854413468cf621c66b7316087 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 12:20:08 -0700 Subject: [PATCH 14/32] Fixed glsl shader portability - defined a fallback value for ROTATE - made GetPatchLevel() a macro to avoid referencing gl_PrimitiveID from vertex shaders - fixed float array initializers --- opensubdiv/osd/glslPatchCommon.glsl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/opensubdiv/osd/glslPatchCommon.glsl b/opensubdiv/osd/glslPatchCommon.glsl index d57d0256..37cceb1c 100644 --- a/opensubdiv/osd/glslPatchCommon.glsl +++ b/opensubdiv/osd/glslPatchCommon.glsl @@ -63,6 +63,10 @@ #define OSD_NUM_VARYINGS 0 #endif +#ifndef ROTATE +#define ROTATE 0 +#endif + #define M_PI 3.14159265359f struct ControlVertex { @@ -164,12 +168,8 @@ float TessAdaptive(vec3 p0, vec3 p1, int patchLevel) uniform isamplerBuffer g_ptexIndicesBuffer; -int GetPatchLevel() -{ - ivec2 ptexIndex = texelFetch(g_ptexIndicesBuffer, - gl_PrimitiveID + LevelBase).xy; - return (ptexIndex.y & 0xf); -} +#define GetPatchLevel() \ + (texelFetch(g_ptexIndicesBuffer, gl_PrimitiveID + LevelBase).y & 0xf) #define OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER \ { \ @@ -270,12 +270,12 @@ uniform mat4 R = mat4( ); #if OSD_MAX_VALENCE<=10 -uniform float ef[7] = { +uniform float ef[7] = float[]( 0.813008, 0.500000, 0.363636, 0.287505, 0.238692, 0.204549, 0.179211 -}; +); #else -uniform float ef[27] = { +uniform float ef[27] = float[]( 0.812816, 0.500000, 0.363644, 0.287514, 0.238688, 0.204544, 0.179229, 0.159657, 0.144042, 0.131276, 0.120632, 0.111614, @@ -283,7 +283,7 @@ uniform float ef[27] = { 0.0814022, 0.0772401, 0.0734867, 0.0700842, 0.0669851, 0.0641504, 0.0615475, 0.0591488, 0.0569311, 0.0548745, 0.0529621 -}; +); #endif float csf(uint n, uint j) From ffe427dc65c34b313818b3548ff3264b799e0c35 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 12:32:45 -0700 Subject: [PATCH 15/32] Fixed glsl unsigned conversions in Gregory shaders --- opensubdiv/osd/glslPatchBoundaryGregory.glsl | 8 ++++---- opensubdiv/osd/glslPatchGregory.glsl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/opensubdiv/osd/glslPatchBoundaryGregory.glsl b/opensubdiv/osd/glslPatchBoundaryGregory.glsl index e293a552..9272501a 100644 --- a/opensubdiv/osd/glslPatchBoundaryGregory.glsl +++ b/opensubdiv/osd/glslPatchBoundaryGregory.glsl @@ -285,8 +285,8 @@ void main() output[ID].v.position = input[ID].v.position; - uint start = texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x & 0x00ff; - uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00; + uint start = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0x00ffu; + uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00u; prev=uint(prev/256); uint np = abs(input[ip].v.valence); uint nm = abs(input[im].v.valence); @@ -320,7 +320,7 @@ void main() vec3 Fp = vec3(0.0f,0.0f,0.0f); vec3 Fm = vec3(0.0f,0.0f,0.0f); - uint prev_p = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x)&0xff00; + uint prev_p = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x) & 0xff00u; prev_p=uint(prev_p/256); vec3 Em_ip; @@ -331,7 +331,7 @@ void main() Em_ip = input[ip].v.position + input[ip].v.e0*csf(np-3,2*prev_p) + input[ip].v.e1*csf(np-3,2*prev_p+1); } - uint start_m = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x)&0x00ff; + uint start_m = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x) & 0x00ffu; vec3 Ep_im; if (input[im].v.valence < -2) { diff --git a/opensubdiv/osd/glslPatchGregory.glsl b/opensubdiv/osd/glslPatchGregory.glsl index 4c2cb32e..4cd68ad2 100644 --- a/opensubdiv/osd/glslPatchGregory.glsl +++ b/opensubdiv/osd/glslPatchGregory.glsl @@ -179,8 +179,8 @@ void main() output[ID].v.position = input[ID].v.position; - uint start = texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x & 0x00ff; - uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00; + uint start = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0x00ffu; + uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00u; prev=uint(prev/256); // Control Vertices based on : @@ -213,11 +213,11 @@ void main() uint np = input[ip].v.valence; uint nm = input[im].v.valence; - uint prev_p = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x)&0xff00; + uint prev_p = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x) & 0xff00u; prev_p=uint(prev_p/256); vec3 Em_ip = input[ip].v.position + input[ip].v.e0*csf(np-3,2*prev_p) +input[ip].v.e1*csf(np-3, 2*prev_p+1); - uint start_m = texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x&0x00ff; + uint start_m = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x) & 0x00ffu; vec3 Ep_im = input[im].v.position + input[im].v.e0*csf(nm-3, 2*start_m) + input[im].v.e1*csf(nm-3, 2*start_m+1); float s1 = 3 - 2*csf(n-3,2)-csf(np-3,2); From 1461deb308b3cb3d7e4531f756b5e32ccfac19fd Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 12:53:04 -0700 Subject: [PATCH 16/32] Fixed glsl shader portability (input,output) --- examples/glBatchViewer/shader.glsl | 70 +++---- examples/glViewer/shader.glsl | 70 +++---- examples/mayaPtexViewer/shader.glsl | 96 ++++----- examples/mayaViewer/shader.glsl | 56 ++--- examples/paintTest/paintShader.glsl | 46 ++--- examples/paintTest/shader.glsl | 64 +++--- examples/ptexViewer/shader.glsl | 136 ++++++------- examples/ptexViewer/shader_gl3.glsl | 10 +- opensubdiv/osd/glslPatchBoundary.glsl | 54 ++--- opensubdiv/osd/glslPatchBoundaryGregory.glsl | 204 +++++++++---------- opensubdiv/osd/glslPatchCommon.glsl | 30 +-- opensubdiv/osd/glslPatchCorner.glsl | 52 ++--- opensubdiv/osd/glslPatchGregory.glsl | 134 ++++++------ opensubdiv/osd/glslPatchRegular.glsl | 54 ++--- opensubdiv/osd/glslPatchTransition.glsl | 88 ++++---- 15 files changed, 582 insertions(+), 582 deletions(-) diff --git a/examples/glBatchViewer/shader.glsl b/examples/glBatchViewer/shader.glsl index f921689f..fd419faf 100644 --- a/examples/glBatchViewer/shader.glsl +++ b/examples/glBatchViewer/shader.glsl @@ -65,12 +65,12 @@ layout (location=1) in vec3 normal; out block { OutputVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; - output.v.normal = (ModelViewMatrix * vec4(normal, 0.0)).xyz; + outpt.v.position = ModelViewMatrix * position; + outpt.v.normal = (ModelViewMatrix * vec4(normal, 0.0)).xyz; } #endif @@ -90,7 +90,7 @@ void main() in block { OutputVertex v; - } input[4]; + } inpt[4]; #endif // PRIM_QUAD @@ -104,7 +104,7 @@ void main() in block { OutputVertex v; - } input[3]; + } inpt[3]; #endif // PRIM_TRI @@ -115,23 +115,23 @@ void main() in block { OutputVertex v; - } input[1]; + } inpt[1]; #endif // PRIM_POINT out block { OutputVertex v; -} output; +} outpt; void emit(int index, vec3 normal) { - output.v.position = input[index].v.position; + outpt.v.position = inpt[index].v.position; #ifdef SMOOTH_NORMALS - output.v.normal = input[index].v.normal; + outpt.v.normal = inpt[index].v.normal; #else - output.v.normal = normal; + outpt.v.normal = normal; #endif - gl_Position = ProjectionMatrix * input[index].v.position; + gl_Position = ProjectionMatrix * inpt[index].v.position; EmitVertex(); } @@ -147,18 +147,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS]) { - output.v.edgeDistance[0] = + outpt.v.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - output.v.edgeDistance[1] = + outpt.v.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); #ifdef PRIM_TRI - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); #endif #ifdef PRIM_QUAD - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]); - output.v.edgeDistance[3] = + outpt.v.edgeDistance[3] = edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]); #endif @@ -175,17 +175,17 @@ void main() #endif #ifdef PRIM_QUAD - vec3 A = (input[0].v.position - input[1].v.position).xyz; - vec3 B = (input[3].v.position - input[1].v.position).xyz; - vec3 C = (input[2].v.position - input[1].v.position).xyz; + vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz; + vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz; + vec3 C = (inpt[2].v.position - inpt[1].v.position).xyz; vec3 n0 = normalize(cross(B, A)); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; - edgeVerts[3] = ProjectionMatrix * input[3].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; + edgeVerts[3] = ProjectionMatrix * inpt[3].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -205,15 +205,15 @@ void main() #endif // PRIM_QUAD #ifdef PRIM_TRI - vec3 A = (input[1].v.position - input[0].v.position).xyz; - vec3 B = (input[2].v.position - input[0].v.position).xyz; + vec3 A = (inpt[1].v.position - inpt[0].v.position).xyz; + vec3 B = (inpt[2].v.position - inpt[0].v.position).xyz; vec3 n0 = normalize(cross(B, A)); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -241,7 +241,7 @@ void main() in block { OutputVertex v; -} input; +} inpt; out vec4 outColor; @@ -303,12 +303,12 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) #ifdef PRIM_TRI float d = - min(input.v.edgeDistance[0], min(input.v.edgeDistance[1], input.v.edgeDistance[2])); + min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); #endif #ifdef PRIM_QUAD float d = - min(min(input.v.edgeDistance[0], input.v.edgeDistance[1]), - min(input.v.edgeDistance[2], input.v.edgeDistance[3])); + min(min(inpt.v.edgeDistance[0], inpt.v.edgeDistance[1]), + min(inpt.v.edgeDistance[2], inpt.v.edgeDistance[3])); #endif vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0); float p = exp2(-2 * d * d); @@ -326,11 +326,11 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) void main() { - vec3 N = (gl_FrontFacing ? input.v.normal : -input.v.normal); - vec4 Cf = lighting(input.v.position.xyz, N); + vec3 N = (gl_FrontFacing ? inpt.v.normal : -inpt.v.normal); + vec4 Cf = lighting(inpt.v.position.xyz, N); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) - Cf = edgeColor(Cf, input.v.edgeDistance); + Cf = edgeColor(Cf, inpt.v.edgeDistance); #endif outColor = Cf; diff --git a/examples/glViewer/shader.glsl b/examples/glViewer/shader.glsl index f921689f..fd419faf 100644 --- a/examples/glViewer/shader.glsl +++ b/examples/glViewer/shader.glsl @@ -65,12 +65,12 @@ layout (location=1) in vec3 normal; out block { OutputVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; - output.v.normal = (ModelViewMatrix * vec4(normal, 0.0)).xyz; + outpt.v.position = ModelViewMatrix * position; + outpt.v.normal = (ModelViewMatrix * vec4(normal, 0.0)).xyz; } #endif @@ -90,7 +90,7 @@ void main() in block { OutputVertex v; - } input[4]; + } inpt[4]; #endif // PRIM_QUAD @@ -104,7 +104,7 @@ void main() in block { OutputVertex v; - } input[3]; + } inpt[3]; #endif // PRIM_TRI @@ -115,23 +115,23 @@ void main() in block { OutputVertex v; - } input[1]; + } inpt[1]; #endif // PRIM_POINT out block { OutputVertex v; -} output; +} outpt; void emit(int index, vec3 normal) { - output.v.position = input[index].v.position; + outpt.v.position = inpt[index].v.position; #ifdef SMOOTH_NORMALS - output.v.normal = input[index].v.normal; + outpt.v.normal = inpt[index].v.normal; #else - output.v.normal = normal; + outpt.v.normal = normal; #endif - gl_Position = ProjectionMatrix * input[index].v.position; + gl_Position = ProjectionMatrix * inpt[index].v.position; EmitVertex(); } @@ -147,18 +147,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS]) { - output.v.edgeDistance[0] = + outpt.v.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - output.v.edgeDistance[1] = + outpt.v.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); #ifdef PRIM_TRI - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); #endif #ifdef PRIM_QUAD - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]); - output.v.edgeDistance[3] = + outpt.v.edgeDistance[3] = edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]); #endif @@ -175,17 +175,17 @@ void main() #endif #ifdef PRIM_QUAD - vec3 A = (input[0].v.position - input[1].v.position).xyz; - vec3 B = (input[3].v.position - input[1].v.position).xyz; - vec3 C = (input[2].v.position - input[1].v.position).xyz; + vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz; + vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz; + vec3 C = (inpt[2].v.position - inpt[1].v.position).xyz; vec3 n0 = normalize(cross(B, A)); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; - edgeVerts[3] = ProjectionMatrix * input[3].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; + edgeVerts[3] = ProjectionMatrix * inpt[3].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -205,15 +205,15 @@ void main() #endif // PRIM_QUAD #ifdef PRIM_TRI - vec3 A = (input[1].v.position - input[0].v.position).xyz; - vec3 B = (input[2].v.position - input[0].v.position).xyz; + vec3 A = (inpt[1].v.position - inpt[0].v.position).xyz; + vec3 B = (inpt[2].v.position - inpt[0].v.position).xyz; vec3 n0 = normalize(cross(B, A)); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -241,7 +241,7 @@ void main() in block { OutputVertex v; -} input; +} inpt; out vec4 outColor; @@ -303,12 +303,12 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) #ifdef PRIM_TRI float d = - min(input.v.edgeDistance[0], min(input.v.edgeDistance[1], input.v.edgeDistance[2])); + min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); #endif #ifdef PRIM_QUAD float d = - min(min(input.v.edgeDistance[0], input.v.edgeDistance[1]), - min(input.v.edgeDistance[2], input.v.edgeDistance[3])); + min(min(inpt.v.edgeDistance[0], inpt.v.edgeDistance[1]), + min(inpt.v.edgeDistance[2], inpt.v.edgeDistance[3])); #endif vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0); float p = exp2(-2 * d * d); @@ -326,11 +326,11 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) void main() { - vec3 N = (gl_FrontFacing ? input.v.normal : -input.v.normal); - vec4 Cf = lighting(input.v.position.xyz, N); + vec3 N = (gl_FrontFacing ? inpt.v.normal : -inpt.v.normal); + vec4 Cf = lighting(inpt.v.position.xyz, N); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) - Cf = edgeColor(Cf, input.v.edgeDistance); + Cf = edgeColor(Cf, inpt.v.edgeDistance); #endif outColor = Cf; diff --git a/examples/mayaPtexViewer/shader.glsl b/examples/mayaPtexViewer/shader.glsl index 89cf01c4..ad4ff50a 100644 --- a/examples/mayaPtexViewer/shader.glsl +++ b/examples/mayaPtexViewer/shader.glsl @@ -94,11 +94,11 @@ vec4 PTexLookup(vec4 patchCoord, #ifdef USE_PTEX_DISPLACEMENT -#define OSD_DISPLACEMENT_CALLBACK \ - output.v.position = \ - displacement(output.v.position, \ - output.v.normal, \ - output.v.patchCoord); +#define OSD_DISPLACEMENT_CALLBACK \ + outpt.v.position = \ + displacement(outpt.v.position, \ + outpt.v.normal, \ + outpt.v.patchCoord); uniform sampler2DArray textureDisplace_Data; uniform samplerBuffer textureDisplace_Packing; @@ -124,12 +124,12 @@ layout (location=1) in vec3 normal; out block { OutputVertex v; -} output; +} outpt; void main() { - output.v.position = vec4(position, 1); - output.v.normal = normal; + outpt.v.position = vec4(position, 1); + outpt.v.normal = normal; } #endif // VERTEX_SHADER @@ -153,7 +153,7 @@ void main() in block { OutputVertex v; - } input[4]; + } inpt[4]; #endif // PRIM_QUAD @@ -171,23 +171,23 @@ void main() in block { OutputVertex v; - } input[3]; + } inpt[3]; #endif // PRIM_TRI out block { OutputVertex v; -} output; +} outpt; void emit(int index, vec4 position, vec3 normal, vec4 patchCoord) { - output.v.position = position; - output.v.normal = normal; - output.v.patchCoord = patchCoord; + outpt.v.position = position; + outpt.v.normal = normal; + outpt.v.patchCoord = patchCoord; - output.v.tangent = input[index].v.tangent; + outpt.v.tangent = inpt[index].v.tangent; - gl_Position = ProjectionMatrix * output.v.position; + gl_Position = ProjectionMatrix * outpt.v.position; EmitVertex(); } @@ -210,15 +210,15 @@ void main() patchCoord[3] = GeneratePatchCoord(vec2(0, 1)); #ifdef USE_PTEX_DISPLACEMENT - position[0] = displacement(input[0].v.position, input[0].v.normal, patchCoord[0]); - position[1] = displacement(input[1].v.position, input[1].v.normal, patchCoord[1]); - position[2] = displacement(input[2].v.position, input[2].v.normal, patchCoord[2]); - position[3] = displacement(input[3].v.position, input[3].v.normal, patchCoord[3]); + position[0] = displacement(inpt[0].v.position, inpt[0].v.normal, patchCoord[0]); + position[1] = displacement(inpt[1].v.position, inpt[1].v.normal, patchCoord[1]); + position[2] = displacement(inpt[2].v.position, inpt[2].v.normal, patchCoord[2]); + position[3] = displacement(inpt[3].v.position, inpt[3].v.normal, patchCoord[3]); #else - position[0] = input[0].v.position; - position[1] = input[1].v.position; - position[2] = input[2].v.position; - position[3] = input[3].v.position; + position[0] = inpt[0].v.position; + position[1] = inpt[1].v.position; + position[2] = inpt[2].v.position; + position[3] = inpt[3].v.position; #endif #ifdef FLAT_NORMALS @@ -231,10 +231,10 @@ void main() normal[2] = normal[0]; normal[3] = normal[0]; #else - normal[0] = input[0].v.normal; - normal[1] = input[1].v.normal; - normal[2] = input[2].v.normal; - normal[3] = input[3].v.normal; + normal[0] = inpt[0].v.normal; + normal[1] = inpt[1].v.normal; + normal[2] = inpt[2].v.normal; + normal[3] = inpt[3].v.normal; #endif emit(0, position[0], normal[0], patchCoord[0]); @@ -257,18 +257,18 @@ void main() vec3 normal[3]; // patch coords are computed in tessellation shader - patchCoord[0] = input[0].v.patchCoord; - patchCoord[1] = input[1].v.patchCoord; - patchCoord[2] = input[2].v.patchCoord; + patchCoord[0] = inpt[0].v.patchCoord; + patchCoord[1] = inpt[1].v.patchCoord; + patchCoord[2] = inpt[2].v.patchCoord; #ifdef USE_PTEX_DISPLACEMENT - position[0] = displacement(input[0].v.position, input[0].v.normal, patchCoord[0]); - position[1] = displacement(input[1].v.position, input[1].v.normal, patchCoord[1]); - position[2] = displacement(input[2].v.position, input[2].v.normal, patchCoord[2]); + position[0] = displacement(inpt[0].v.position, inpt[0].v.normal, patchCoord[0]); + position[1] = displacement(inpt[1].v.position, inpt[1].v.normal, patchCoord[1]); + position[2] = displacement(inpt[2].v.position, inpt[2].v.normal, patchCoord[2]); #else - position[0] = input[0].v.position; - position[1] = input[1].v.position; - position[2] = input[2].v.position; + position[0] = inpt[0].v.position; + position[1] = inpt[1].v.position; + position[2] = inpt[2].v.position; #endif #ifdef FLAT_NORMALS // emit flat normals for displaced surface @@ -278,9 +278,9 @@ void main() normal[1] = normal[0]; normal[2] = normal[0]; #else - normal[0] = input[0].v.normal; - normal[1] = input[1].v.normal; - normal[2] = input[2].v.normal; + normal[0] = inpt[0].v.normal; + normal[1] = inpt[1].v.normal; + normal[2] = inpt[2].v.normal; #endif emit(0, position[0], normal[0], patchCoord[0]); @@ -303,7 +303,7 @@ void main() in block { OutputVertex v; -} input; +} inpt; uniform int ptexFaceOffset; @@ -398,7 +398,7 @@ void main() { #ifdef USE_PTEX_COLOR - vec4 texColor = PTexLookup(input.v.patchCoord, + vec4 texColor = PTexLookup(inpt.v.patchCoord, textureImage_Data, textureImage_Packing, textureImage_Pages); @@ -407,16 +407,16 @@ main() #endif #if USE_PTEX_NORMAL - vec3 objN = perturbNormalFromDisplacement(input.v.position.xyz, - input.v.normal, - input.v.patchCoord); + vec3 objN = perturbNormalFromDisplacement(inpt.v.position.xyz, + inpt.v.normal, + inpt.v.patchCoord); #else - vec3 objN = input.v.normal; + vec3 objN = inpt.v.normal; #endif #ifdef USE_PTEX_OCCLUSION - float occ = PTexLookup(input.v.patchCoord, + float occ = PTexLookup(inpt.v.patchCoord, textureOcclusion_Data, textureOcclusion_Packing, textureOcclusion_Pages).x; @@ -432,7 +432,7 @@ main() vec4 d = vec4(1); #endif - vec3 eye = normalize(input.v.position.xyz - eyePositionInWorld); + vec3 eye = normalize(inpt.v.position.xyz - eyePositionInWorld); #ifdef USE_SPECULAR_ENV_MAP vec3 reflect = reflect(eye, objN); diff --git a/examples/mayaViewer/shader.glsl b/examples/mayaViewer/shader.glsl index 1e4c8ffa..b574a785 100644 --- a/examples/mayaViewer/shader.glsl +++ b/examples/mayaViewer/shader.glsl @@ -65,11 +65,11 @@ layout (location=0) in vec4 position; out block { OutputVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; + outpt.v.position = ModelViewMatrix * position; } #endif // VERTEX_SHADER @@ -95,7 +95,7 @@ uniform samplerBuffer g_uvFVarBuffer; in block { OutputVertex v; - } input[4]; + } inpt[4]; #endif // PRIM_QUAD @@ -113,7 +113,7 @@ uniform samplerBuffer g_uvFVarBuffer; in block { OutputVertex v; - } input[3]; + } inpt[3]; #endif // PRIM_TRI @@ -124,21 +124,21 @@ uniform samplerBuffer g_uvFVarBuffer; in block { OutputVertex v; - } input[1]; + } inpt[1]; #endif // PRIM_POINT out block { OutputVertex v; -} output; +} outpt; void emitUniform(int index, vec3 normal) { - output.v.position = input[index].v.position; + outpt.v.position = inpt[index].v.position; #ifdef SMOOTH_NORMALS - output.v.normal = input[index].v.normal; + outpt.v.normal = inpt[index].v.normal; #else - output.v.normal = normal; + outpt.v.normal = normal; #endif // We fetch each uv component separately since the texture buffer @@ -151,32 +151,32 @@ void emitUniform(int index, vec3 normal) // prim 0 prim 1 int uvOffset = gl_PrimitiveID * 4; - output.v.patchCoord.st = + outpt.v.patchCoord.st = vec2( texelFetch( g_uvFVarBuffer, (uvOffset+index)*2 ).s, texelFetch( g_uvFVarBuffer, (uvOffset+index)*2+1 ).s ); - gl_Position = ProjectionMatrix * input[index].v.position; + gl_Position = ProjectionMatrix * inpt[index].v.position; EmitVertex(); } void emitAdaptive(int index, vec3 normal, vec2 uvs[4]) { - output.v.position = input[index].v.position; + outpt.v.position = inpt[index].v.position; #ifdef SMOOTH_NORMALS - output.v.normal = input[index].v.normal; + outpt.v.normal = inpt[index].v.normal; #else - output.v.normal = normal; + outpt.v.normal = normal; #endif // Bi-linear interpolation within the patch - output.v.patchCoord = input[index].v.patchCoord; - vec2 st = input[index].v.tessCoord; - output.v.patchCoord.st = + outpt.v.patchCoord = inpt[index].v.patchCoord; + vec2 st = inpt[index].v.tessCoord; + outpt.v.patchCoord.st = vec2( mix( mix(uvs[0].x, uvs[1].x, st.s ), mix(uvs[3].x, uvs[2].x, st.s ), st.t), mix( mix(uvs[0].y, uvs[1].y, st.s ), mix(uvs[3].y, uvs[2].y, st.s ), st.t) ); - gl_Position = ProjectionMatrix * input[index].v.position; + gl_Position = ProjectionMatrix * inpt[index].v.position; EmitVertex(); } @@ -221,8 +221,8 @@ void main() #elif defined ( PRIM_TRI) - vec3 A = (input[1].v.position - input[0].v.position).xyz; - vec3 B = (input[2].v.position - input[0].v.position).xyz; + vec3 A = (inpt[1].v.position - inpt[0].v.position).xyz; + vec3 B = (inpt[2].v.position - inpt[0].v.position).xyz; n0 = normalize(cross(B, A)); #ifdef FVAR_ADAPTIVE emitAdaptive(0, n0, uvs); @@ -245,9 +245,9 @@ void main() #elif defined ( PRIM_QUAD ) - vec3 A = (input[0].v.position - input[1].v.position).xyz; - vec3 B = (input[3].v.position - input[1].v.position).xyz; - //vec3 C = (input[2].v.position - input[1].v.position).xyz; + vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz; + vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz; + //vec3 C = (inpt[2].v.position - inpt[1].v.position).xyz; n0 = normalize(cross(B, A)); #ifdef GEOMETRY_OUT_FILL @@ -279,7 +279,7 @@ uniform sampler2D diffuseMap; in block { OutputVertex v; -} input; +} inpt; #define NUM_LIGHTS 2 @@ -349,12 +349,12 @@ main() void main() { - vec3 N = (gl_FrontFacing ? input.v.normal : -input.v.normal); + vec3 N = (gl_FrontFacing ? inpt.v.normal : -inpt.v.normal); #ifdef USE_DIFFUSE_MAP - vec4 texColor = texture(diffuseMap, input.v.patchCoord.st); - gl_FragColor = lighting(input.v.position.xyz, N, texColor); + vec4 texColor = texture(diffuseMap, inpt.v.patchCoord.st); + gl_FragColor = lighting(inpt.v.position.xyz, N, texColor); #else - gl_FragColor = lighting(input.v.position.xyz, N, vec4(1.0)); + gl_FragColor = lighting(inpt.v.position.xyz, N, vec4(1.0)); #endif } #endif // GEOMETRY_OUT_LINE diff --git a/examples/paintTest/paintShader.glsl b/examples/paintTest/paintShader.glsl index 47de444d..02a3e77a 100644 --- a/examples/paintTest/paintShader.glsl +++ b/examples/paintTest/paintShader.glsl @@ -94,11 +94,11 @@ layout (location=0) in vec4 position; out block { OutputVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; + outpt.v.position = ModelViewMatrix * position; } #endif @@ -114,19 +114,19 @@ layout(triangle_strip, max_vertices = 3) out; in block { OutputVertex v; -} input[3]; +} inpt[3]; out block { OutputVertex v; vec4 depthPosition; -} output; +} outpt; void emit(int index, vec4 position) { - vec2 uv = vec2(input[index].v.patchCoord.xy); - output.v.position = ProjectionMatrix * position; - output.depthPosition = ProjectionWithoutPickMatrix * position; - output.v.patchCoord = input[index].v.patchCoord; + vec2 uv = vec2(inpt[index].v.patchCoord.xy); + outpt.v.position = ProjectionMatrix * position; + outpt.depthPosition = ProjectionWithoutPickMatrix * position; + outpt.v.patchCoord = inpt[index].v.patchCoord; gl_Position = vec4(uv*2-vec2(1.0), 0, 1); EmitVertex(); } @@ -139,18 +139,18 @@ void main() vec4 position[3]; // patch coords are computed in tessellation shader - patchCoord[0] = input[0].v.patchCoord; - patchCoord[1] = input[1].v.patchCoord; - patchCoord[2] = input[2].v.patchCoord; + patchCoord[0] = inpt[0].v.patchCoord; + patchCoord[1] = inpt[1].v.patchCoord; + patchCoord[2] = inpt[2].v.patchCoord; #ifdef USE_PTEX_DISPLACEMENT - position[0] = displacement(input[0].v.position, input[0].v.normal, patchCoord[0]); - position[1] = displacement(input[1].v.position, input[1].v.normal, patchCoord[1]); - position[2] = displacement(input[2].v.position, input[2].v.normal, patchCoord[2]); + position[0] = displacement(inpt[0].v.position, inpt[0].v.normal, patchCoord[0]); + position[1] = displacement(inpt[1].v.position, inpt[1].v.normal, patchCoord[1]); + position[2] = displacement(inpt[2].v.position, inpt[2].v.normal, patchCoord[2]); #else - position[0] = input[0].v.position; - position[1] = input[1].v.position; - position[2] = input[2].v.position; + position[0] = inpt[0].v.position; + position[1] = inpt[1].v.position; + position[2] = inpt[2].v.position; #endif emit(0, position[0]); @@ -169,7 +169,7 @@ void main() in block { OutputVertex v; vec4 depthPosition; -} input; +} inpt; layout(size1x32) uniform image2DArray outTextureImage; uniform sampler2D paintTexture; @@ -179,10 +179,10 @@ uniform int imageSize = 256; void main() { - vec4 p = input.v.position; + vec4 p = inpt.v.position; p.xyz /= p.w; - vec4 wp = input.depthPosition; + vec4 wp = inpt.depthPosition; wp.z -= 0.001; wp.xyz /= wp.w; @@ -190,9 +190,9 @@ main() float depth = texture(depthTexture, wp.xy*0.5+0.5).x; if (wp.z*0.5+0.5 >= depth) return; - ivec3 pos = ivec3(input.v.patchCoord.x * imageSize, - input.v.patchCoord.y * imageSize, - int(input.v.patchCoord.w)); + ivec3 pos = ivec3(inpt.v.patchCoord.x * imageSize, + inpt.v.patchCoord.y * imageSize, + int(inpt.v.patchCoord.w)); vec4 d = imageLoad(outTextureImage, pos); c = c + d; diff --git a/examples/paintTest/shader.glsl b/examples/paintTest/shader.glsl index 150521d6..93ec142e 100644 --- a/examples/paintTest/shader.glsl +++ b/examples/paintTest/shader.glsl @@ -97,19 +97,19 @@ vec4 displacement(vec4 position, vec3 normal, vec4 patchCoord) in block { OutputVertex v; - } input[3]; + } inpt[3]; out block { OutputVertex v; -} output; +} outpt; void emit(int index, vec4 position, vec3 normal, vec4 patchCoord) { - output.v.position = position; - output.v.patchCoord = patchCoord; - output.v.normal = normal; + outpt.v.position = position; + outpt.v.patchCoord = patchCoord; + outpt.v.normal = normal; - gl_Position = ProjectionMatrix * output.v.position; + gl_Position = ProjectionMatrix * outpt.v.position; EmitVertex(); } @@ -124,11 +124,11 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec4 position, vec3 normal, vec4 patchCoord, vec4 edgeVerts[EDGE_VERTS]) { - output.v.edgeDistance[0] = + outpt.v.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - output.v.edgeDistance[1] = + outpt.v.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); emit(index, position, normal, patchCoord); } @@ -144,29 +144,29 @@ void main() vec3 normal[3]; // patch coords are computed in tessellation shader - patchCoord[0] = input[0].v.patchCoord; - patchCoord[1] = input[1].v.patchCoord; - patchCoord[2] = input[2].v.patchCoord; + patchCoord[0] = inpt[0].v.patchCoord; + patchCoord[1] = inpt[1].v.patchCoord; + patchCoord[2] = inpt[2].v.patchCoord; #ifdef USE_PTEX_DISPLACEMENT - position[0] = displacement(input[0].v.position, input[0].v.normal, patchCoord[0]); - position[1] = displacement(input[1].v.position, input[1].v.normal, patchCoord[1]); - position[2] = displacement(input[2].v.position, input[2].v.normal, patchCoord[2]); + position[0] = displacement(inpt[0].v.position, inpt[0].v.normal, patchCoord[0]); + position[1] = displacement(inpt[1].v.position, inpt[1].v.normal, patchCoord[1]); + position[2] = displacement(inpt[2].v.position, inpt[2].v.normal, patchCoord[2]); #else - position[0] = input[0].v.position; - position[1] = input[1].v.position; - position[2] = input[2].v.position; + position[0] = inpt[0].v.position; + position[1] = inpt[1].v.position; + position[2] = inpt[2].v.position; #endif - normal[0] = input[0].v.normal; - normal[1] = input[1].v.normal; - normal[2] = input[2].v.normal; + normal[0] = inpt[0].v.normal; + normal[1] = inpt[1].v.normal; + normal[2] = inpt[2].v.normal; #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -193,7 +193,7 @@ void main() in block { OutputVertex v; -} input; +} inpt; out vec4 outColor; @@ -281,7 +281,7 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) { #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) float d = - min(input.v.edgeDistance[0], min(input.v.edgeDistance[1], input.v.edgeDistance[2])); + min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); vec4 Cedge = vec4(0.5, 0.5, 0.5, 1.0); float p = exp2(-2 * d * d); @@ -297,26 +297,26 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) void main() { - vec3 N = (gl_FrontFacing ? input.v.normal : -input.v.normal); + vec3 N = (gl_FrontFacing ? inpt.v.normal : -inpt.v.normal); #ifdef USE_PTEX_DISPLACEMENT - N = perturbNormalFromDisplacement(input.v.position.xyz, + N = perturbNormalFromDisplacement(inpt.v.position.xyz, N, - input.v.patchCoord); + inpt.v.patchCoord); #endif vec4 Cf = vec4(1.0); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) - Cf = edgeColor(Cf, input.v.edgeDistance); + Cf = edgeColor(Cf, inpt.v.edgeDistance); #endif #ifdef USE_PTEX_COLOR - Cf = Cf * (vec4(1) - vec4(PTexLookup(input.v.patchCoord, + Cf = Cf * (vec4(1) - vec4(PTexLookup(inpt.v.patchCoord, textureImage_Data, textureImage_Packing, textureImage_Pages).x)); #endif - Cf = lighting(Cf, input.v.position.xyz, N); + Cf = lighting(Cf, inpt.v.position.xyz, N); outColor = Cf; } diff --git a/examples/ptexViewer/shader.glsl b/examples/ptexViewer/shader.glsl index feca0551..5cf8fc7d 100644 --- a/examples/ptexViewer/shader.glsl +++ b/examples/ptexViewer/shader.glsl @@ -94,11 +94,11 @@ vec4 PTexLookup(vec4 patchCoord, #ifdef USE_PTEX_DISPLACEMENT -#define OSD_DISPLACEMENT_CALLBACK \ - output.v.position = \ - displacement(output.v.position, \ - output.v.normal, \ - output.v.patchCoord); +#define OSD_DISPLACEMENT_CALLBACK \ + outpt.v.position = \ + displacement(outpt.v.position, \ + outpt.v.normal, \ + outpt.v.patchCoord); uniform sampler2DArray textureDisplace_Data; uniform samplerBuffer textureDisplace_Packing; @@ -124,12 +124,12 @@ layout (location=1) in vec3 normal; out block { OutputVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; - output.v.normal = (ModelViewMatrix * vec4(normal, 0)).xyz; + outpt.v.position = ModelViewMatrix * position; + outpt.v.normal = (ModelViewMatrix * vec4(normal, 0)).xyz; } #endif @@ -151,7 +151,7 @@ void main() in block { OutputVertex v; - } input[4]; + } inpt[4]; #endif // PRIM_QUAD @@ -165,23 +165,23 @@ void main() in block { OutputVertex v; - } input[3]; + } inpt[3]; #endif // PRIM_TRI out block { OutputVertex v; -} output; +} outpt; // -------------------------------------- void emit(vec4 position, vec3 normal, vec4 patchCoord) { - output.v.position = position; - output.v.patchCoord = patchCoord; - output.v.normal = normal; + outpt.v.position = position; + outpt.v.patchCoord = patchCoord; + outpt.v.normal = normal; - gl_Position = ProjectionMatrix * output.v.position; + gl_Position = ProjectionMatrix * outpt.v.position; EmitVertex(); } @@ -196,18 +196,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec4 position, vec3 normal, vec4 patchCoord, vec4 edgeVerts[EDGE_VERTS]) { - output.v.edgeDistance[0] = + outpt.v.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - output.v.edgeDistance[1] = + outpt.v.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); #ifdef PRIM_TRI - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); #endif #ifdef PRIM_QUAD - output.v.edgeDistance[2] = + outpt.v.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]); - output.v.edgeDistance[3] = + outpt.v.edgeDistance[3] = edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]); #endif @@ -232,15 +232,15 @@ void main() patchCoord[3] = GeneratePatchCoord(vec2(0, 1)); #ifdef USE_PTEX_DISPLACEMENT - position[0] = displacement(input[0].v.position, input[0].v.normal, patchCoord[0]); - position[1] = displacement(input[1].v.position, input[1].v.normal, patchCoord[1]); - position[2] = displacement(input[2].v.position, input[2].v.normal, patchCoord[2]); - position[3] = displacement(input[3].v.position, input[3].v.normal, patchCoord[3]); + position[0] = displacement(inpt[0].v.position, inpt[0].v.normal, patchCoord[0]); + position[1] = displacement(inpt[1].v.position, inpt[1].v.normal, patchCoord[1]); + position[2] = displacement(inpt[2].v.position, inpt[2].v.normal, patchCoord[2]); + position[3] = displacement(inpt[3].v.position, inpt[3].v.normal, patchCoord[3]); #else - position[0] = input[0].v.position; - position[1] = input[1].v.position; - position[2] = input[2].v.position; - position[3] = input[3].v.position; + position[0] = inpt[0].v.position; + position[1] = inpt[1].v.position; + position[2] = inpt[2].v.position; + position[3] = inpt[3].v.position; #endif #ifdef FLAT_NORMALS @@ -253,18 +253,18 @@ void main() normal[2] = normal[0]; normal[3] = normal[0]; #else - normal[0] = input[0].v.normal; - normal[1] = input[1].v.normal; - normal[2] = input[2].v.normal; - normal[3] = input[3].v.normal; + normal[0] = inpt[0].v.normal; + normal[1] = inpt[1].v.normal; + normal[2] = inpt[2].v.normal; + normal[3] = inpt[3].v.normal; #endif #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; - edgeVerts[3] = ProjectionMatrix * input[3].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; + edgeVerts[3] = ProjectionMatrix * inpt[3].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -289,18 +289,18 @@ void main() vec3 normal[3]; // patch coords are computed in tessellation shader - patchCoord[0] = input[0].v.patchCoord; - patchCoord[1] = input[1].v.patchCoord; - patchCoord[2] = input[2].v.patchCoord; + patchCoord[0] = inpt[0].v.patchCoord; + patchCoord[1] = inpt[1].v.patchCoord; + patchCoord[2] = inpt[2].v.patchCoord; #ifdef USE_PTEX_DISPLACEMENT - position[0] = displacement(input[0].v.position, input[0].v.normal, patchCoord[0]); - position[1] = displacement(input[1].v.position, input[1].v.normal, patchCoord[1]); - position[2] = displacement(input[2].v.position, input[2].v.normal, patchCoord[2]); + position[0] = displacement(inpt[0].v.position, inpt[0].v.normal, patchCoord[0]); + position[1] = displacement(inpt[1].v.position, inpt[1].v.normal, patchCoord[1]); + position[2] = displacement(inpt[2].v.position, inpt[2].v.normal, patchCoord[2]); #else - position[0] = input[0].v.position; - position[1] = input[1].v.position; - position[2] = input[2].v.position; + position[0] = inpt[0].v.position; + position[1] = inpt[1].v.position; + position[2] = inpt[2].v.position; #endif #ifdef FLAT_NORMALS // emit flat normals for displaced surface @@ -310,16 +310,16 @@ void main() normal[1] = normal[0]; normal[2] = normal[0]; #else - normal[0] = input[0].v.normal; - normal[1] = input[1].v.normal; - normal[2] = input[2].v.normal; + normal[0] = inpt[0].v.normal; + normal[1] = inpt[1].v.normal; + normal[2] = inpt[2].v.normal; #endif #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) vec4 edgeVerts[EDGE_VERTS]; - edgeVerts[0] = ProjectionMatrix * input[0].v.position; - edgeVerts[1] = ProjectionMatrix * input[1].v.position; - edgeVerts[2] = ProjectionMatrix * input[2].v.position; + edgeVerts[0] = ProjectionMatrix * inpt[0].v.position; + edgeVerts[1] = ProjectionMatrix * inpt[1].v.position; + edgeVerts[2] = ProjectionMatrix * inpt[2].v.position; edgeVerts[0].xy /= edgeVerts[0].w; edgeVerts[1].xy /= edgeVerts[1].w; @@ -346,7 +346,7 @@ void main() in block { OutputVertex v; -} input; +} inpt; out vec4 outColor; @@ -449,7 +449,7 @@ lighting(vec4 texColor, vec3 Peye, vec3 Neye) vec4 color = vec4(0); #ifdef USE_PTEX_OCCLUSION - float occ = PTexLookup(input.v.patchCoord, + float occ = PTexLookup(inpt.v.patchCoord, textureOcclusion_Data, textureOcclusion_Packing, textureOcclusion_Pages).x; @@ -487,12 +487,12 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) #ifdef PRIM_TRI float d = - min(input.v.edgeDistance[0], min(input.v.edgeDistance[1], input.v.edgeDistance[2])); + min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); #endif #ifdef PRIM_QUAD float d = - min(min(input.v.edgeDistance[0], input.v.edgeDistance[1]), - min(input.v.edgeDistance[2], input.v.edgeDistance[3])); + min(min(inpt.v.edgeDistance[0], inpt.v.edgeDistance[1]), + min(inpt.v.edgeDistance[2], inpt.v.edgeDistance[3])); #endif vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0); float p = exp2(-2 * d * d); @@ -510,7 +510,7 @@ void main() { #if USE_PTEX_COLOR - vec4 texColor = PTexLookup(input.v.patchCoord, + vec4 texColor = PTexLookup(inpt.v.patchCoord, textureImage_Data, textureImage_Packing, textureImage_Pages); @@ -520,23 +520,23 @@ main() #endif #if USE_PTEX_NORMAL - vec3 normal = perturbNormalFromDisplacement(input.v.position.xyz, - input.v.normal, - input.v.patchCoord); + vec3 normal = perturbNormalFromDisplacement(inpt.v.position.xyz, + inpt.v.normal, + inpt.v.patchCoord); #else - vec3 normal = input.v.normal; + vec3 normal = inpt.v.normal; #endif if (overrideColorEnable) { texColor = overrideColor; - vec4 Cf = lighting(texColor, input.v.position.xyz, normal); - outColor = edgeColor(Cf, input.v.edgeDistance); + vec4 Cf = lighting(texColor, inpt.v.position.xyz, normal); + outColor = edgeColor(Cf, inpt.v.edgeDistance); return; } #if USE_IBL #ifdef USE_PTEX_OCCLUSION - float occ = PTexLookup(input.v.patchCoord, + float occ = PTexLookup(inpt.v.patchCoord, textureOcclusion_Data, textureOcclusion_Packing, textureOcclusion_Pages).x; @@ -545,7 +545,7 @@ main() #endif #ifdef USE_PTEX_SPECULAR - float specular = PTexLookup(input.v.patchCoord, + float specular = PTexLookup(inpt.v.patchCoord, textureSpecular_Data, textureSpecular_Packing, textureSpecular_Pages).x; @@ -555,7 +555,7 @@ main() vec4 a = vec4(0, 0, 0, 1); //ambientColor; vec4 d = getEnvironmentHDR(diffuseEnvironmentMap, normal) * 1.4; - vec3 eye = normalize(input.v.position.xyz - vec3(0,0,0)); + vec3 eye = normalize(inpt.v.position.xyz - vec3(0,0,0)); vec3 reflect = reflect(eye, normal); vec4 s = getEnvironmentHDR(specularEnvironmentMap, reflect); const float fresnelBias = 0; @@ -569,10 +569,10 @@ main() vec4 Cf = (a + d) * texColor + s * 0.5; #else - vec4 Cf = lighting(texColor, input.v.position.xyz, normal); + vec4 Cf = lighting(texColor, inpt.v.position.xyz, normal); #endif - outColor = edgeColor(Cf, input.v.edgeDistance); + outColor = edgeColor(Cf, inpt.v.edgeDistance); } #endif diff --git a/examples/ptexViewer/shader_gl3.glsl b/examples/ptexViewer/shader_gl3.glsl index 248e4f3b..ae3126e1 100644 --- a/examples/ptexViewer/shader_gl3.glsl +++ b/examples/ptexViewer/shader_gl3.glsl @@ -86,11 +86,11 @@ vec4 PTexLookup(vec4 patchCoord, #ifdef USE_PTEX_DISPLACEMENT -#define OSD_DISPLACEMENT_CALLBACK \ - output.v.position = \ - displacement(output.v.position, \ - output.v.normal, \ - output.v.patchCoord); +#define OSD_DISPLACEMENT_CALLBACK \ + outpt.v.position = \ + displacement(outpt.v.position, \ + outpt.v.normal, \ + outpt.v.patchCoord); uniform sampler2DArray textureDisplace_Data; uniform samplerBuffer textureDisplace_Packing; diff --git a/opensubdiv/osd/glslPatchBoundary.glsl b/opensubdiv/osd/glslPatchBoundary.glsl index 3d280c07..0e28227a 100644 --- a/opensubdiv/osd/glslPatchBoundary.glsl +++ b/opensubdiv/osd/glslPatchBoundary.glsl @@ -64,15 +64,15 @@ layout (location=0) in vec4 position; out block { ControlVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; + outpt.v.position = ModelViewMatrix * position; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); #if OSD_NUM_VARYINGS > 0 for (int i = 0; i < OSD_NUM_VARYINGS; ++i) - output.v.varyings[i] = varyings[i]; + outpt.v.varyings[i] = varyings[i]; #endif } @@ -87,11 +87,11 @@ layout(vertices = 16) out; in block { ControlVertex v; -} input[]; +} inpt[]; out block { ControlVertex v; -} output[]; +} outpt[]; #define ID gl_InvocationID @@ -107,7 +107,7 @@ void main() H[l] = vec3(0,0,0); for (int k=0; k<4; k++) { float c = Q[i][k]; - H[l] += c*input[l*4 + k].v.position.xyz; + H[l] += c*inpt[l*4 + k].v.position.xyz; } } @@ -116,13 +116,13 @@ void main() pos += B[j][k]*H[k]; } - output[ID].v.position = vec4(pos, 1.0); + outpt[ID].v.position = vec4(pos, 1.0); int patchLevel = GetPatchLevel(); // +0.5 to avoid interpolation error of integer value - output[ID].v.patchCoord = vec4(0, 0, - patchLevel+0.5, - gl_PrimitiveID+LevelBase+0.5); + outpt[ID].v.patchCoord = vec4(0, 0, + patchLevel+0.5, + gl_PrimitiveID+LevelBase+0.5); OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER; @@ -131,13 +131,13 @@ void main() #ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = - TessAdaptive(input[1].v.position.xyz, input[2].v.position.xyz, patchLevel); + TessAdaptive(inpt[1].v.position.xyz, inpt[2].v.position.xyz, patchLevel); gl_TessLevelOuter[1] = - TessAdaptive(input[2].v.position.xyz, input[6].v.position.xyz, patchLevel); + TessAdaptive(inpt[2].v.position.xyz, inpt[6].v.position.xyz, patchLevel); gl_TessLevelOuter[2] = - TessAdaptive(input[5].v.position.xyz, input[6].v.position.xyz, patchLevel); + TessAdaptive(inpt[5].v.position.xyz, inpt[6].v.position.xyz, patchLevel); gl_TessLevelOuter[3] = - TessAdaptive(input[1].v.position.xyz, input[5].v.position.xyz, patchLevel); + TessAdaptive(inpt[1].v.position.xyz, inpt[5].v.position.xyz, patchLevel); gl_TessLevelInner[0] = max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]); gl_TessLevelInner[1] = @@ -166,11 +166,11 @@ layout(equal_spacing) in; in block { ControlVertex v; int clipFlag; -} input[]; +} inpt[]; out block { OutputVertex v; -} output; +} outpt; void main() { @@ -189,7 +189,7 @@ void main() DUCP[i] = vec3(0.0f, 0.0f, 0.0f); for (int j=0; j<4; ++j) { - vec3 A = input[4*i + j].v.position.xyz; + vec3 A = inpt[4*i + j].v.position.xyz; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; @@ -210,19 +210,19 @@ void main() */ vec3 WorldPos, Tangent, BiTangent; vec3 cp[16]; - for(int i = 0; i < 16; ++i) cp[i] = input[i].v.position.xyz; + for(int i = 0; i < 16; ++i) cp[i] = inpt[i].v.position.xyz; EvalBSpline(gl_TessCoord.xy, cp, WorldPos, Tangent, BiTangent); vec3 normal = normalize(cross(Tangent, BiTangent)); - output.v.position = vec4(WorldPos, 1.0f); - output.v.normal = normal; + outpt.v.position = vec4(WorldPos, 1.0f); + outpt.v.normal = normal; BiTangent = -BiTangent; // BiTangent will be used in following macro - output.v.tangent = BiTangent; + outpt.v.tangent = BiTangent; - output.v.patchCoord = input[0].v.patchCoord; - output.v.patchCoord.xy = vec2(1.0-v, u); + outpt.v.patchCoord = inpt[0].v.patchCoord; + outpt.v.patchCoord.xy = vec2(1.0-v, u); OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER; @@ -246,11 +246,11 @@ layout (location=2) in vec4 color; out block { OutputVertex v; -} output; +} outpt; void main() { gl_Position = ModelViewProjectionMatrix * position; - output.v.color = color; + outpt.v.color = color; } #endif @@ -262,9 +262,9 @@ void main() { in block { OutputVertex v; -} input; +} inpt; void main() { - gl_FragColor = input.v.color; + gl_FragColor = inpt.v.color; } #endif diff --git a/opensubdiv/osd/glslPatchBoundaryGregory.glsl b/opensubdiv/osd/glslPatchBoundaryGregory.glsl index 9272501a..e7e29176 100644 --- a/opensubdiv/osd/glslPatchBoundaryGregory.glsl +++ b/opensubdiv/osd/glslPatchBoundaryGregory.glsl @@ -67,22 +67,22 @@ layout (location=0) in vec4 position; out block { GregControlVertex v; -} output; +} outpt; void main() { int vID = gl_VertexID; - output.v.hullPosition = (ModelViewMatrix * position).xyz; + outpt.v.hullPosition = (ModelViewMatrix * position).xyz; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); int valence = texelFetch(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x; - output.v.valence = int(valence); + outpt.v.valence = int(valence); uint ivalence = uint(abs(valence)); vec3 f[OSD_MAX_VALENCE]; vec3 pos = position.xyz; - output.v.org = position.xyz; + outpt.v.org = position.xyz; vec3 opos = vec3(0,0,0); int boundaryEdgeNeighbors[2]; @@ -150,16 +150,16 @@ void main() f[i] = (pos * float(ivalence) + (neighbor_p + neighbor)*2.0f + diagonal) / (float(ivalence)+5.0f); opos += f[i]; - output.v.r[i] = (neighbor_p-neighbor_m)/3.0f + (diagonal - diagonal_m)/6.0f; + outpt.v.r[i] = (neighbor_p-neighbor_m)/3.0f + (diagonal - diagonal_m)/6.0f; } opos /= ivalence; - output.v.position = vec4(opos, 1.0f).xyz; - output.v.zerothNeighbor = zerothNeighbor; + outpt.v.position = vec4(opos, 1.0f).xyz; + outpt.v.zerothNeighbor = zerothNeighbor; #if OSD_NUM_VARYINGS > 0 for (int i = 0; i < OSD_NUM_VARYINGS; ++i) - output.v.varyings[i] = varyings[i]; + outpt.v.varyings[i] = varyings[i]; #endif @@ -168,21 +168,21 @@ void main() } vec3 e; - output.v.e0 = vec3(0,0,0); - output.v.e1 = vec3(0,0,0); + outpt.v.e0 = vec3(0,0,0); + outpt.v.e1 = vec3(0,0,0); for(uint i=0; i 2) { - output.v.position = ( + outpt.v.position = ( vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) + @@ -191,10 +191,10 @@ void main() texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) + 4.0f * pos)/6.0f; } else { - output.v.position = pos; + outpt.v.position = pos; } - output.v.e0 = ( + outpt.v.e0 = ( vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) - @@ -218,7 +218,7 @@ void main() texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); - output.v.e1 = gamma * pos + + outpt.v.e1 = gamma * pos + alpha_0k * vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) + @@ -247,10 +247,10 @@ void main() texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x, texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x); - output.v.e1 += alpha * neighbor + beta * diagonal; + outpt.v.e1 += alpha * neighbor + beta * diagonal; } - output.v.e1 /= 3.0f; + outpt.v.e1 /= 3.0f; } } #endif @@ -266,11 +266,11 @@ uniform isamplerBuffer g_QuadOffsetBuffer; in block { GregControlVertex v; -} input[]; +} inpt[]; out block { GregEvalVertex v; -} output[]; +} outpt[]; #define ID gl_InvocationID @@ -279,17 +279,17 @@ void main() uint i = gl_InvocationID; uint ip = (i+1)%4; uint im = (i+3)%4; - uint n = uint(abs(input[i].v.valence)); - uint ivalence = abs(input[i].v.valence); + uint n = uint(abs(inpt[i].v.valence)); + uint ivalence = abs(inpt[i].v.valence); int base = GregoryQuadOffsetBase; - output[ID].v.position = input[ID].v.position; + outpt[ID].v.position = inpt[ID].v.position; uint start = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0x00ffu; uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00u; prev=uint(prev/256); - uint np = abs(input[ip].v.valence); - uint nm = abs(input[im].v.valence); + uint np = abs(inpt[ip].v.valence); + uint nm = abs(inpt[im].v.valence); // Control Vertices based on : // "Approximating Subdivision Surfaces with Gregory Patches for Hardware Tessellation" @@ -324,84 +324,84 @@ void main() prev_p=uint(prev_p/256); vec3 Em_ip; - if (input[ip].v.valence < -2) { - uint j = (np + prev_p - input[ip].v.zerothNeighbor) % np; - Em_ip = input[ip].v.position + cos((M_PI*j)/float(np-1))*input[ip].v.e0 + sin((M_PI*j)/float(np-1))*input[ip].v.e1; + if (inpt[ip].v.valence < -2) { + uint j = (np + prev_p - inpt[ip].v.zerothNeighbor) % np; + Em_ip = inpt[ip].v.position + cos((M_PI*j)/float(np-1))*inpt[ip].v.e0 + sin((M_PI*j)/float(np-1))*inpt[ip].v.e1; } else { - Em_ip = input[ip].v.position + input[ip].v.e0*csf(np-3,2*prev_p) + input[ip].v.e1*csf(np-3,2*prev_p+1); + Em_ip = inpt[ip].v.position + inpt[ip].v.e0*csf(np-3,2*prev_p) + inpt[ip].v.e1*csf(np-3,2*prev_p+1); } uint start_m = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x) & 0x00ffu; vec3 Ep_im; - if (input[im].v.valence < -2) { - uint j = (nm + start_m - input[im].v.zerothNeighbor) % nm; - Ep_im = input[im].v.position + cos((M_PI*j)/float(nm-1))*input[im].v.e0 + sin((M_PI*j)/float(nm-1))*input[im].v.e1; + if (inpt[im].v.valence < -2) { + uint j = (nm + start_m - inpt[im].v.zerothNeighbor) % nm; + Ep_im = inpt[im].v.position + cos((M_PI*j)/float(nm-1))*inpt[im].v.e0 + sin((M_PI*j)/float(nm-1))*inpt[im].v.e1; } else { - Ep_im = input[im].v.position + input[im].v.e0*csf(nm-3,2*start_m) + input[im].v.e1*csf(nm-3,2*start_m+1); + Ep_im = inpt[im].v.position + inpt[im].v.e0*csf(nm-3,2*start_m) + inpt[im].v.e1*csf(nm-3,2*start_m+1); } - if (input[i].v.valence < 0) { + if (inpt[i].v.valence < 0) { n = (n-1)*2; } - if (input[im].v.valence < 0) { + if (inpt[im].v.valence < 0) { nm = (nm-1)*2; } - if (input[ip].v.valence < 0) { + if (inpt[ip].v.valence < 0) { np = (np-1)*2; } - if (input[i].v.valence > 2) { - Ep = input[i].v.position + (input[i].v.e0*csf(n-3,2*start) + input[i].v.e1*csf(n-3,2*start+1)); - Em = input[i].v.position + (input[i].v.e0*csf(n-3,2*prev) + input[i].v.e1*csf(n-3,2*prev+1)); + if (inpt[i].v.valence > 2) { + Ep = inpt[i].v.position + (inpt[i].v.e0*csf(n-3,2*start) + inpt[i].v.e1*csf(n-3,2*start+1)); + Em = inpt[i].v.position + (inpt[i].v.e0*csf(n-3,2*prev) + inpt[i].v.e1*csf(n-3,2*prev+1)); float s1=3-2*csf(n-3,2)-csf(np-3,2); float s2=2*csf(n-3,2); - Fp = (csf(np-3,2)*input[i].v.position + s1*Ep + s2*Em_ip + input[i].v.r[start])/3.0f; + Fp = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f; s1 = 3.0f-2.0f*cos(2.0f*M_PI/n)-cos(2*M_PI/nm); - Fm = (csf(nm-3,2)*input[i].v.position + s1*Em + s2*Ep_im - input[i].v.r[prev])/3.0f; + Fm = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f; - } else if (input[i].v.valence < -2) { - uint j = (ivalence + start - input[i].v.zerothNeighbor) % ivalence; + } else if (inpt[i].v.valence < -2) { + uint j = (ivalence + start - inpt[i].v.zerothNeighbor) % ivalence; - Ep = input[i].v.position + cos((M_PI*j)/float(ivalence-1))*input[i].v.e0 + sin((M_PI*j)/float(ivalence-1))*input[i].v.e1; - j = (ivalence + prev - input[i].v.zerothNeighbor) % ivalence; - Em = input[i].v.position + cos((M_PI*j)/float(ivalence-1))*input[i].v.e0 + sin((M_PI*j)/float(ivalence-1))*input[i].v.e1; + Ep = inpt[i].v.position + cos((M_PI*j)/float(ivalence-1))*inpt[i].v.e0 + sin((M_PI*j)/float(ivalence-1))*inpt[i].v.e1; + j = (ivalence + prev - inpt[i].v.zerothNeighbor) % ivalence; + Em = inpt[i].v.position + cos((M_PI*j)/float(ivalence-1))*inpt[i].v.e0 + sin((M_PI*j)/float(ivalence-1))*inpt[i].v.e1; - vec3 Rp = ((-2.0f * input[i].v.org - 1.0f * input[im].v.org) + (2.0f * input[ip].v.org + 1.0f * input[(i+2)%4].v.org))/3.0f; - vec3 Rm = ((-2.0f * input[i].v.org - 1.0f * input[ip].v.org) + (2.0f * input[im].v.org + 1.0f * input[(i+2)%4].v.org))/3.0f; + vec3 Rp = ((-2.0f * inpt[i].v.org - 1.0f * inpt[im].v.org) + (2.0f * inpt[ip].v.org + 1.0f * inpt[(i+2)%4].v.org))/3.0f; + vec3 Rm = ((-2.0f * inpt[i].v.org - 1.0f * inpt[ip].v.org) + (2.0f * inpt[im].v.org + 1.0f * inpt[(i+2)%4].v.org))/3.0f; float s1=3-2*csf(n-3,2)-csf(np-3,2); float s2=2*csf(n-3,2); - Fp = (csf(np-3,2)*input[i].v.position + s1*Ep + s2*Em_ip + input[i].v.r[start])/3.0f; + Fp = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f; s1 = 3.0f-2.0f*cos(2.0f*M_PI/n)-cos(2.0f*M_PI/nm); - Fm = (csf(nm-3,2)*input[i].v.position + s1*Em + s2*Ep_im - input[i].v.r[prev])/3.0f; + Fm = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f; - if (input[im].v.valence < 0) { + if (inpt[im].v.valence < 0) { s1=3-2*csf(n-3,2)-csf(np-3,2); - Fp = Fm = (csf(np-3,2)*input[i].v.position + s1*Ep + s2*Em_ip + input[i].v.r[start])/3.0f; - } else if (input[ip].v.valence < 0) { + Fp = Fm = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f; + } else if (inpt[ip].v.valence < 0) { s1 = 3.0f-2.0f*cos(2.0f*M_PI/n)-cos(2.0f*M_PI/nm); - Fm = Fp = (csf(nm-3,2)*input[i].v.position + s1*Em + s2*Ep_im - input[i].v.r[prev])/3.0f; + Fm = Fp = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f; } - } else if (input[i].v.valence == -2) { - Ep = (2.0f * input[i].v.org + input[ip].v.org)/3.0f; - Em = (2.0f * input[i].v.org + input[im].v.org)/3.0f; - Fp = Fm = (4.0f * input[i].v.org + input[(i+2)%n].v.org + 2.0f * input[ip].v.org + 2.0f * input[im].v.org)/9.0f; + } else if (inpt[i].v.valence == -2) { + Ep = (2.0f * inpt[i].v.org + inpt[ip].v.org)/3.0f; + Em = (2.0f * inpt[i].v.org + inpt[im].v.org)/3.0f; + Fp = Fm = (4.0f * inpt[i].v.org + inpt[(i+2)%n].v.org + 2.0f * inpt[ip].v.org + 2.0f * inpt[im].v.org)/9.0f; } - output[ID].v.Ep = Ep; - output[ID].v.Em = Em; - output[ID].v.Fp = Fp; - output[ID].v.Fm = Fm; + outpt[ID].v.Ep = Ep; + outpt[ID].v.Em = Em; + outpt[ID].v.Fp = Fp; + outpt[ID].v.Fm = Fm; int patchLevel = GetPatchLevel(); - output[ID].v.patchCoord = vec4(0, 0, - patchLevel+0.5f, - gl_PrimitiveID+LevelBase+0.5f); + outpt[ID].v.patchCoord = vec4(0, 0, + patchLevel+0.5f, + gl_PrimitiveID+LevelBase+0.5f); OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER; @@ -410,13 +410,13 @@ void main() #ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = - TessAdaptive(input[0].v.hullPosition.xyz, input[1].v.hullPosition.xyz, patchLevel); + TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[1].v.hullPosition.xyz, patchLevel); gl_TessLevelOuter[1] = - TessAdaptive(input[0].v.hullPosition.xyz, input[3].v.hullPosition.xyz, patchLevel); + TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz, patchLevel); gl_TessLevelOuter[2] = - TessAdaptive(input[2].v.hullPosition.xyz, input[3].v.hullPosition.xyz, patchLevel); + TessAdaptive(inpt[2].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz, patchLevel); gl_TessLevelOuter[3] = - TessAdaptive(input[1].v.hullPosition.xyz, input[2].v.hullPosition.xyz, patchLevel); + TessAdaptive(inpt[1].v.hullPosition.xyz, inpt[2].v.hullPosition.xyz, patchLevel); gl_TessLevelInner[0] = max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]); gl_TessLevelInner[1] = @@ -443,11 +443,11 @@ layout(cw) in; in block { GregEvalVertex v; -} input[]; +} inpt[]; out block { OutputVertex v; -} output; +} outpt; void main() { @@ -456,29 +456,29 @@ void main() vec3 p[20]; - p[0] = input[0].v.position; - p[1] = input[0].v.Ep; - p[2] = input[0].v.Em; - p[3] = input[0].v.Fp; - p[4] = input[0].v.Fm; + p[0] = inpt[0].v.position; + p[1] = inpt[0].v.Ep; + p[2] = inpt[0].v.Em; + p[3] = inpt[0].v.Fp; + p[4] = inpt[0].v.Fm; - p[5] = input[1].v.position; - p[6] = input[1].v.Ep; - p[7] = input[1].v.Em; - p[8] = input[1].v.Fp; - p[9] = input[1].v.Fm; + p[5] = inpt[1].v.position; + p[6] = inpt[1].v.Ep; + p[7] = inpt[1].v.Em; + p[8] = inpt[1].v.Fp; + p[9] = inpt[1].v.Fm; - p[10] = input[2].v.position; - p[11] = input[2].v.Ep; - p[12] = input[2].v.Em; - p[13] = input[2].v.Fp; - p[14] = input[2].v.Fm; + p[10] = inpt[2].v.position; + p[11] = inpt[2].v.Ep; + p[12] = inpt[2].v.Em; + p[13] = inpt[2].v.Fp; + p[14] = inpt[2].v.Fm; - p[15] = input[3].v.position; - p[16] = input[3].v.Ep; - p[17] = input[3].v.Em; - p[18] = input[3].v.Fp; - p[19] = input[3].v.Fm; + p[15] = inpt[3].v.position; + p[16] = inpt[3].v.Ep; + p[17] = inpt[3].v.Em; + p[18] = inpt[3].v.Fp; + p[19] = inpt[3].v.Fm; vec3 q[16]; @@ -542,11 +542,11 @@ void main() vec3 normal = normalize(cross(BiTangent, Tangent)); - output.v.position = ModelViewMatrix * vec4(WorldPos, 1.0f); - output.v.normal = normal; - output.v.patchCoord = input[0].v.patchCoord; - output.v.patchCoord.xy = vec2(v, u); - output.v.tangent = normalize(BiTangent); + outpt.v.position = ModelViewMatrix * vec4(WorldPos, 1.0f); + outpt.v.normal = normal; + outpt.v.patchCoord = inpt[0].v.patchCoord; + outpt.v.patchCoord.xy = vec2(v, u); + outpt.v.tangent = normalize(BiTangent); OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER; @@ -568,11 +568,11 @@ layout (location=2) in vec4 color; out block { OutputVertex v; -} output; +} outpt; void main() { gl_Position = ModelViewProjectionMatrix * position; - output.v.color = color; + outpt.v.color = color; } #endif @@ -584,9 +584,9 @@ void main() { in block { OutputVertex v; -} input; +} inpt; void main() { - gl_FragColor = input.v.color; + gl_FragColor = inpt.v.color; } #endif diff --git a/opensubdiv/osd/glslPatchCommon.glsl b/opensubdiv/osd/glslPatchCommon.glsl index 37cceb1c..fb201c3f 100644 --- a/opensubdiv/osd/glslPatchCommon.glsl +++ b/opensubdiv/osd/glslPatchCommon.glsl @@ -180,35 +180,35 @@ uniform isamplerBuffer g_ptexIndicesBuffer; int u = (ptexIndex.y >> 17) & 0x3ff; \ int v = (ptexIndex.y >> 7) & 0x3ff; \ int rotation = (ptexIndex.y >> 5) & 0x3; \ - output[ID].v.patchCoord.w = faceID+0.5; \ - output[ID].v.ptexInfo = ivec4(u, v, lv, rotation); \ + outpt[ID].v.patchCoord.w = faceID+0.5; \ + outpt[ID].v.ptexInfo = ivec4(u, v, lv, rotation); \ } #define OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER \ { \ - vec2 uv = output.v.patchCoord.xy; \ - ivec2 p = input[0].v.ptexInfo.xy; \ - int lv = input[0].v.ptexInfo.z; \ - int rot = input[0].v.ptexInfo.w; \ - output.v.tessCoord.xy = uv; \ + vec2 uv = outpt.v.patchCoord.xy; \ + ivec2 p = inpt[0].v.ptexInfo.xy; \ + int lv = inpt[0].v.ptexInfo.z; \ + int rot = inpt[0].v.ptexInfo.w; \ + outpt.v.tessCoord.xy = uv; \ uv.xy = float(rot==0)*uv.xy \ + float(rot==1)*vec2(1.0-uv.y, uv.x) \ + float(rot==2)*vec2(1.0-uv.x, 1.0-uv.y) \ + float(rot==3)*vec2(uv.y, 1.0-uv.x); \ - output.v.patchCoord.xy = (uv * vec2(1.0)/lv) + vec2(p.x, p.y)/lv; \ + outpt.v.patchCoord.xy = (uv * vec2(1.0)/lv) + vec2(p.x, p.y)/lv; \ } #define OSD_COMPUTE_PTEX_COMPATIBLE_TANGENT(ROTATE) \ { \ - int rot = (input[0].v.ptexInfo.w + 4 - ROTATE)%4; \ + int rot = (inpt[0].v.ptexInfo.w + 4 - ROTATE)%4; \ if (rot == 1) { \ - output.v.tangent = -normalize(Tangent); \ + outpt.v.tangent = -normalize(Tangent); \ } else if (rot == 2) { \ - output.v.tangent = -normalize(BiTangent); \ + outpt.v.tangent = -normalize(BiTangent); \ } else if (rot == 3) { \ - output.v.tangent = normalize(Tangent); \ + outpt.v.tangent = normalize(Tangent); \ } else { \ - output.v.tangent = normalize(BiTangent); \ + outpt.v.tangent = normalize(BiTangent); \ } \ } @@ -218,12 +218,12 @@ uniform isamplerBuffer g_ptexIndicesBuffer; vec4 clipPos = ModelViewProjectionMatrix * P; \ bvec3 clip0 = lessThan(clipPos.xyz, vec3(clipPos.w)); \ bvec3 clip1 = greaterThan(clipPos.xyz, -vec3(clipPos.w)); \ - output.v.clipFlag = ivec3(clip0) + 2*ivec3(clip1); \ + outpt.v.clipFlag = ivec3(clip0) + 2*ivec3(clip1); \ #define OSD_PATCH_CULL(N) \ ivec3 clipFlag = ivec3(0); \ for(int i = 0; i < N; ++i) { \ - clipFlag |= input[i].v.clipFlag; \ + clipFlag |= inpt[i].v.clipFlag; \ } \ if (clipFlag != ivec3(3) ) { \ gl_TessLevelInner[0] = 0; \ diff --git a/opensubdiv/osd/glslPatchCorner.glsl b/opensubdiv/osd/glslPatchCorner.glsl index 13b9d490..185ffe02 100644 --- a/opensubdiv/osd/glslPatchCorner.glsl +++ b/opensubdiv/osd/glslPatchCorner.glsl @@ -64,15 +64,15 @@ layout (location=0) in vec4 position; out block { ControlVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; + outpt.v.position = ModelViewMatrix * position; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); #if OSD_NUM_VARYINGS > 0 for (int i = 0; i < OSD_NUM_VARYINGS; ++i) - output.v.varyings[i] = varyings[i]; + outpt.v.varyings[i] = varyings[i]; #endif } @@ -87,11 +87,11 @@ layout(vertices = 16) out; in block { ControlVertex v; -} input[]; +} inpt[]; out block { ControlVertex v; -} output[]; +} outpt[]; #define ID gl_InvocationID @@ -105,7 +105,7 @@ void main() H[l] = vec3(0,0,0); for (int k=0; k<3; k++) { float c = B[i][2-k]; - H[l] += c*input[l*3 + k].v.position.xyz; + H[l] += c*inpt[l*3 + k].v.position.xyz; } } @@ -114,13 +114,13 @@ void main() pos += B[j][k]*H[k]; } - output[ID].v.position = vec4(pos, 1.0); + outpt[ID].v.position = vec4(pos, 1.0); int patchLevel = GetPatchLevel(); // +0.5 to avoid interpolation error of integer value - output[ID].v.patchCoord = vec4(0, 0, - patchLevel+0.5, - gl_PrimitiveID+LevelBase+0.5); + outpt[ID].v.patchCoord = vec4(0, 0, + patchLevel+0.5, + gl_PrimitiveID+LevelBase+0.5); OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER; @@ -129,16 +129,16 @@ void main() #ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = - TessAdaptive(input[2].v.position.xyz, input[5].v.position.xyz, patchLevel); + TessAdaptive(inpt[2].v.position.xyz, inpt[5].v.position.xyz, patchLevel); gl_TessLevelOuter[1] = - TessAdaptive(input[1].v.position.xyz, input[2].v.position.xyz, patchLevel); + TessAdaptive(inpt[1].v.position.xyz, inpt[2].v.position.xyz, patchLevel); gl_TessLevelOuter[2] = - TessAdaptive(input[4].v.position.xyz, input[5].v.position.xyz, patchLevel); + TessAdaptive(inpt[4].v.position.xyz, inpt[5].v.position.xyz, patchLevel); gl_TessLevelOuter[3] = - TessAdaptive(input[1].v.position.xyz, input[4].v.position.xyz, patchLevel); + TessAdaptive(inpt[1].v.position.xyz, inpt[4].v.position.xyz, patchLevel); gl_TessLevelInner[0] = max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]); @@ -167,11 +167,11 @@ layout(equal_spacing) in; in block { ControlVertex v; -} input[]; +} inpt[]; out block { OutputVertex v; -} output; +} outpt; void main() { @@ -189,7 +189,7 @@ void main() DUCP[i] = vec3(0.0f, 0.0f, 0.0f); for (int j=0; j<4; ++j) { - vec3 A = input[4*i + j].v.position.xyz; + vec3 A = inpt[4*i + j].v.position.xyz; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; @@ -210,14 +210,14 @@ void main() vec3 normal = normalize(cross(Tangent, BiTangent)); - output.v.position = vec4(WorldPos, 1.0f); - output.v.normal = normal; + outpt.v.position = vec4(WorldPos, 1.0f); + outpt.v.normal = normal; BiTangent = -BiTangent; // BiTangent will be used in following macro - output.v.tangent = BiTangent; + outpt.v.tangent = BiTangent; - output.v.patchCoord = input[0].v.patchCoord; - output.v.patchCoord.xy = vec2(1.0-v, u); + outpt.v.patchCoord = inpt[0].v.patchCoord; + outpt.v.patchCoord.xy = vec2(1.0-v, u); OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER; @@ -241,11 +241,11 @@ layout (location=2) in vec4 color; out block { OutputVertex v; -} output; +} outpt; void main() { gl_Position = ModelViewProjectionMatrix * position; - output.v.color = color; + outpt.v.color = color; } #endif @@ -257,9 +257,9 @@ void main() { in block { OutputVertex v; -} input; +} inpt; void main() { - gl_FragColor = input.v.color; + gl_FragColor = inpt.v.color; } #endif diff --git a/opensubdiv/osd/glslPatchGregory.glsl b/opensubdiv/osd/glslPatchGregory.glsl index 4cd68ad2..f5f7cdd7 100644 --- a/opensubdiv/osd/glslPatchGregory.glsl +++ b/opensubdiv/osd/glslPatchGregory.glsl @@ -67,17 +67,17 @@ layout (location=0) in vec4 position; out block { GregControlVertex v; -} output; +} outpt; void main() { int vID = gl_VertexID; - output.v.hullPosition = (ModelViewMatrix * position).xyz; + outpt.v.hullPosition = (ModelViewMatrix * position).xyz; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); uint valence = uint(texelFetch(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x); - output.v.valence = int(valence); + outpt.v.valence = int(valence); vec3 f[OSD_MAX_VALENCE]; vec3 pos = position.xyz; @@ -125,28 +125,28 @@ void main() f[i] = (pos * float(valence) + (neighbor_p + neighbor)*2.0 + diagonal) / (float(valence)+5.0); opos += f[i]; - output.v.r[i] = (neighbor_p-neighbor_m)/3.0 + (diagonal - diagonal_m)/6.0; + outpt.v.r[i] = (neighbor_p-neighbor_m)/3.0 + (diagonal - diagonal_m)/6.0; } opos /= valence; - output.v.position = vec4(opos, 1.0f).xyz; + outpt.v.position = vec4(opos, 1.0f).xyz; #if OSD_NUM_VARYINGS > 0 for (int i = 0; i < OSD_NUM_VARYINGS; ++i) - output.v.varyings[i] = varyings[i]; + outpt.v.varyings[i] = varyings[i]; #endif vec3 e; - output.v.e0 = vec3(0,0,0); - output.v.e1 = vec3(0,0,0); + outpt.v.e0 = vec3(0,0,0); + outpt.v.e1 = vec3(0,0,0); for(uint i=0; i 0 for (int i = 0; i < OSD_NUM_VARYINGS; ++i) - output.v.varyings[i] = varyings[i]; + outpt.v.varyings[i] = varyings[i]; #endif } @@ -87,11 +87,11 @@ layout(vertices = 16) out; in block { ControlVertex v; -} input[]; +} inpt[]; out block { ControlVertex v; -} output[]; +} outpt[]; #define ID gl_InvocationID @@ -106,8 +106,8 @@ void main() for (int k=0; k<4; k++) { float c = Q[i][k]; // XXX: fix this in patchMeshFactory. -// H[l] += c*input[l*4 + k].v.position.xyz; - H[l] += c*input[l + k*4].v.position.xyz; +// H[l] += c*inpt[l*4 + k].v.position.xyz; + H[l] += c*inpt[l + k*4].v.position.xyz; } } @@ -116,14 +116,14 @@ void main() pos += Q[j][k]*H[k]; } - output[ID].v.position = vec4(pos, 1.0); + outpt[ID].v.position = vec4(pos, 1.0); int patchLevel = GetPatchLevel(); // +0.5 to avoid interpolation error of integer value - output[ID].v.patchCoord = vec4(0, 0, - patchLevel+0.5, - gl_PrimitiveID+LevelBase+0.5); + outpt[ID].v.patchCoord = vec4(0, 0, + patchLevel+0.5, + gl_PrimitiveID+LevelBase+0.5); OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER; @@ -132,13 +132,13 @@ void main() #ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION gl_TessLevelOuter[0] = - TessAdaptive(input[5].v.position.xyz, input[9].v.position.xyz, patchLevel); + TessAdaptive(inpt[5].v.position.xyz, inpt[9].v.position.xyz, patchLevel); gl_TessLevelOuter[1] = - TessAdaptive(input[5].v.position.xyz, input[6].v.position.xyz, patchLevel); + TessAdaptive(inpt[5].v.position.xyz, inpt[6].v.position.xyz, patchLevel); gl_TessLevelOuter[2] = - TessAdaptive(input[6].v.position.xyz, input[10].v.position.xyz, patchLevel); + TessAdaptive(inpt[6].v.position.xyz, inpt[10].v.position.xyz, patchLevel); gl_TessLevelOuter[3] = - TessAdaptive(input[9].v.position.xyz, input[10].v.position.xyz, patchLevel); + TessAdaptive(inpt[9].v.position.xyz, inpt[10].v.position.xyz, patchLevel); gl_TessLevelInner[0] = max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]); gl_TessLevelInner[1] = @@ -166,11 +166,11 @@ layout(equal_spacing) in; in block { ControlVertex v; -} input[]; +} inpt[]; out block { OutputVertex v; -} output; +} outpt; void main() { @@ -179,17 +179,17 @@ void main() vec3 WorldPos, Tangent, BiTangent; vec3 cp[16]; - for(int i = 0; i < 16; ++i) cp[i] = input[i].v.position.xyz; + for(int i = 0; i < 16; ++i) cp[i] = inpt[i].v.position.xyz; EvalBSpline(gl_TessCoord.xy, cp, WorldPos, Tangent, BiTangent); vec3 normal = normalize(cross(Tangent, BiTangent)); - output.v.position = vec4(WorldPos, 1.0f); - output.v.normal = normal; - output.v.tangent = Tangent; + outpt.v.position = vec4(WorldPos, 1.0f); + outpt.v.normal = normal; + outpt.v.tangent = Tangent; - output.v.patchCoord = input[0].v.patchCoord; - output.v.patchCoord.xy = vec2(u, v); + outpt.v.patchCoord = inpt[0].v.patchCoord; + outpt.v.patchCoord.xy = vec2(u, v); OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER; @@ -211,11 +211,11 @@ layout (location=2) in vec4 color; out block { OutputVertex v; -} output; +} outpt; void main() { gl_Position = ModelViewProjectionMatrix * position; - output.v.color = color; + outpt.v.color = color; } #endif @@ -227,9 +227,9 @@ void main() { in block { OutputVertex v; -} input; +} inpt; void main() { - gl_FragColor = input.v.color; + gl_FragColor = inpt.v.color; } #endif diff --git a/opensubdiv/osd/glslPatchTransition.glsl b/opensubdiv/osd/glslPatchTransition.glsl index a51d3233..55af546d 100644 --- a/opensubdiv/osd/glslPatchTransition.glsl +++ b/opensubdiv/osd/glslPatchTransition.glsl @@ -78,15 +78,15 @@ layout (location=0) in vec4 position; out block { ControlVertex v; -} output; +} outpt; void main() { - output.v.position = ModelViewMatrix * position; + outpt.v.position = ModelViewMatrix * position; OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position); #if OSD_NUM_VARYINGS > 0 for (int i = 0; i < OSD_NUM_VARYINGS; ++i) - output.v.varyings[i] = varyings[i]; + outpt.v.varyings[i] = varyings[i]; #endif } @@ -101,11 +101,11 @@ layout(vertices = 16) out; in block { ControlVertex v; -} input[]; +} inpt[]; out block { ControlVertex v; -} output[]; +} outpt[]; #define ID gl_InvocationID @@ -125,7 +125,7 @@ void main() H[l] = vec3(0,0,0); for (int k=0; k<4; k++) { float c = Q[i][k]; - H[l] += c*input[l*4 + k].v.position.xyz; + H[l] += c*inpt[l*4 + k].v.position.xyz; } } @@ -143,7 +143,7 @@ void main() H[l] = vec3(0,0,0); for (int k=0; k<3; k++) { float c = B[i][2-k]; - H[l] += c*input[l*3 + k].v.position.xyz; + H[l] += c*inpt[l*3 + k].v.position.xyz; } } @@ -161,7 +161,7 @@ void main() H[l] = vec3(0,0,0); for (int k=0; k<4; k++) { float c = Q[i][k]; - H[l] += c*input[l*4 + k].v.position.xyz; + H[l] += c*inpt[l*4 + k].v.position.xyz; } } @@ -172,12 +172,12 @@ void main() #endif - output[ID].v.position = vec4(pos, 1.0); + outpt[ID].v.position = vec4(pos, 1.0); int patchLevel = GetPatchLevel(); - output[ID].v.patchCoord = vec4(0, 0, - patchLevel+0.5, - gl_PrimitiveID+LevelBase+0.5); + outpt[ID].v.patchCoord = vec4(0, 0, + patchLevel+0.5, + gl_PrimitiveID+LevelBase+0.5); OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER; @@ -185,7 +185,7 @@ void main() OSD_PATCH_CULL(16); #ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION - // These tables map the 9, 12, or 16 input control points onto the + // These tables map the 9, 12, or 16 inpt control points onto the // canonical 16 control points for a regular patch. #if defined BOUNDARY const int p[16] = int[]( 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ); @@ -206,25 +206,25 @@ void main() #endif // Expand and rotate control points using remapping tables above - vec3 pv0 = input[p[r[0]]].v.position.xyz; - vec3 pv1 = input[p[r[1]]].v.position.xyz; - vec3 pv2 = input[p[r[2]]].v.position.xyz; - vec3 pv3 = input[p[r[3]]].v.position.xyz; + vec3 pv0 = inpt[p[r[0]]].v.position.xyz; + vec3 pv1 = inpt[p[r[1]]].v.position.xyz; + vec3 pv2 = inpt[p[r[2]]].v.position.xyz; + vec3 pv3 = inpt[p[r[3]]].v.position.xyz; - vec3 pv4 = input[p[r[4]]].v.position.xyz; - vec3 pv5 = input[p[r[5]]].v.position.xyz; - vec3 pv6 = input[p[r[6]]].v.position.xyz; - vec3 pv7 = input[p[r[7]]].v.position.xyz; + vec3 pv4 = inpt[p[r[4]]].v.position.xyz; + vec3 pv5 = inpt[p[r[5]]].v.position.xyz; + vec3 pv6 = inpt[p[r[6]]].v.position.xyz; + vec3 pv7 = inpt[p[r[7]]].v.position.xyz; - vec3 pv8 = input[p[r[8]]].v.position.xyz; - vec3 pv9 = input[p[r[9]]].v.position.xyz; - vec3 pv10 = input[p[r[10]]].v.position.xyz; - vec3 pv11 = input[p[r[11]]].v.position.xyz; + vec3 pv8 = inpt[p[r[8]]].v.position.xyz; + vec3 pv9 = inpt[p[r[9]]].v.position.xyz; + vec3 pv10 = inpt[p[r[10]]].v.position.xyz; + vec3 pv11 = inpt[p[r[11]]].v.position.xyz; - vec3 pv12 = input[p[r[12]]].v.position.xyz; - vec3 pv13 = input[p[r[13]]].v.position.xyz; - vec3 pv14 = input[p[r[14]]].v.position.xyz; - vec3 pv15 = input[p[r[15]]].v.position.xyz; + vec3 pv12 = inpt[p[r[12]]].v.position.xyz; + vec3 pv13 = inpt[p[r[13]]].v.position.xyz; + vec3 pv14 = inpt[p[r[14]]].v.position.xyz; + vec3 pv15 = inpt[p[r[15]]].v.position.xyz; // Each edge of a transition patch is adjacent to one or two // patches at the next refined level of subdivision. @@ -600,11 +600,11 @@ void main() in block { ControlVertex v; -} input[]; +} inpt[]; out block { OutputVertex v; -} output; +} outpt; void main() { @@ -734,25 +734,25 @@ void main() vec3 WorldPos, Tangent, BiTangent; vec3 cp[16]; - for(int i = 0; i < 16; ++i) cp[i] = input[i].v.position.xyz; + for(int i = 0; i < 16; ++i) cp[i] = inpt[i].v.position.xyz; EvalBSpline(UV, cp, WorldPos, Tangent, BiTangent); vec3 normal = normalize(cross(BiTangent, Tangent)); - output.v.position = vec4(WorldPos, 1.0f); - output.v.normal = normal; - output.v.tangent = BiTangent; + outpt.v.position = vec4(WorldPos, 1.0f); + outpt.v.normal = normal; + outpt.v.tangent = BiTangent; - output.v.patchCoord = input[0].v.patchCoord; + outpt.v.patchCoord = inpt[0].v.patchCoord; #if ROTATE == 1 - output.v.patchCoord.xy = vec2(UV.x, 1.0-UV.y); + outpt.v.patchCoord.xy = vec2(UV.x, 1.0-UV.y); #elif ROTATE == 2 - output.v.patchCoord.xy = vec2(1.0-UV.y, 1.0-UV.x); + outpt.v.patchCoord.xy = vec2(1.0-UV.y, 1.0-UV.x); #elif ROTATE == 3 - output.v.patchCoord.xy = vec2(1.0-UV.x, UV.y); + outpt.v.patchCoord.xy = vec2(1.0-UV.x, UV.y); #else - output.v.patchCoord.xy = vec2(UV.y, UV.x); + outpt.v.patchCoord.xy = vec2(UV.y, UV.x); #endif OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER; @@ -777,11 +777,11 @@ layout (location=2) in vec4 color; out block { OutputVertex v; -} output; +} outpt; void main() { gl_Position = ModelViewProjectionMatrix * position; - output.v.color = color; + outpt.v.color = color; } #endif @@ -793,9 +793,9 @@ void main() { in block { OutputVertex v; -} input; +} inpt; void main() { - gl_FragColor = input.v.color; + gl_FragColor = inpt.v.color; } #endif From 967fc4db727379a5a0c0b219f5a82bbe82179da1 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 15:51:27 -0700 Subject: [PATCH 17/32] Fixed glsl shader portability edgeDistance Moved all edgeDistance declarations to client shader code. --- examples/glBatchViewer/shader.glsl | 20 +++++++++++--------- examples/glViewer/shader.glsl | 20 +++++++++++--------- examples/paintTest/shader.glsl | 12 +++++++----- examples/ptexViewer/shader.glsl | 22 ++++++++++++---------- opensubdiv/osd/glslPatchCommon.glsl | 1 - 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/examples/glBatchViewer/shader.glsl b/examples/glBatchViewer/shader.glsl index fd419faf..2b317bd9 100644 --- a/examples/glBatchViewer/shader.glsl +++ b/examples/glBatchViewer/shader.glsl @@ -121,6 +121,7 @@ void main() out block { OutputVertex v; + noperspective out vec4 edgeDistance; } outpt; void emit(int index, vec3 normal) @@ -147,18 +148,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS]) { - outpt.v.edgeDistance[0] = + outpt.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - outpt.v.edgeDistance[1] = + outpt.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); #ifdef PRIM_TRI - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); #endif #ifdef PRIM_QUAD - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]); - outpt.v.edgeDistance[3] = + outpt.edgeDistance[3] = edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]); #endif @@ -241,6 +242,7 @@ void main() in block { OutputVertex v; + noperspective in vec4 edgeDistance; } inpt; out vec4 outColor; @@ -303,12 +305,12 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) #ifdef PRIM_TRI float d = - min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); + min(inpt.edgeDistance[0], min(inpt.edgeDistance[1], inpt.edgeDistance[2])); #endif #ifdef PRIM_QUAD float d = - min(min(inpt.v.edgeDistance[0], inpt.v.edgeDistance[1]), - min(inpt.v.edgeDistance[2], inpt.v.edgeDistance[3])); + min(min(inpt.edgeDistance[0], inpt.edgeDistance[1]), + min(inpt.edgeDistance[2], inpt.edgeDistance[3])); #endif vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0); float p = exp2(-2 * d * d); @@ -330,7 +332,7 @@ main() vec4 Cf = lighting(inpt.v.position.xyz, N); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) - Cf = edgeColor(Cf, inpt.v.edgeDistance); + Cf = edgeColor(Cf, inpt.edgeDistance); #endif outColor = Cf; diff --git a/examples/glViewer/shader.glsl b/examples/glViewer/shader.glsl index fd419faf..2b317bd9 100644 --- a/examples/glViewer/shader.glsl +++ b/examples/glViewer/shader.glsl @@ -121,6 +121,7 @@ void main() out block { OutputVertex v; + noperspective out vec4 edgeDistance; } outpt; void emit(int index, vec3 normal) @@ -147,18 +148,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS]) { - outpt.v.edgeDistance[0] = + outpt.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - outpt.v.edgeDistance[1] = + outpt.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); #ifdef PRIM_TRI - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); #endif #ifdef PRIM_QUAD - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]); - outpt.v.edgeDistance[3] = + outpt.edgeDistance[3] = edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]); #endif @@ -241,6 +242,7 @@ void main() in block { OutputVertex v; + noperspective in vec4 edgeDistance; } inpt; out vec4 outColor; @@ -303,12 +305,12 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) #ifdef PRIM_TRI float d = - min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); + min(inpt.edgeDistance[0], min(inpt.edgeDistance[1], inpt.edgeDistance[2])); #endif #ifdef PRIM_QUAD float d = - min(min(inpt.v.edgeDistance[0], inpt.v.edgeDistance[1]), - min(inpt.v.edgeDistance[2], inpt.v.edgeDistance[3])); + min(min(inpt.edgeDistance[0], inpt.edgeDistance[1]), + min(inpt.edgeDistance[2], inpt.edgeDistance[3])); #endif vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0); float p = exp2(-2 * d * d); @@ -330,7 +332,7 @@ main() vec4 Cf = lighting(inpt.v.position.xyz, N); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) - Cf = edgeColor(Cf, inpt.v.edgeDistance); + Cf = edgeColor(Cf, inpt.edgeDistance); #endif outColor = Cf; diff --git a/examples/paintTest/shader.glsl b/examples/paintTest/shader.glsl index 93ec142e..6856c269 100644 --- a/examples/paintTest/shader.glsl +++ b/examples/paintTest/shader.glsl @@ -101,6 +101,7 @@ vec4 displacement(vec4 position, vec3 normal, vec4 patchCoord) out block { OutputVertex v; + noperspective out vec4 edgeDistance; } outpt; void emit(int index, vec4 position, vec3 normal, vec4 patchCoord) @@ -124,11 +125,11 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec4 position, vec3 normal, vec4 patchCoord, vec4 edgeVerts[EDGE_VERTS]) { - outpt.v.edgeDistance[0] = + outpt.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - outpt.v.edgeDistance[1] = + outpt.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); emit(index, position, normal, patchCoord); } @@ -193,6 +194,7 @@ void main() in block { OutputVertex v; + noperspective in vec4 edgeDistance; } inpt; out vec4 outColor; @@ -281,7 +283,7 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) { #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) float d = - min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); + min(inpt.edgeDistance[0], min(inpt.edgeDistance[1], inpt.edgeDistance[2])); vec4 Cedge = vec4(0.5, 0.5, 0.5, 1.0); float p = exp2(-2 * d * d); @@ -306,7 +308,7 @@ main() vec4 Cf = vec4(1.0); #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) - Cf = edgeColor(Cf, inpt.v.edgeDistance); + Cf = edgeColor(Cf, inpt.edgeDistance); #endif #ifdef USE_PTEX_COLOR diff --git a/examples/ptexViewer/shader.glsl b/examples/ptexViewer/shader.glsl index 5cf8fc7d..090954e4 100644 --- a/examples/ptexViewer/shader.glsl +++ b/examples/ptexViewer/shader.glsl @@ -171,6 +171,7 @@ void main() out block { OutputVertex v; + noperspective out vec4 edgeDistance; } outpt; // -------------------------------------- @@ -196,18 +197,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1) void emit(int index, vec4 position, vec3 normal, vec4 patchCoord, vec4 edgeVerts[EDGE_VERTS]) { - outpt.v.edgeDistance[0] = + outpt.edgeDistance[0] = edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]); - outpt.v.edgeDistance[1] = + outpt.edgeDistance[1] = edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]); #ifdef PRIM_TRI - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]); #endif #ifdef PRIM_QUAD - outpt.v.edgeDistance[2] = + outpt.edgeDistance[2] = edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]); - outpt.v.edgeDistance[3] = + outpt.edgeDistance[3] = edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]); #endif @@ -346,6 +347,7 @@ void main() in block { OutputVertex v; + noperspective in vec4 edgeDistance; } inpt; out vec4 outColor; @@ -487,12 +489,12 @@ edgeColor(vec4 Cfill, vec4 edgeDistance) #if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE) #ifdef PRIM_TRI float d = - min(inpt.v.edgeDistance[0], min(inpt.v.edgeDistance[1], inpt.v.edgeDistance[2])); + min(inpt.edgeDistance[0], min(inpt.edgeDistance[1], inpt.edgeDistance[2])); #endif #ifdef PRIM_QUAD float d = - min(min(inpt.v.edgeDistance[0], inpt.v.edgeDistance[1]), - min(inpt.v.edgeDistance[2], inpt.v.edgeDistance[3])); + min(min(inpt.edgeDistance[0], inpt.edgeDistance[1]), + min(inpt.edgeDistance[2], inpt.edgeDistance[3])); #endif vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0); float p = exp2(-2 * d * d); @@ -530,7 +532,7 @@ main() if (overrideColorEnable) { texColor = overrideColor; vec4 Cf = lighting(texColor, inpt.v.position.xyz, normal); - outColor = edgeColor(Cf, inpt.v.edgeDistance); + outColor = edgeColor(Cf, inpt.edgeDistance); return; } @@ -572,7 +574,7 @@ main() vec4 Cf = lighting(texColor, inpt.v.position.xyz, normal); #endif - outColor = edgeColor(Cf, inpt.v.edgeDistance); + outColor = edgeColor(Cf, inpt.edgeDistance); } #endif diff --git a/opensubdiv/osd/glslPatchCommon.glsl b/opensubdiv/osd/glslPatchCommon.glsl index fb201c3f..08742099 100644 --- a/opensubdiv/osd/glslPatchCommon.glsl +++ b/opensubdiv/osd/glslPatchCommon.glsl @@ -85,7 +85,6 @@ struct OutputVertex { vec3 tangent; centroid vec4 patchCoord; // u, v, level, faceID centroid vec2 tessCoord; // tesscoord.st - noperspective vec4 edgeDistance; #if OSD_NUM_VARYINGS > 0 float varyings[OSD_NUM_VARYINGS]; #endif From 2b972f311794fd100dd6a902d9ed1e12d6886067 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 15:54:40 -0700 Subject: [PATCH 18/32] Consolidated OpenGL includes into osd/opengl.h --- opensubdiv/osd/CMakeLists.txt | 1 + opensubdiv/osd/clGLVertexBuffer.cpp | 8 +- opensubdiv/osd/clGLVertexBuffer.h | 2 + opensubdiv/osd/cpuGLVertexBuffer.cpp | 18 +---- opensubdiv/osd/cpuGLVertexBuffer.h | 16 +--- opensubdiv/osd/cpuKernel.h | 1 + opensubdiv/osd/cudaGLVertexBuffer.cpp | 12 +-- opensubdiv/osd/cudaGLVertexBuffer.h | 5 ++ opensubdiv/osd/drawContext.h | 1 + opensubdiv/osd/gcdKernel.h | 3 +- opensubdiv/osd/glDrawContext.cpp | 18 +---- opensubdiv/osd/glDrawContext.h | 18 +---- opensubdiv/osd/glDrawRegistry.cpp | 18 +---- opensubdiv/osd/glDrawRegistry.h | 18 +---- opensubdiv/osd/glPtexTexture.cpp | 9 +-- opensubdiv/osd/glPtexTexture.h | 18 +---- opensubdiv/osd/glVertexBuffer.cpp | 18 +---- opensubdiv/osd/glVertexBuffer.h | 18 +---- opensubdiv/osd/glslComputeContext.cpp | 18 +---- opensubdiv/osd/glslComputeContext.h | 18 +---- opensubdiv/osd/glslComputeController.cpp | 18 +---- opensubdiv/osd/glslKernelBundle.cpp | 8 +- opensubdiv/osd/glslKernelBundle.h | 18 +---- .../glslTransformFeedbackComputeContext.cpp | 18 +---- .../osd/glslTransformFeedbackComputeContext.h | 18 +---- ...glslTransformFeedbackComputeController.cpp | 8 +- .../osd/glslTransformFeedbackKernelBundle.cpp | 8 +- .../osd/glslTransformFeedbackKernelBundle.h | 19 +---- opensubdiv/osd/opengl.h | 77 +++++++++++++++++++ 29 files changed, 138 insertions(+), 292 deletions(-) create mode 100644 opensubdiv/osd/opengl.h diff --git a/opensubdiv/osd/CMakeLists.txt b/opensubdiv/osd/CMakeLists.txt index 0a37ef81..3ea8feee 100644 --- a/opensubdiv/osd/CMakeLists.txt +++ b/opensubdiv/osd/CMakeLists.txt @@ -115,6 +115,7 @@ set(PUBLIC_HEADER_FILES evalLimitContext.h mesh.h nonCopyable.h + opengl.h drawContext.h drawRegistry.h vertex.h diff --git a/opensubdiv/osd/clGLVertexBuffer.cpp b/opensubdiv/osd/clGLVertexBuffer.cpp index 491c7eb5..365ac3b1 100644 --- a/opensubdiv/osd/clGLVertexBuffer.cpp +++ b/opensubdiv/osd/clGLVertexBuffer.cpp @@ -57,14 +57,10 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include -#else - #include -#endif - #include "../osd/clGLVertexBuffer.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/clGLVertexBuffer.h b/opensubdiv/osd/clGLVertexBuffer.h index 7ae4aea6..d8de2d28 100644 --- a/opensubdiv/osd/clGLVertexBuffer.h +++ b/opensubdiv/osd/clGLVertexBuffer.h @@ -59,6 +59,8 @@ #include "../version.h" +#include "../osd/opengl.h" + #if defined(__APPLE__) #include #else diff --git a/opensubdiv/osd/cpuGLVertexBuffer.cpp b/opensubdiv/osd/cpuGLVertexBuffer.cpp index 1d0c834a..f78d7522 100644 --- a/opensubdiv/osd/cpuGLVertexBuffer.cpp +++ b/opensubdiv/osd/cpuGLVertexBuffer.cpp @@ -55,24 +55,10 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../osd/cpuGLVertexBuffer.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/cpuGLVertexBuffer.h b/opensubdiv/osd/cpuGLVertexBuffer.h index 78d76c8b..5751b6e2 100644 --- a/opensubdiv/osd/cpuGLVertexBuffer.h +++ b/opensubdiv/osd/cpuGLVertexBuffer.h @@ -59,21 +59,7 @@ #include "../version.h" -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif +#include "../osd/opengl.h" namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/cpuKernel.h b/opensubdiv/osd/cpuKernel.h index 5e73c5d4..ffd69680 100644 --- a/opensubdiv/osd/cpuKernel.h +++ b/opensubdiv/osd/cpuKernel.h @@ -58,6 +58,7 @@ #define OSD_CPU_KERNEL_H #include "../version.h" + #include "../osd/vertexDescriptor.h" namespace OpenSubdiv { diff --git a/opensubdiv/osd/cudaGLVertexBuffer.cpp b/opensubdiv/osd/cudaGLVertexBuffer.cpp index 5d4ad02c..4b16c016 100644 --- a/opensubdiv/osd/cudaGLVertexBuffer.cpp +++ b/opensubdiv/osd/cudaGLVertexBuffer.cpp @@ -55,18 +55,14 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include -#else - #include -#endif +#include "../osd/cudaGLVertexBuffer.h" +#include "../osd/error.h" + +#include "../osd/opengl.h" #include #include -#include "../osd/cudaGLVertexBuffer.h" -#include "../osd/error.h" - #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/cudaGLVertexBuffer.h b/opensubdiv/osd/cudaGLVertexBuffer.h index 5399126c..c5fc05aa 100644 --- a/opensubdiv/osd/cudaGLVertexBuffer.h +++ b/opensubdiv/osd/cudaGLVertexBuffer.h @@ -59,6 +59,11 @@ #include "../version.h" +#include "../osd/opengl.h" + +#include +#include + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/drawContext.h b/opensubdiv/osd/drawContext.h index 72a72dd3..a50a4372 100644 --- a/opensubdiv/osd/drawContext.h +++ b/opensubdiv/osd/drawContext.h @@ -58,6 +58,7 @@ #define OSD_DRAW_CONTEXT_H #include "../version.h" + #include "../far/patchTables.h" #include diff --git a/opensubdiv/osd/gcdKernel.h b/opensubdiv/osd/gcdKernel.h index 6f686cfc..895d9700 100644 --- a/opensubdiv/osd/gcdKernel.h +++ b/opensubdiv/osd/gcdKernel.h @@ -57,9 +57,10 @@ #ifndef OSD_GCD_KERNEL_H #define OSD_GCD_KERNEL_H -#include #include "../version.h" +#include + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glDrawContext.cpp b/opensubdiv/osd/glDrawContext.cpp index 358c8f43..ef5e2668 100644 --- a/opensubdiv/osd/glDrawContext.cpp +++ b/opensubdiv/osd/glDrawContext.cpp @@ -49,27 +49,13 @@ // (E) The software is licensed "as-is." You bear the risk of // using it. The contributors give no express warranties, -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../far/dispatcher.h" #include "../far/loopSubdivisionTables.h" #include "../osd/glDrawRegistry.h" #include "../osd/glDrawContext.h" +#include "../osd/opengl.h" + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glDrawContext.h b/opensubdiv/osd/glDrawContext.h index 30139952..a64397ff 100644 --- a/opensubdiv/osd/glDrawContext.h +++ b/opensubdiv/osd/glDrawContext.h @@ -57,22 +57,6 @@ #ifndef OSD_GL_DRAW_CONTEXT_H #define OSD_GL_DRAW_CONTEXT_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" #include "../far/mesh.h" @@ -80,6 +64,8 @@ #include "../osd/drawRegistry.h" #include "../osd/vertex.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glDrawRegistry.cpp b/opensubdiv/osd/glDrawRegistry.cpp index 48f5cc53..1440244b 100644 --- a/opensubdiv/osd/glDrawRegistry.cpp +++ b/opensubdiv/osd/glDrawRegistry.cpp @@ -49,25 +49,11 @@ // (E) The software is licensed "as-is." You bear the risk of // using it. The contributors give no express warranties, -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../osd/glDrawRegistry.h" #include "../osd/error.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glDrawRegistry.h b/opensubdiv/osd/glDrawRegistry.h index 134d70ea..882ea66c 100644 --- a/opensubdiv/osd/glDrawRegistry.h +++ b/opensubdiv/osd/glDrawRegistry.h @@ -57,28 +57,14 @@ #ifndef OSD_GL_DRAW_REGISTRY_H #define OSD_GL_DRAW_REGISTRY_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" #include "../far/mesh.h" #include "../osd/drawRegistry.h" #include "../osd/vertex.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glPtexTexture.cpp b/opensubdiv/osd/glPtexTexture.cpp index 09dddd4f..2c8ca163 100644 --- a/opensubdiv/osd/glPtexTexture.cpp +++ b/opensubdiv/osd/glPtexTexture.cpp @@ -55,14 +55,11 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include -#else - #include -#endif - #include "../osd/glPtexTexture.h" #include "../osd/ptexTextureLoader.h" + +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glPtexTexture.h b/opensubdiv/osd/glPtexTexture.h index 3afcad19..1244c216 100644 --- a/opensubdiv/osd/glPtexTexture.h +++ b/opensubdiv/osd/glPtexTexture.h @@ -57,26 +57,12 @@ #ifndef OSD_GL_PTEX_TEXTURE_H #define OSD_GL_PTEX_TEXTURE_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" #include "../osd/nonCopyable.h" +#include "../osd/opengl.h" + class PtexTexture; namespace OpenSubdiv { diff --git a/opensubdiv/osd/glVertexBuffer.cpp b/opensubdiv/osd/glVertexBuffer.cpp index 61bcc029..b836bc05 100644 --- a/opensubdiv/osd/glVertexBuffer.cpp +++ b/opensubdiv/osd/glVertexBuffer.cpp @@ -55,24 +55,10 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../osd/glVertexBuffer.h" +#include "../osd/opengl.h" + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glVertexBuffer.h b/opensubdiv/osd/glVertexBuffer.h index d844aa86..88e25593 100644 --- a/opensubdiv/osd/glVertexBuffer.h +++ b/opensubdiv/osd/glVertexBuffer.h @@ -57,24 +57,10 @@ #ifndef OSD_GL_VERTEX_BUFFER_H #define OSD_GL_VERTEX_BUFFER_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" +#include "../osd/opengl.h" + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glslComputeContext.cpp b/opensubdiv/osd/glslComputeContext.cpp index 80f01326..da286999 100644 --- a/opensubdiv/osd/glslComputeContext.cpp +++ b/opensubdiv/osd/glslComputeContext.cpp @@ -55,28 +55,14 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../far/mesh.h" #include "../osd/debug.h" #include "../osd/error.h" #include "../osd/glslComputeContext.h" #include "../osd/glslKernelBundle.h" +#include "../osd/opengl.h" + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glslComputeContext.h b/opensubdiv/osd/glslComputeContext.h index eaf3286b..d252a9cb 100644 --- a/opensubdiv/osd/glslComputeContext.h +++ b/opensubdiv/osd/glslComputeContext.h @@ -57,22 +57,6 @@ #ifndef OSD_GLSL_COMPUTE_CONTEXT_H #define OSD_GLSL_COMPUTE_CONTEXT_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" #include "../far/vertexEditTables.h" @@ -80,6 +64,8 @@ #include "../osd/vertexDescriptor.h" #include "../osd/nonCopyable.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glslComputeController.cpp b/opensubdiv/osd/glslComputeController.cpp index 9985ed16..49fc3f0d 100644 --- a/opensubdiv/osd/glslComputeController.cpp +++ b/opensubdiv/osd/glslComputeController.cpp @@ -55,26 +55,12 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../osd/glslComputeController.h" #include "../osd/glslComputeContext.h" #include "../osd/glslKernelBundle.h" +#include "../osd/opengl.h" + #include #include diff --git a/opensubdiv/osd/glslKernelBundle.cpp b/opensubdiv/osd/glslKernelBundle.cpp index c2876df3..ce007a78 100644 --- a/opensubdiv/osd/glslKernelBundle.cpp +++ b/opensubdiv/osd/glslKernelBundle.cpp @@ -55,12 +55,6 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include -#else - #include -#endif - #include #ifdef _MSC_VER #define snprintf _snprintf @@ -73,6 +67,8 @@ #include "../far/subdivisionTables.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glslKernelBundle.h b/opensubdiv/osd/glslKernelBundle.h index 389536c7..efa420e5 100644 --- a/opensubdiv/osd/glslKernelBundle.h +++ b/opensubdiv/osd/glslKernelBundle.h @@ -57,28 +57,14 @@ #ifndef OSD_GLSL_COMPUTE_KERNEL_BUNDLE_H #define OSD_GLSL_COMPUTE_KERNEL_BUNDLE_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" + #include "../far/subdivisionTables.h" #include "../osd/nonCopyable.h" #include "../osd/vertex.h" #include "../osd/vertexDescriptor.h" +#include "../osd/opengl.h" namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp b/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp index d21b049d..7066c698 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp +++ b/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp @@ -55,27 +55,15 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif +#include "../version.h" #include "../far/mesh.h" #include "../far/subdivisionTables.h" #include "../osd/glslTransformFeedbackComputeContext.h" #include "../osd/glslTransformFeedbackKernelBundle.h" +#include "../osd/opengl.h" + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/glslTransformFeedbackComputeContext.h b/opensubdiv/osd/glslTransformFeedbackComputeContext.h index 36af7788..20273f82 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeContext.h +++ b/opensubdiv/osd/glslTransformFeedbackComputeContext.h @@ -57,22 +57,6 @@ #ifndef OSD_GLSL_TRANSFORM_FEEDBACK_COMPUTE_CONTEXT_H #define OSD_GLSL_TRANSFORM_FEEDBACK_COMPUTE_CONTEXT_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" #include "../far/vertexEditTables.h" @@ -80,6 +64,8 @@ #include "../osd/vertexDescriptor.h" #include "../osd/nonCopyable.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glslTransformFeedbackComputeController.cpp b/opensubdiv/osd/glslTransformFeedbackComputeController.cpp index 982c5a4f..3fcbcab3 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeController.cpp +++ b/opensubdiv/osd/glslTransformFeedbackComputeController.cpp @@ -55,16 +55,12 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include -#else - #include -#endif - #include "../osd/glslTransformFeedbackComputeController.h" #include "../osd/glslTransformFeedbackComputeContext.h" #include "../osd/glslTransformFeedbackKernelBundle.h" +#include "../osd/opengl.h" + #include #include diff --git a/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp b/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp index dcd662f8..d524a69c 100644 --- a/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp +++ b/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp @@ -55,11 +55,7 @@ // a particular purpose and non-infringement. // -#if defined(__APPLE__) - #include -#else - #include -#endif +#include "../version.h" #include #ifdef _MSC_VER @@ -73,6 +69,8 @@ #include "../far/subdivisionTables.h" +#include "../osd/opengl.h" + #include namespace OpenSubdiv { diff --git a/opensubdiv/osd/glslTransformFeedbackKernelBundle.h b/opensubdiv/osd/glslTransformFeedbackKernelBundle.h index dafa989f..eb57a239 100644 --- a/opensubdiv/osd/glslTransformFeedbackKernelBundle.h +++ b/opensubdiv/osd/glslTransformFeedbackKernelBundle.h @@ -57,28 +57,15 @@ #ifndef OSD_GLSL_TRANSFORM_FEEDBACK_KERNEL_BUNDLE_H #define OSD_GLSL_TRANSFORM_FEEDBACK_KERNEL_BUNDLE_H -#if defined(__APPLE__) - #include "TargetConditionals.h" - #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR - #include - #else - #include - #endif -#elif defined(ANDROID) - #include -#else - #if defined(_WIN32) - #include - #endif - #include -#endif - #include "../version.h" + #include "../osd/nonCopyable.h" #include "../osd/vertex.h" #include "../osd/vertexDescriptor.h" #include "../far/subdivisionTables.h" +#include "../osd/opengl.h" + namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { diff --git a/opensubdiv/osd/opengl.h b/opensubdiv/osd/opengl.h new file mode 100644 index 00000000..a4f371d8 --- /dev/null +++ b/opensubdiv/osd/opengl.h @@ -0,0 +1,77 @@ +// +// Copyright (C) Pixar. All rights reserved. +// +// This license governs use of the accompanying software. If you +// use the software, you accept this license. If you do not accept +// the license, do not use the software. +// +// 1. Definitions +// The terms "reproduce," "reproduction," "derivative works," and +// "distribution" have the same meaning here as under U.S. +// copyright law. A "contribution" is the original software, or +// any additions or changes to the software. +// A "contributor" is any person or entity that distributes its +// contribution under this license. +// "Licensed patents" are a contributor's patent claims that read +// directly on its contribution. +// +// 2. Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, +// including the license conditions and limitations in section 3, +// each contributor grants you a non-exclusive, worldwide, +// royalty-free copyright license to reproduce its contribution, +// prepare derivative works of its contribution, and distribute +// its contribution or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, +// including the license conditions and limitations in section 3, +// each contributor grants you a non-exclusive, worldwide, +// royalty-free license under its licensed patents to make, have +// made, use, sell, offer for sale, import, and/or otherwise +// dispose of its contribution in the software or derivative works +// of the contribution in the software. +// +// 3. Conditions and Limitations +// (A) No Trademark License- This license does not grant you +// rights to use any contributor's name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over +// patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends +// automatically. +// (C) If you distribute any portion of the software, you must +// retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source +// code form, you may do so only under this license by including a +// complete copy of this license with your distribution. If you +// distribute any portion of the software in compiled or object +// code form, you may only do so under a license that complies +// with this license. +// (E) The software is licensed "as-is." You bear the risk of +// using it. The contributors give no express warranties, +// guarantees or conditions. You may have additional consumer +// rights under your local laws which this license cannot change. +// To the extent permitted under your local laws, the contributors +// exclude the implied warranties of merchantability, fitness for +// a particular purpose and non-infringement. +// +#ifndef OSD_OPENGL_H +#define OSD_OPENGL_H + +#if defined(__APPLE__) + #include "TargetConditionals.h" + #if TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR + #include + #else + #include + #endif +#elif defined(ANDROID) + #include +#else + #if defined(_WIN32) + #define W32_LEAN_AND_MEAN + #include + #endif + #include +#endif + +#endif // OSD_OPENGL_H From f5f524322a6e7e7608250c3d343844cb48859131 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 16:30:25 -0700 Subject: [PATCH 19/32] Fixed VS2010 build warning/error --- opensubdiv/far/multiMeshFactory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensubdiv/far/multiMeshFactory.h b/opensubdiv/far/multiMeshFactory.h index 03981d7a..e0077b3f 100644 --- a/opensubdiv/far/multiMeshFactory.h +++ b/opensubdiv/far/multiMeshFactory.h @@ -375,7 +375,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV // merge batch, model by model FarKernelBatchVector &batches = farMesh->_batches; int editTableIndexOffset = 0; - for (size_t i = 0; i < meshes.size(); ++i) { + for (int i = 0; i < (int)meshes.size(); ++i) { for (int j = 0; j < (int)meshes[i]->_batches.size(); ++j) { FarKernelBatch batch = meshes[i]->_batches[j]; batch._meshIndex = i; From 29afdfc8b375d7d1722249e9d89a30443c9e4da4 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 16:56:32 -0700 Subject: [PATCH 20/32] Fixed GLSL transform feedback initialization. --- examples/glViewer/viewer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/glViewer/viewer.cpp b/examples/glViewer/viewer.cpp index 508e21f7..9d276bce 100644 --- a/examples/glViewer/viewer.cpp +++ b/examples/glViewer/viewer.cpp @@ -693,7 +693,7 @@ createOsdMesh( const std::string &shape, int level, int kernel, Scheme scheme=kC #endif #ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK } else if(kernel == kGLSL) { - if (not g_glslComputeController) { + if (not g_glslTransformFeedbackComputeController) { g_glslTransformFeedbackComputeController = new OpenSubdiv::OsdGLSLTransformFeedbackComputeController(); } g_mesh = new OpenSubdiv::OsdMesh Date: Mon, 10 Jun 2013 17:24:34 -0700 Subject: [PATCH 21/32] Deleted examples/evalTest --- examples/evalTest/CMakeLists.txt | 119 ---- examples/evalTest/algebra.h | 210 ------ examples/evalTest/evalTest.cpp | 1142 ------------------------------ examples/evalTest/glhelpers.h | 242 ------- examples/evalTest/mainApple.mm | 176 ----- examples/evalTest/mainGlut.cpp | 74 -- examples/evalTest/notes.md | 38 - examples/evalTest/shader.glsl | 142 ---- 8 files changed, 2143 deletions(-) delete mode 100644 examples/evalTest/CMakeLists.txt delete mode 100644 examples/evalTest/algebra.h delete mode 100644 examples/evalTest/evalTest.cpp delete mode 100644 examples/evalTest/glhelpers.h delete mode 100644 examples/evalTest/mainApple.mm delete mode 100644 examples/evalTest/mainGlut.cpp delete mode 100644 examples/evalTest/notes.md delete mode 100644 examples/evalTest/shader.glsl diff --git a/examples/evalTest/CMakeLists.txt b/examples/evalTest/CMakeLists.txt deleted file mode 100644 index f10380e7..00000000 --- a/examples/evalTest/CMakeLists.txt +++ /dev/null @@ -1,119 +0,0 @@ -# -# Copyright (C) Pixar. All rights reserved. -# -# This license governs use of the accompanying software. If you -# use the software, you accept this license. If you do not accept -# the license, do not use the software. -# -# 1. Definitions -# The terms "reproduce," "reproduction," "derivative works," and -# "distribution" have the same meaning here as under U.S. -# copyright law. A "contribution" is the original software, or -# any additions or changes to the software. -# A "contributor" is any person or entity that distributes its -# contribution under this license. -# "Licensed patents" are a contributor's patent claims that read -# directly on its contribution. -# -# 2. Grant of Rights -# (A) Copyright Grant- Subject to the terms of this license, -# including the license conditions and limitations in section 3, -# each contributor grants you a non-exclusive, worldwide, -# royalty-free copyright license to reproduce its contribution, -# prepare derivative works of its contribution, and distribute -# its contribution or any derivative works that you create. -# (B) Patent Grant- Subject to the terms of this license, -# including the license conditions and limitations in section 3, -# each contributor grants you a non-exclusive, worldwide, -# royalty-free license under its licensed patents to make, have -# made, use, sell, offer for sale, import, and/or otherwise -# dispose of its contribution in the software or derivative works -# of the contribution in the software. -# -# 3. Conditions and Limitations -# (A) No Trademark License- This license does not grant you -# rights to use any contributor's name, logo, or trademarks. -# (B) If you bring a patent claim against any contributor over -# patents that you claim are infringed by the software, your -# patent license from such contributor to the software ends -# automatically. -# (C) If you distribute any portion of the software, you must -# retain all copyright, patent, trademark, and attribution -# notices that are present in the software. -# (D) If you distribute any portion of the software in source -# code form, you may do so only under this license by including a -# complete copy of this license with your distribution. If you -# distribute any portion of the software in compiled or object -# code form, you may only do so under a license that complies -# with this license. -# (E) The software is licensed "as-is." You bear the risk of -# using it. The contributors give no express warranties, -# guarantees or conditions. You may have additional consumer -# rights under your local laws which this license cannot change. -# To the extent permitted under your local laws, the contributors -# exclude the implied warranties of merchantability, fitness for -# a particular purpose and non-infringement. -# - -# *** evalTest *** - -set(SHADER_FILES - shader.glsl -) - -set(PLATFORM_LIBRARIES - ${OSD_LINK_TARGET} - ${OPENGL_LIBRARY} - ${GLEW_LIBRARY} - ${GLFW_LIBRARIES} -) - -include_directories( - ${PROJECT_SOURCE_DIR}/opensubdiv - ${PROJECT_SOURCE_DIR}/regression - ${GLEW_INCLUDE_DIR} - ${GLFW_INCLUDE_DIR} -) - -#------------------------------------------------------------------------------- -# Shader Stringification -# We want to use preprocessor include directives to include GLSL and OpenCL -# shader source files in cpp files, but since the sources contain newline -# characters we would need raw string literals from C++11 to do this directly. -# To avoid depending on C++11 we instead use a small tool called "line_quote" -# to generate source files that are suitable for direct inclusion. -foreach(shader_file ${SHADER_FILES}) - - string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file}) - - string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file}) - list(APPEND INC_FILES ${inc_file}) - - add_custom_command( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file} - COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file} - ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file} - DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file} - ) -endforeach() - -if(APPLE) - _add_glfw_executable(evalTest - mainApple.mm - evalTest.cpp - ${SHADER_FILES} - ${INC_FILES} - ) -else() - _add_glfw_executable(evalTest - evalTest.cpp - mainGlut.cpp - ${SHADER_FILES} - ${INC_FILES} - ) -endif() - -target_link_libraries(evalTest - ${PLATFORM_LIBRARIES} -) - diff --git a/examples/evalTest/algebra.h b/examples/evalTest/algebra.h deleted file mode 100644 index 5cb86e74..00000000 --- a/examples/evalTest/algebra.h +++ /dev/null @@ -1,210 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include -#include - -// -// A few basic linear algebra operations -// - -// -// Make the given matrix an identity matrix -// -inline void setIdentity(float* m) -{ - m[0] = m[5] = m[10] = m[15] = 1.0f; - m[1] = m[2] = m[3] = m[4] = m[6] = m[7] = m[8] = m[9] = m[11] = m[12] = m[13] = m[14] = 0.0f; -} - -// -// Multiply A * B and store the result in D -// -inline void -multMatrix(float *d, const float *a, const float *b) -{ - for (int i=0; i<4; ++i) - { - for (int j=0; j<4; ++j) - { - d[i*4 + j] = - a[i*4 + 0] * b[0*4 + j] + - a[i*4 + 1] * b[1*4 + j] + - a[i*4 + 2] * b[2*4 + j] + - a[i*4 + 3] * b[3*4 + j]; - } - } -} - -// -// Create a perspective projection matrix -// -void setPersp( float fov, float aspect, float znear, float zfar, float* m ) -{ - float xymax = znear * tanf(fov * 3.141592653589793238462f / 360.f); - float ymin = -xymax; - float xmin = -xymax; - - float width = xymax - xmin; - float height = xymax - ymin; - - float depth = zfar - znear; - float q = -(zfar + znear) / depth; - float qn = -2 * (zfar * znear) / depth; - - float w = 2 * znear / width; - w = w / aspect; - float h = 2 * znear / height; - - m[0] = w; - m[1] = 0.f; - m[2] = 0.f; - m[3] = 0.f; - - m[4] = 0.f; - m[5] = h; - m[6] = 0.f; - m[7] = 0.f; - - m[8] = 0.f; - m[9] = 0.f; - m[10] = q; - m[11] = -1; - - m[12] = 0.f; - m[13] = 0.f; - m[14] = qn; - m[15] = 0.f; -} - -// -// Apply a translation to the given matrix m -// -void -translateMatrix(float x, float y, float z, float* m) -{ - m[0] += m[3]*x; m[4] += m[7]*x; m[8] += m[11]*x; m[12] += m[15]*x; - m[1] += m[3]*y; m[5] += m[7]*y; m[9] += m[11]*y; m[13] += m[15]*y; - m[2] += m[3]*z; m[6] += m[7]*z; m[10]+= m[11]*z; m[14] += m[15]*z; -} - -// -// Apply a rotation to the given matrix m -// -void -rotateMatrix(float angle, float x, float y, float z, float* m) -{ - float rads = float((2*3.14159 / 360.) * angle); - float c = cosf(rads); - float s = sinf(rads); - float xx = x * x; - float xy = x * y; - float xz = x * z; - float yy = y * y; - float yz = y * z; - float zz = z * z; - - float m2[16]; - m2[0] = xx * (1 - c) + c; - m2[4] = xy * (1 - c) - z * s; - m2[8] = xz * (1 - c) + y * s; - m2[12] = 0; - - m2[1] = xy * (1 - c) + z * s; - m2[5] = yy * (1 - c) + c; - m2[9] = yz * (1 - c) - x * s; - m2[13] = 0; - - m2[2] = xz * (1 - c) - y * s; - m2[6] = yz * (1 - c) + x * s; - m2[10]= zz * (1 - c) + c; - m2[14]= 0; - - m2[3]= 0; - m2[7]= 0; - m2[11]= 0; - m2[15]= 1; - - float mOrig[16]; - for (int i = 0; i < 16; i++) - mOrig[i] = m[i]; - - multMatrix(m, mOrig, m2); -} - -// -// Print out the matrix (as usual, column-major order is assumed) -// -inline void printMatrix(float* m) -{ - for (int r = 0; r < 4; r++) { - std::cout << " "; - for (int c = 0; c < 4; c++) { - std::cout << std::setprecision(3) << m[c*4 + r]; - if (c != 3) - std::cout << ","; - else - std::cout << std::endl; - } - } -} - -// -// Perform a cross-product of three points to calculate a face normal -// -inline void -cross(float *n, const float *p0, const float *p1, const float *p2) -{ - float a[3] = { p1[0]-p0[0], p1[1]-p0[1], p1[2]-p0[2] }; - float b[3] = { p2[0]-p0[0], p2[1]-p0[1], p2[2]-p0[2] }; - n[0] = a[1]*b[2]-a[2]*b[1]; - n[1] = a[2]*b[0]-a[0]*b[2]; - n[2] = a[0]*b[1]-a[1]*b[0]; - - float rn = 1.0f/sqrtf(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]); - n[0] *= rn; - n[1] *= rn; - n[2] *= rn; -} - -// -// Normalize the given vector -// -inline void -normalize(float * p) -{ - float dist = sqrtf( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] ); - p[0]/=dist; - p[1]/=dist; - p[2]/=dist; -} - -// -// Compute the center of the list of points and the size of the bound -// -inline void -computeCenterAndSize(const std::vector& positions, float* center, float* size) -{ - float fmax = std::numeric_limits().max(), - fmin = std::numeric_limits().min(); - float min[3] = { fmax, fmax, fmax}; - float max[3] = { fmin, fmin, fmin}; - for (size_t i=0; i < positions.size()/3; ++i) { - for(int j=0; j<3; ++j) { - float v = positions[i*3+j]; - min[j] = std::min(min[j], v); - max[j] = std::max(max[j], v); - } - } - for (int j=0; j<3; ++j) { - center[j] = (min[j] + max[j]) * 0.5f; - *size += (max[j]-min[j])*(max[j]-min[j]); - } - *size = sqrtf(*size); -} - diff --git a/examples/evalTest/evalTest.cpp b/examples/evalTest/evalTest.cpp deleted file mode 100644 index 0324bdfb..00000000 --- a/examples/evalTest/evalTest.cpp +++ /dev/null @@ -1,1142 +0,0 @@ -// CPU Subdivision with OpenSubdiv -// ------------------------------- -// In this example program, we will setup an OpenGL application that uses OSD to -// subdivide an animated mesh. It is intended to be as simple as possible and -// not necessarily efficient. It is also intended as a learning tool for -// understanding the OSD internals. Unlike the other OSD examples, the common -// code infrastructure has been removed for clarity. -// -// ### Program Structure -// -// This example program is structured as follows: -// -// 1. Setup static mesh topology (OsdHbrMesh) -// 2. Convert the topology into a subdividable mesh (OsdMesh) -// 3. On each frame: -// * Animate the coarse mesh points and update the OsdMesh -// * Subdivide the updated mesh -// * Draw the subdivided mesh and wire frame -// -// If you are completely new to OSD, you should read the following sections to -// get a basic understanding of how it works. -// -// ### OSD Architecture Basics -// As a client, you will primarily be interacting with the Osd and Hbr classes, -// however it's good to be aware of all three layers. The following describes -// these layers from lowest level (Hbr) to highest (Osd): -// -// **Hbr: Halfedge Boundary Representation.** -// This layer represents the mesh topology as meshes, vertices and edges. It is -// the core that provides the structure for subdivision and provides an -// abstraction for dealing with topology in a type-agnostic way (i.e. everything -// is templated). -// -// **Far: Feature Adaptive Representation.** -// Far uses hbr to create and cache fast run time data structures for table -// driven subdivision. Feature-adaptive refinement logic is used to adaptively -// refine coarse topology only as much as needed. The FarMesh does hold vertex -// objects but the topology has been baked into FarSubdivisionTables. It also -// provides the underpinnings for generic dispatch of subdivision evaluation, so -// subdivision can be preformed with different mechanisms (GLSL, Cuda, etc.), -// the concrete implementations are specified at the next layer up. -// -// **Osd: Open Subdiv.** -// Osd contains client level code that uses Far to create concrete instances of -// meshes and compute patch CVs with different back ends for table driven -// subdivision. Currently, the following are supported in Osd: -// -// * CPU / C++ with single or multiple threads -// * GLSL kernels with transform feedback into VBOs -// * OpenCL kernels -// * CUDA kernels -// -// The amount of hardware specific computation code is small, ~300 lines of code, -// so it isn't a large effort to support multiple different ones for different -// clients. In the future, it is conceivable that additional dispatchers will be -// developed to target mobile devices. -// - -/* -Copyright (C) Pixar. All rights reserved. - -This license governs use of the accompanying software. If you -use the software, you accept this license. If you do not accept -the license, do not use the software. - -1. Definitions -The terms "reproduce," "reproduction," "derivative works," and -"distribution" have the same meaning here as under U.S. -copyright law. A "contribution" is the original software, or -any additions or changes to the software. -A "contributor" is any person or entity that distributes its -contribution under this license. -"Licensed patents" are a contributor's patent claims that read -directly on its contribution. - -2. Grant of Rights -(A) Copyright Grant- Subject to the terms of this license, -including the license conditions and limitations in section 3, -each contributor grants you a non-exclusive, worldwide, -royalty-free copyright license to reproduce its contribution, -prepare derivative works of its contribution, and distribute -its contribution or any derivative works that you create. -(B) Patent Grant- Subject to the terms of this license, -including the license conditions and limitations in section 3, -each contributor grants you a non-exclusive, worldwide, -royalty-free license under its licensed patents to make, have -made, use, sell, offer for sale, import, and/or otherwise -dispose of its contribution in the software or derivative works -of the contribution in the software. - -3. Conditions and Limitations -(A) No Trademark License- This license does not grant you -rights to use any contributor's name, logo, or trademarks. -(B) If you bring a patent claim against any contributor over -patents that you claim are infringed by the software, your -patent license from such contributor to the software ends -automatically. -(C) If you distribute any portion of the software, you must -retain all copyright, patent, trademark, and attribution -notices that are present in the software. -(D) If you distribute any portion of the software in source -code form, you may do so only under this license by including a -complete copy of this license with your distribution. If you -distribute any portion of the software in compiled or object -code form, you may only do so under a license that complies -with this license. -(E) The software is licensed "as-is." You bear the risk of -using it. The contributors give no express warranties, -guarantees or conditions. You may have additional consumer -rights under your local laws which this license cannot change. -To the extent permitted under your local laws, the contributors -exclude the implied warranties of merchantability, fitness for -a particular purpose and non-infringement. -*/ - -// ### Helper Includes - -// Vector algebra and common GL machinations that have been isolated for -// clarity of the core OSD code. -// - -#include "glhelpers.h" - -// -// ### OpenSubdiv Includes - -// The vertex and mesh headers provide abstract representations -// of verts and meshes; the -// element array buffer provides an abstract representation of an index buffer; -// and finally, the cpu dispatcher is how subdivision work is dispatched to the -// CPU. -// - -#include - -#include -#include -#include -#include -#include -#include - -using namespace OpenSubdiv; - -// -// ### Global Variables & Declarations -// - -// The screen width & height; current frame for animation; and the desired -// subdivision level. -// -int g_width = 0, - g_height = 0, - g_frame = 0, - g_level = 10; - -// -// A center point for the view matrix and the object size for framing -// -float g_center[3] = {0.0f, 0.0f, 0.0f}, - g_size = 0.0f; - - -// -// The coarse mesh positions are saved externally and deformed -// during playback. -// -std::vector g_orgPositions; - -// Global cache of subdivided positions and triangle mesh -std::vector g_refinedPositions; -std::vector g_refinedTriangleIndices; - -GLuint g_refinedPositionsBuf; -GLuint g_refinedTriangleIndicesBuf; - -// -// The OSD state: a mesh, vertex buffer and element array -// -//#include -//OpenSubdiv::OsdGLMeshInterface *g_mesh = 0;; - -typedef OpenSubdiv::HbrMesh OsdHbrMesh; -typedef OpenSubdiv::HbrVertex OsdHbrVertex; -typedef OpenSubdiv::HbrFace OsdHbrFace; -typedef OpenSubdiv::HbrHalfedge OsdHbrHalfedge; - -// -// Forward declarations. These functions will be described below as they are -// defined. -// -void idle(); -void reshape(int width, int height); -void createOsdMesh(int level); -void display(); -void updateGeom(); - -// -// ### The main program entry point -// - -// register the Osd CPU kernel, -// call createOsdMesh (see below), init glew and one-time GL state and enter the -// main glfw loop. -// -void initOsd() -{ - // Initialize OpenGL in glhelpers.h, specify true for "adaptive" so the - // glsl shaders for simple adaptive subdivision will be compiled and linked - initGL(); - - // - // Dispatchers are created from a kernel enumeration via the factory pattern, - // calling register here ensures that the CPU dispatcher will be available - // for construction when it is requested via the kCPU enumeration inside the - // function createOsdMesh. - // - createOsdMesh(g_level); -} - - - - -void -Univar4x4(float u, float *B, float *D) -{ - float t = u; - float s = 1.0f - u; - - float A0 = s * s; - float A1 = 2 * s * t; - float A2 = t * t; - - B[0] = s * A0; - B[1] = t * A0 + s * A1; - B[2] = t * A1 + s * A2; - B[3] = t * A2; - - D[0] = - A0; - D[1] = A0 - A1; - D[2] = A1 - A2; - D[3] = A2; -} - -struct simpleVec3 -{ - float x, y, z; - - simpleVec3() {} - - simpleVec3( float a ) - { - x = a; - y = a; - z = a; - } - simpleVec3( float a, float b, float c ) - { - x = a; - y = b; - z = c; - } - - simpleVec3 & operator+=( simpleVec3 const & v ) - { x += v.x; y += v.y; z += v.z; return *this; } -}; - -inline simpleVec3 operator*( simpleVec3 const & v, float const & s ) { return simpleVec3( v.x * s, v.y * s, v.z * s ); } -inline simpleVec3 operator*( float const & s, simpleVec3 const &v ) { return simpleVec3( v.x * s, v.y * s, v.z * s ); } - -void EvalBezier(float u, - float v, - // all vertex positions for the subdiv - simpleVec3 *vertexBuffer, - // vector of 16 indices into vertexBuffer - const unsigned int *indices, - simpleVec3 &position, - simpleVec3 &utangent, - simpleVec3 &vtangent) -{ - float B[4], D[4]; - - Univar4x4(u, B, D); - - simpleVec3 *cp = vertexBuffer; - - simpleVec3 BUCP[4], DUCP[4]; - - for (int i=0; i<4; ++i) { - BUCP[i] = simpleVec3(0,0,0); - DUCP[i] = simpleVec3(0,0,0); - - for (int j=0; j<4; ++j) { -#if ROTATE == 1 - simpleVec3 A = cp[indices[4*(3-j) + (3-i)]]; -#elif ROTATE == 2 - simpleVec3 A = cp[indices[4*i + (3-j)]]; -#elif ROTATE == 3 - simpleVec3 A = cp[indices[4*j + i]]; -#else - simpleVec3 A = cp[indices[4*i + j]]; -#endif - BUCP[i] += A * B[j]; - DUCP[i] += A * D[j]; - } - } - - position = simpleVec3(0,0,0); - utangent = simpleVec3(0,0,0); - vtangent = simpleVec3(0,0,0); - - Univar4x4(v, B, D); - - for (int i=0; i<4; ++i) { - position += B[i] * BUCP[i]; - utangent += B[i] * DUCP[i]; - vtangent += D[i] * BUCP[i]; - } -} - - - -void -EvalCubicBSpline(float u, float B[4], float BU[4]) -{ - float t = u; - float s = 1.0 - u; - - float C0 = s * (0.5f * s); - float C1 = t * (s + 0.5f * t) + s * (0.5f * s + t); - float C2 = t * ( 0.5f * t); - - B[0] = 1.f/3.f * s * C0; - B[1] = (2.f/3.f * s + t) * C0 + (2.f/3.f * s + 1.f/3.f * t) * C1; - B[2] = (1.f/3.f * s + 2.f/3.f * t) * C1 + ( s + 2.f/3.f * t) * C2; - B[3] = 1.f/3.f * t * C2; - - BU[0] = - C0; - BU[1] = C0 - C1; - BU[2] = C1 - C2; - BU[3] = C2; -} - -void -EvalBSpline(float u, float v, - // all vertex positions for the subdiv - simpleVec3 *vertexBuffer, - // vector of 16 indices into vertexBuffer - const unsigned int *indices, - simpleVec3 *position, simpleVec3 *utangent, simpleVec3 *vtangent) -{ - float B[4], D[4]; - - EvalCubicBSpline(u, B, D); - - simpleVec3 BUCP[4], DUCP[4]; - - simpleVec3 *cp = vertexBuffer; - - for (int i=0; i<4; ++i) { - BUCP[i] = simpleVec3(0,0,0); - DUCP[i] = simpleVec3(0,0,0); - - for (int j=0; j<4; ++j) { - simpleVec3 A = cp[indices[i + j*4]]; - - BUCP[i] += A * B[j]; - DUCP[i] += A * D[j]; - } - } - - *position = simpleVec3(0,0,0); - *utangent = simpleVec3(0,0,0); - *vtangent = simpleVec3(0,0,0); - - EvalCubicBSpline(v, B, D); - - for (int i=0; i<4; ++i) { - *position += B[i] * BUCP[i]; - *utangent += B[i] * DUCP[i]; - *vtangent += D[i] * BUCP[i]; - } -} - - - -class MyPatch { -public: - - // Enum describing the number and arrangment of control vertices - // in the patch. - // - // Regular patches will have 16 CVs, boundary = 12, corner = 9, - // gregory = 4. - enum PatchType { - Regular, - Boundary, - Corner, - Gregory - }; - - // Note that MyPatch retains a pointer to CVs and depends - // on it remaining allocated. - MyPatch(const unsigned int *CVs, PatchType patchType) { - - _patchType = patchType; - - // These tables map the 9, 12, or 16 input control points onto the - // canonical 16 control points for a regular patch. - const int pRegular[16] = - {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - const int pBoundary[16] = - {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - const int pCorner[16] = - {0, 1, 2, 2, 0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8 }; - - const int *p=NULL; - switch (_patchType) { - case Regular: p=pRegular; break; - case Boundary: p=pBoundary; break; - case Corner: p=pCorner; break; - case Gregory: return; // XXX not yet implemented - } - - // These tables account for patch rotation - const int r0[16] = - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; -/* - const int r1[16] = - { 12, 8, 4, 0, 13, 9, 5, 1, 14, 10, 6, 2, 15, 11, 7, 3 }; - const int r2[16] = - { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; - const int r3[16] = - { 3, 7, 11, 15, 2, 6, 10, 14, 1, 5, 9, 13, 0, 4, 8, 12 }; -*/ - - // XXX deal with rotation here - const int *r = r0; - - // Expand and rotate control points using remapping tables - // above. Now the CVs will be expressed as a consistent 16 cv - // arrangment for EvalBSpline use in Eval. - // - for (int i=0;i<16; ++i) { - _cvs[i] = CVs[p[r[i]]]; - } - - } - void Eval( float u, float v, simpleVec3 *vertexBuffer, - simpleVec3 *position, simpleVec3 *utangent, - simpleVec3 *vtangent) { - if (_patchType != Gregory) { - EvalBSpline(u, v, vertexBuffer, _cvs, - position, utangent, vtangent); - } - } - - static int RingSizeForPatchType(PatchType patchType) { - switch (patchType) { - case Regular: return 16; - case Boundary: return 12; - case Corner: return 9; - case Gregory: return 4; - } - } - -private: - - - // Packed patch control vertices - // 0 1 2 3 - // 4 5 6 7 - // 8 9 10 11 - // 12 13 14 15 - unsigned int _cvs[16]; - - PatchType _patchType; -}; - - - - -static bool -TestPatchEvaluation() -{ - - // This method creates a 4x4 cubic patch with limit - // surface from 0->1 in x and y - - float positions[16*3] = { - -1.0f, -1.0f, 0.0f, - 0.00f, -1.0f, 0.0f, - 1.00f, -1.0f, 0.0f, - 2.00f, -1.0f, 0.0f, - - -1.0f, 0.00f, 0.0f, - 0.00f, 0.00f, 0.0f, - 1.00f, 0.00f, 0.0f, - 2.00f, 0.00f, 0.0f, - - -1.0f, 1.00f, 0.0f, - 0.00f, 1.00f, 0.0f, - 1.00f, 1.00f, 0.0f, - 2.00f, 1.00f, 0.0f, - - -1.0f, 2.00f, 0.0f, - 0.00f, 2.00f, 0.0f, - 1.00f, 2.00f, 0.0f, - 2.00f, 2.00f, 0.0f}; - - unsigned int faceIndices[16] = { - 0,1,2,3, - 4,5,6,7, - 8,9,10,11, - 12,13,14,15}; - - MyPatch patch(faceIndices, MyPatch::Regular); - - for (float u=0; u<=1.0; u+= 0.2) { - for (float v=0; v<=1.0; v+= 0.2) { - simpleVec3 position; - simpleVec3 uTangent; - simpleVec3 vTangent; - patch.Eval(u, v, (simpleVec3*)positions, - &position, &uTangent, &vTangent); - - std::cout << u << "," << v << "( " << - position.x << ", " << - position.y << ", " << - position.z << "), "; - } - std::cout << "\n"; - } - - return true; -} - - - - - -class OsdEvalContext : OpenSubdiv::OsdNonCopyable { -public: - - explicit OsdEvalContext( - OpenSubdiv::FarMesh *farmesh, - unsigned int elementsPerVertex); - - virtual ~OsdEvalContext(); - - // vertexData contains one float for each "elementsPerVertex", - // for each vertex. For position it'd be three floats for each vertex. - void UpdateData(float *vertexData); - - void TessellateIntoTriangles( - std::vector *elementArray, - std::vector *vertices); - - OpenSubdiv::FarMesh *GetFarMesh() { return _farMesh; } - - - /* - GetPatch(faceID) { - if (regular) { - } - - } - Eval(int faceID, float u, float v, float *return, const OsdVertexBuffer &buf) { - // gimme 16 indices into the vertex buffer and remap u and v for me into the local parameter space of the patch. - // XXX do something a little different for boundary and corner. - 16indices indices = GetPatch(faceID, &u, &v); - u = remap(u); - v = remap(v); - - EvalBSpline(u,v , cp, WorldPos, Tangent, BiTangent); - - - } - */ - - OpenSubdiv::FarTable _patchTable; - - -private: - - // Create evaluation patches given a table describing a bunch of - // patches, and the "ringSize" or number of CVs per patch. - // - // Regular patches will have ringSize = 16, boundary = 12, - // corner = 9, gregory = 4. - // - void _AppendPatchArray( - const OpenSubdiv::FarTable &ptable, - MyPatch::PatchType patchType) { - - // Iterate over all patches in this table. Don't worry about - // markers here, those would tell use what level of - // subdivision the patch was created on. - // - // Just iterate over all patches, this is in blocks of - // 16, 12, 9, or 4 unsigned ints per patch depending - // on patchType - // - const unsigned int *vertIndices = ptable[0]; - int ringSize = MyPatch::RingSizeForPatchType(patchType); - - for (int i=0; i *_farMesh; - std::vector _patches; - - // ElementsPerVertex would be 3 for xyz position, 6 for xyz - // position + xyz normal, or more for shading data. Here elements - // represents the data specified per vertex and interpolated on the - // surface, e.g. vertex varying - // - unsigned int _elementsPerVertex; - - OpenSubdiv::OsdCpuComputeContext *_osdComputeContext; - OpenSubdiv::OsdCpuComputeController _osdComputeController; - OpenSubdiv::OsdCpuVertexBuffer *_osdVertexBuffer; -}; - - -OsdEvalContext::OsdEvalContext( - OpenSubdiv::FarMesh *farMesh, - unsigned int elementsPerVertex) - : _farMesh(farMesh), - _elementsPerVertex(elementsPerVertex) -{ - - const FarPatchTables *patchTables = farMesh->GetPatchTables(); - - if (not patchTables) { - std::cout << "Oooops- patchTables not constructed\n"; - return; - } else { - std::cout << "Have some patchTables\n"; - } - - // Iterate over the patches generated by feature - // adaptive refinement and create MyPatch objects. - // - _AppendPatchArray(patchTables->GetFullRegularPatches(), MyPatch::Regular); - - _AppendPatchArray(patchTables->GetFullBoundaryPatches(), MyPatch::Boundary); - _AppendPatchArray(patchTables->GetFullCornerPatches(), MyPatch::Corner); - - _AppendPatchArray(patchTables->GetFullGregoryPatches(), MyPatch::Gregory); - _AppendPatchArray(patchTables->GetFullBoundaryGregoryPatches(), - MyPatch::Gregory); - - for (int p=0; p<5; ++p) { - _AppendPatchArray(patchTables->GetTransitionRegularPatches(p), - MyPatch::Regular); - - for (int r=0; r<4; ++r) { - _AppendPatchArray(patchTables->GetTransitionBoundaryPatches(p, r), - MyPatch::Boundary); - _AppendPatchArray(patchTables->GetTransitionCornerPatches(p, r), - MyPatch::Corner); - } - } - - - - - std::cout << "Made " << _patches.size() << " patches\n"; - - // Now create OpenSubdiv compute objects that will be used - // later for limit surface computation - - _osdComputeContext = OpenSubdiv::OsdCpuComputeContext::Create(_farMesh); - _osdVertexBuffer = - OpenSubdiv::OsdCpuVertexBuffer::Create( - 3 /* 3 floats for position*/ , _farMesh->GetNumVertices()); -} - - -OsdEvalContext::~OsdEvalContext() -{ - if (_osdComputeContext) - delete _osdComputeContext; - - if (_osdVertexBuffer) - delete _osdVertexBuffer; -} - - - -void -OsdEvalContext::UpdateData(float *vertexData) -{ - // Now compute control point positions and shading data on the - // refined surface. - // - - // - // Send the animated coarse positions to the vertex buffer. - // - _osdVertexBuffer->UpdateData(vertexData, _farMesh->GetNumVertices()); - - // - // Dispatch subdivision work based on the coarse vertex buffer. At this - // point, the assigned dispatcher will queue up work, potentially in many - // worker threads. If the subdivided data is required for further - // processing a call to Synchronize() will allow you to block until - // the worker threads complete. - // - _osdComputeController.Refine(_osdComputeContext, _osdVertexBuffer); - - // - // Is the call to Synchronize() needed here in order to call BindCpuBuffer - // later? - // - _osdComputeController.Synchronize(); -} - - -void -OsdEvalContext::TessellateIntoTriangles( - std::vector *elementArray, - std::vector *vertices) -{ - float *points = _osdVertexBuffer->BindCpuBuffer(); - - unsigned int N = 5; - unsigned int N1 = N+1; - float delta = 1.0/(float)N; - - unsigned int debugPatch = -1; - - for (unsigned int i=0; i< _patches.size(); ++i) { - - // Add points for this patch first, record the starting - // index of the points for this patch within vertices - // before adding point positions - int baseIndex = vertices->size()/3; - - for (float u=0; u<=1.0; u+=delta) { - for (float v=0; v<=1.0; v+=delta) { - simpleVec3 position, utangent, vtangent; - _patches[i].Eval(u, v, (simpleVec3*)points, - &position, &utangent, &vtangent); - vertices->push_back(position.x); - vertices->push_back(position.y); - vertices->push_back(position.z); - if (i==debugPatch) { - std::cout << "\tPoint " << position.x << ", " << position.y << ", " << position.z << std::endl; - } - } - } - - if (i==debugPatch) - std::cout << "Num points = " << vertices->size()/3 << "\n"; - - // Now add indexing for triangles - for (unsigned int u=baseIndex; u< N*N + baseIndex; u+=N1) { - for (unsigned int v=0; v< N; ++v) { - // Add the indices for two triangles that get their - // point positions from the vertices array - elementArray->push_back(u + v ); - elementArray->push_back(u + N1 + v ); - elementArray->push_back(u + N1 + v + 1); - - elementArray->push_back(u + v); - elementArray->push_back(u + N1 + v + 1); - elementArray->push_back(u + v + 1); - - if ((u+N1+v+1) > vertices->size()) { - std::cout << "ERROR: " << - u << "," << - N1 << "," << - v << "," << - vertices->size() << "\n"; - } - if (i==debugPatch) { - std::cout << "triIndices: "; - for (int j=0; j<6; ++j) { - std::cout << " " << (*elementArray)[elementArray->size() - (6-j)]; - } - std::cout << "\n"; - } - - } - if (i==debugPatch) - std::cout << "\n"; - - - } - } -} - - -OsdEvalContext *g_evalContext = NULL; - -// -// ### Construct the OSD Mesh - -// Here is where the real meat of the OSD setup happens. The mesh topology is -// created and stored for later use. Actual subdivision happens in updateGeom -// which gets called at the end of this function and on frame change. -// -void -createOsdMesh(int level) -{ - std::cout << "Start createOsdMesh\n"; - - - TestPatchEvaluation(); - - // - // Setup an OsdHbr mesh based on the desired subdivision scheme - // - static OpenSubdiv::HbrCatmarkSubdivision _catmark; - OsdHbrMesh *hmesh(new OsdHbrMesh(&_catmark)); - - - // - // Now that we have a mesh, we need to add verticies and define the - // topology. - // - // Here, we've declared the raw vertex data in-line, for simplicity - // - float verts[] = { 0.000000f, -1.414214f, 1.000000f, - 1.414214f, 0.000000f, 1.000000f, - -1.414214f, 0.000000f, 1.000000f, - 0.000000f, 1.414214f, 1.000000f, - -1.414214f, 0.000000f, -1.000000f, - 0.000000f, 1.414214f, -1.000000f, - 0.000000f, -1.414214f, -1.000000f, - 1.414214f, 0.000000f, -1.000000f - }; - - // - // The cube faces are also in-lined, here they are specified as quads - // - int faces[] = { - 0,1,3,2, - 2,3,5,4, - 4,5,7,6, - 6,7,1,0, - 1,7,5,3, - 6,0,2,4 - }; - - - // - // Record the original vertex positions and add verts to the mesh. - // - // OsdVertex is really just a place holder, it doesn't care what the - // position of the vertex is, it's just being used here as a means of - // defining the mesh topology. - // - for (unsigned i = 0; i < sizeof(verts)/sizeof(float); i += 3) { - g_orgPositions.push_back(verts[i+0]); - g_orgPositions.push_back(verts[i+1]); - g_orgPositions.push_back(verts[i+2]); - - OpenSubdiv::OsdVertex vert; - hmesh->NewVertex(i/3, vert); - } - - // - // Now specify the actual mesh topology by processing the faces array - // - const unsigned VERTS_PER_FACE = 4; - for (unsigned i = 0; i < sizeof(faces)/sizeof(int); i += VERTS_PER_FACE) { - // - // Do some sanity checking. It is a good idea to keep this in your - // code for your personal sanity as well. - // - // Note that this loop is not changing the HbrMesh, it's purely validating - // the topology that is about to be created below. - // - for (unsigned j = 0; j < VERTS_PER_FACE; j++) { - OsdHbrVertex * origin = hmesh->GetVertex(faces[i+j]); - OsdHbrVertex * destination = hmesh->GetVertex(faces[i+((j+1)%VERTS_PER_FACE)]); - OsdHbrHalfedge * opposite = destination->GetEdge(origin); - - if(origin==NULL || destination==NULL) { - std::cerr << - " An edge was specified that connected a nonexistent vertex" - << std::endl; - exit(1); - } - - if(origin == destination) { - std::cerr << - " An edge was specified that connected a vertex to itself" - << std::endl; - exit(1); - } - - if(opposite && opposite->GetOpposite() ) { - std::cerr << - " A non-manifold edge incident to more than 2 faces was found" - << std::endl; - exit(1); - } - - if(origin->GetEdge(destination)) { - std::cerr << - " An edge connecting two vertices was specified more than once." - " It's likely that an incident face was flipped" - << std::endl; - exit(1); - } - } - // - // Now, create current face given the number of verts per face and the - // face index data. - // -// OsdHbrFace * face = hmesh->NewFace(VERTS_PER_FACE, faces+i, 0); - hmesh->NewFace(VERTS_PER_FACE, faces+i, 0); - - // - // If you had ptex data, you would set it here, for example - // - /* face->SetPtexIndex(ptexIndex) */ - - } - - // - // Apply some tags to drive the subdivision algorithm. Here we set the - // default boundary interpolation mode along with a corner sharpness. See - // the API and the renderman spec for the full list of available operations. - // - hmesh->SetInterpolateBoundaryMethod( OsdHbrMesh::k_InterpolateBoundaryEdgeOnly ); - - OsdHbrVertex * v = hmesh->GetVertex(0); - v->SetSharpness(2.7f); - - // - // Finalize the mesh object. The Finish() call is a signal to the internals - // that optimizations can be made on the mesh data. - // - hmesh->Finish(); - - // has 3 elements per vertex (3 floats for position), is defined by the topology - // in hmesh to level subdivisions, and has a bitset that indicates osd should use - // adaptive subdivision. - // - OpenSubdiv::FarMeshFactory meshFactory(hmesh, level, true); - - OpenSubdiv::FarMesh *farMesh = - meshFactory.Create(false /*ptex data*/, false /*fvar data*/); - - // hmesh is no longer needed - delete hmesh; - - - g_evalContext = new OsdEvalContext(farMesh, 3); - - // - // Setup camera positioning based on object bounds. This really has nothing - // to do with OSD. - // - computeCenterAndSize(g_orgPositions, g_center, &g_size); - - // - // Finally, make an explicit call to updateGeom() to force creation of the - // initial buffer objects for the first draw call. - // - g_evalContext->UpdateData(&g_orgPositions[0]); - - // - std::cout << "about to tessellate\n"; - g_evalContext->TessellateIntoTriangles( &g_refinedTriangleIndices, - &g_refinedPositions); - std::cout << "done tessellating\n"; - -// for (unsigned int i=0; i vertex; - vertex.reserve(nverts*3); - - const float *p = &g_orgPositions[0]; - - // - // Apply a simple deformer to the coarse mesh. We save the deformed points - // into a separate buffer to avoid accumulation of error. This - // loop really has nothing to do with OSD. - // - float r = sin(g_frame*0.01f); - for (int i = 0; i < nverts; ++i) { -// float move = 0.05f*cosf(p[0]*20+g_frame*0.001f); - float ct = cos(p[2] * r); - float st = sin(p[2] * r); - - vertex.push_back(p[0]*ct + p[1]*st); - vertex.push_back(-p[0]*st + p[1]*ct); - vertex.push_back(p[2]); - - p += 3; - } - - // - // Send the animated coarse positions to the eval context, - // it'll do the refinement - // - g_evalContext->UpdateData(&vertex[0]); - - // re-get our refined triangle mesh - g_refinedTriangleIndices.clear(); - g_refinedPositions.clear(); - g_evalContext->TessellateIntoTriangles( &g_refinedTriangleIndices, - &g_refinedPositions); - -// std::cout << "End updateGeom\n"; -} - - -// -// ### Draw the Mesh - -// Display handles all drawing per frame. We first call the setupForDisplay -// helper method to setup some uninteresting GL state and then bind the mesh -// using the buffers provided by our OSD objects -// -void -display() -{ -// std::cout << "Start display\n"; - setupForDisplay(g_width, g_height, g_size, g_center); - - // - // Bind the GL vertex and index buffers - // - // Bind the GL vertex buffer and send newly - // refined points down the pipe - glBindBuffer(GL_ARRAY_BUFFER, g_refinedPositionsBuf); - glBufferSubData(GL_ARRAY_BUFFER, 0, - g_refinedPositions.size() * sizeof(float) * 3, - &g_refinedPositions[0]); - - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_refinedTriangleIndicesBuf); - -// glColor3f(0.5, 0.5, 0.5); - glDrawElements(GL_TRIANGLES, g_refinedTriangleIndices.size()/3, - GL_UNSIGNED_INT, NULL); - -// glColor3f(0.2, 0.2, 0.2); -// glDrawElements(GL_LINES, g_refinedTriangleIndices.size()/2, -// GL_UNSIGNED_INT, NULL); - -// glColor3f(1.0, 1.0, 1.0); - glDrawElements(GL_POINTS, g_refinedTriangleIndices.size()/3, - GL_UNSIGNED_INT, NULL); - - - - // - // This isn't strictly necessary, but unbind the GL state - // - glUseProgram(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - //glDisableClientState(GL_VERTEX_ARRAY); - - // - // Draw the HUD/status text - // - //glColor3f(1, 1, 1); - drawString(10, 10, "LEVEL = %d", (int)g_level); - drawString(10, 30, "# of Vertices = %d", (int)g_refinedPositions.size()/3); - drawString(10, 50, "KERNEL = CPU"); - drawString(10, 70, "SUBDIVISION = %s", "CATMARK"); - - // - // Finish the current frame - // - glFinish(); - - checkGLErrors("End display"); -// std::cout << "End display\n"; -} - - diff --git a/examples/evalTest/glhelpers.h b/examples/evalTest/glhelpers.h deleted file mode 100644 index 282c5d25..00000000 --- a/examples/evalTest/glhelpers.h +++ /dev/null @@ -1,242 +0,0 @@ -// -// This file contains standard OpenGL API calls that are mostly uninteresting if -// you are purely trying to learn OSD. The following operations are implemented -// here: -// -// * First time OpenGL state initialization -// * Compile vertex and fragment shaders -// * Link shaders into a program -// * Per-frame drawing state setup -// - -#pragma once - -// -// ### OS Compatibility -// The following is to ensure the example runs on Linux, Windows and OS X -// -#if defined(__APPLE__) - #include - #define GLFW_INCLUDE_GL3 - #define GLFW_NO_GLU -#else - #include - #include - #if defined(WIN32) - #include - #endif -#endif - -#if defined(GLFW_VERSION_3) - #include - GLFWwindow* g_window=0; - GLFWmonitor* g_primary=0; -#else - #include -#endif - - - -#include "algebra.h" - -#include -#include -#include - -// -// Microsoft uses a slightly different snprintf declaration, which we hide -// here by aliasing it as snprintf -// -#if _MSC_VER - #define snprintf _snprintf -#endif - -#if defined(__APPLE__) -#define drawString(x, y, ...); -/* \ - GLUT on OSX means gl 2.1, so forgoe the text drawing until we have a better solution - { char line[1024]; \ - snprintf(line, 1024, __VA_ARGS__); \ - char *p = line; \ - glWindowPos2f(x, y); \ - while(*p) { glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p++); } } - */ -#else -#define drawString(x, y, ...) \ - { char line[1024]; \ - snprintf(line, 1024, __VA_ARGS__); \ - char *p = line; \ - glWindowPos2i(x, y); \ - while(*p) { glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p++); } } -#endif - -// -// These are standard OpenGL shader program handles. One for wire frame and one -// for shaded rendering -// -GLuint g_quadLineProgram = 0; -GLuint g_quadFillProgram = 0; - -// -// To avoid reading the shader source from a file, we include it here as a string -// see [shader.glsl](shader.html). -// -static const char *shaderSource = -#include "shader.inc" -; - -GLfloat g_modelView[16], g_proj[16], g_mvp[16]; - -void -bindProgram(GLuint program) -{ - glUseProgram(program); - - // shader uniform setting - GLint position = glGetUniformLocation(program, "lightSource[0].position"); - GLint ambient = glGetUniformLocation(program, "lightSource[0].ambient"); - GLint diffuse = glGetUniformLocation(program, "lightSource[0].diffuse"); - GLint specular = glGetUniformLocation(program, "lightSource[0].specular"); - GLint position1 = glGetUniformLocation(program, "lightSource[1].position"); - GLint ambient1 = glGetUniformLocation(program, "lightSource[1].ambient"); - GLint diffuse1 = glGetUniformLocation(program, "lightSource[1].diffuse"); - GLint specular1 = glGetUniformLocation(program, "lightSource[1].specular"); - - glUniform4f(position, 0.5, 0.2f, 1.0f, 0.0f); - glUniform4f(ambient, 0.1f, 0.1f, 0.1f, 1.0f); - glUniform4f(diffuse, 0.7f, 0.7f, 0.7f, 1.0f); - glUniform4f(specular, 0.8f, 0.8f, 0.8f, 1.0f); - - glUniform4f(position1, -0.8f, 0.4f, -1.0f, 0.0f); - glUniform4f(ambient1, 0.0f, 0.0f, 0.0f, 1.0f); - glUniform4f(diffuse1, 0.5f, 0.5f, 0.5f, 1.0f); - glUniform4f(specular1, 0.8f, 0.8f, 0.8f, 1.0f); - - GLint otcMatrix = glGetUniformLocation(program, "objectToClipMatrix"); - GLint oteMatrix = glGetUniformLocation(program, "objectToEyeMatrix"); - multMatrix(g_mvp, g_modelView, g_proj); - - glUniformMatrix4fv(otcMatrix, 1, false, g_mvp); - glUniformMatrix4fv(oteMatrix, 1, false, g_modelView); -} - -static GLuint -compileShader(GLenum shaderType, const char *section, const char *define) -{ - const char *sources[4]; - char sdefine[64]; - sprintf(sdefine, "#define %s\n", section); - - sources[0] = "#version 330\n"; - sources[1] = define; - sources[2] = sdefine; - sources[3] = shaderSource; - - GLuint shader = glCreateShader(shaderType); - glShaderSource(shader, 4, sources, NULL); - glCompileShader(shader); - - GLint status; - glGetShaderiv(shader, GL_COMPILE_STATUS, &status); - if( status == GL_FALSE ) { - GLchar emsg[1024]; - glGetShaderInfoLog(shader, sizeof(emsg), 0, emsg); - fprintf(stderr, "Error compiling GLSL shader (%s): %s\n", section, emsg ); - fprintf(stderr, "Section: %s\n", sdefine); - fprintf(stderr, "Defines: %s\n", define); - fprintf(stderr, "Source: %s\n", sources[2]); - exit(0); - } - - return shader; -} - -GLuint -linkProgram(const char *define) -{ - GLuint vertexShader = compileShader(GL_VERTEX_SHADER, "VERTEX_SHADER", define); - GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, "FRAGMENT_SHADER", define); - - GLuint program = glCreateProgram(); - glAttachShader(program, vertexShader); - glAttachShader(program, fragmentShader); - - glBindAttribLocation(program, 0, "position"); - - glLinkProgram(program); - - glDeleteShader(vertexShader); - glDeleteShader(fragmentShader); - - GLint status; - glGetProgramiv(program, GL_LINK_STATUS, &status ); - if( status == GL_FALSE ) { - GLchar emsg[1024]; - glGetProgramInfoLog(program, sizeof(emsg), 0, emsg); - fprintf(stderr, "Error linking GLSL program : %s\n", emsg ); - fprintf(stderr, "Defines: %s\n", define); - exit(0); - } - - return program; -} - -void -initGL() -{ - glClearColor(0.1f, 0.1f, 0.1f, 1.0f); - - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glDepthFunc(GL_LEQUAL); - - g_quadFillProgram = linkProgram("#define PRIM_QUAD\n#define GEOMETRY_OUT_FILL\n"); - g_quadLineProgram = linkProgram("#define PRIM_QUAD\n#define GEOMETRY_OUT_LINE\n"); -} - -void -setupForDisplay(int width, int height, float size, float* center) -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glViewport(0, 0, width, height); - setIdentity(g_proj); - setIdentity(g_modelView); - setIdentity(g_mvp); - - // setup the projection - float aspect = width/(float)height; - setPersp(45.0f, aspect, 0.01f, 500.0f, g_proj); - - // setup the model view matrix - translateMatrix(-center[0], -center[1], -center[2], g_modelView); - rotateMatrix(-90, 1, 0, 0, g_modelView); // z-up model - translateMatrix(0, 0, -size, g_modelView); -} - - -static void -checkGLErrors(std::string const & where = "") -{ - GLuint err; - while ((err = glGetError()) != GL_NO_ERROR) { - std::cout << "Where = " << where << std::endl; - - if (err == GL_INVALID_ENUM) { - std::cout << "GL_INVALID_ENUM\n"; - } else - if (err == GL_INVALID_VALUE) { - std::cout << "GL_INVALID_VALUE\n"; - } else - if (err == GL_INVALID_OPERATION) { - std::cout << "GL_INVALID_OPERATION\n"; - } else - if (err == GL_INVALID_OPERATION) { - std::cout << "GL_INVALID_OPERATION\n"; - } else - if (err == GL_OUT_OF_MEMORY) { - std::cout << "GL_OUT_OF_MEMORY\n"; - } else { - std::cout << "Some other gl error \n"; - } - } -} diff --git a/examples/evalTest/mainApple.mm b/examples/evalTest/mainApple.mm deleted file mode 100644 index b4b1d4c5..00000000 --- a/examples/evalTest/mainApple.mm +++ /dev/null @@ -1,176 +0,0 @@ -#import -#import -#import -#import -#import -// -// Hooks back into the example code -// -extern void initOsd(); -extern void updateGeom(); -extern void display(); - -// -// Shared global state from the example -// -extern int g_width, g_height, g_frame; - - -// -// OSX application bootstrap -// -@class View; - -@interface View : NSOpenGLView { - NSRect m_frameRect; - BOOL m_didInit; - uint64_t m_previousTime; - NSTimer* m_timer; -} - -- (void) animate; - -@end - -@implementation View - --(void)windowWillClose:(NSNotification *)note -{ - [[NSApplication sharedApplication] terminate:self]; -} - -- (void) timerFired:(NSTimer*) timer -{ - [self animate]; -} - -- (id) initWithFrame: (NSRect) frame -{ - m_didInit = FALSE; - - // - // Various GL state, of note is the 3.2 Core profile selection - // and 8x antialiasing, which we might want to disable for performance - // - int attribs[] = { - NSOpenGLPFAAccelerated, - NSOpenGLPFADoubleBuffer, - NSOpenGLPFADepthSize, 24, - NSOpenGLPFAAlphaSize, 8, - NSOpenGLPFAColorSize, 32, - NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, - NSOpenGLPFANoRecovery, - kCGLPFASampleBuffers, 1, - kCGLPFASamples, 8, - 0 - }; - - NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] - initWithAttributes:(NSOpenGLPixelFormatAttribute*) attribs]; - - self = [self initWithFrame:frame pixelFormat:fmt]; - [fmt release]; - m_frameRect = frame; - m_timer = [[NSTimer - scheduledTimerWithTimeInterval:1.0f/120.0f - target:self - selector:@selector(timerFired:) - userInfo:nil - repeats:YES] retain]; - - return self; -} - -- (void) drawRect:(NSRect) theRect -{ - if (!m_didInit) { - initOsd(); - - m_didInit = YES; - - [[self window] setLevel: NSFloatingWindowLevel]; - [[self window] makeKeyAndOrderFront: self]; - [[self window] setTitle: [NSString stringWithUTF8String: "SimpleCPU"]]; - } - - // run the example code - display(); - - // make sure GL state is clean - assert(glGetError() == GL_NO_ERROR); - - [[self openGLContext] flushBuffer]; -} - -- (void) animate -{ - g_frame++; - updateGeom(); - [self display]; -} -@end - -int main(int argc, const char *argv[]) -{ - // - // It seems that some ATI cards fall back to software when rendering geometry shaders - // but only *sometimes*. Post this notice so it's obvious that OSD isn't the problem. - // - // XXX(jcowles): we should only use vertex and fragment shaders to avoid this potential confusion - // - std::cout << "--------------------------------------------------------------------------------" << std::endl; - std::cout << "NOTICE: Some Apple hardware runs geometry shaders in software, which will cause" << std::endl; - std::cout << " this demo to run extremely slowly. That slowness is not related to OSD" << std::endl; - std::cout << " and can be avoided by not using OpenGL geometry shaders." << std::endl; - std::cout << "--------------------------------------------------------------------------------" << std::endl; - - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSApplication *NSApp = [NSApplication sharedApplication]; - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - - id menubar = [[NSMenu new] autorelease]; - id appMenuItem = [[NSMenuItem new] autorelease]; - [menubar addItem:appMenuItem]; - [NSApp setMainMenu:menubar]; - - id appMenu = [[NSMenu new] autorelease]; - id appName = [[NSProcessInfo processInfo] processName]; - id quitTitle = [@"Quit " stringByAppendingString:appName]; - id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle - action:@selector(terminate:) keyEquivalent:@"q"] autorelease]; - [appMenu addItem:quitMenuItem]; - [appMenuItem setSubmenu:appMenu]; - - NSRect screenBounds = [[NSScreen mainScreen] frame]; - - g_width = 512; - g_height = 512; - NSRect viewBounds = NSMakeRect(0, 0, g_width, g_height); - - View* view = [[View alloc] initWithFrame:viewBounds]; - - NSRect centered = NSMakeRect(NSMidX(screenBounds) - NSMidX(viewBounds), - NSMidY(screenBounds) - NSMidY(viewBounds), - viewBounds.size.width, viewBounds.size.height); - - NSWindow *window = [[NSWindow alloc] - initWithContentRect:centered - styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask - backing:NSBackingStoreBuffered - defer:NO]; - - [window setContentView:view]; - [window setDelegate:view]; - [window makeKeyAndOrderFront:nil]; - [NSApp activateIgnoringOtherApps:YES]; - - [view release]; - - [NSApp run]; - - - [pool release]; - return EXIT_SUCCESS; -} - - diff --git a/examples/evalTest/mainGlut.cpp b/examples/evalTest/mainGlut.cpp deleted file mode 100644 index b3097ecd..00000000 --- a/examples/evalTest/mainGlut.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -#include -#include -#include - -extern void initOsd(); -extern void updateGeom(); -extern void display(); -extern int g_width, g_height, g_frame; - -// -// ### Misc. GLUT Callback Methods - -// Reshape is called when the window is resized, here we need the width and -// height so that we can correctly adjust the aspect ratio of the projection -// matrix. -// -void -reshape(int width, int height) -{ - g_width = width; - g_height = height; -} - -// -// Idle is called between frames, here we advance the frame number and update -// the procedural animation that is being applied to the mesh -// -void -idle() -{ - g_frame++; - updateGeom(); - glutPostRedisplay(); -} - -// -// ### Draw the Mesh - -// Display handles all drawing per frame. We first call the setupForDisplay -// helper method to setup some uninteresting GL state and then bind the mesh -// using the buffers provided by our OSD objects -// -void -glutDisplay() -{ - display(); - glutSwapBuffers(); -} - - -int main(int argc, char ** argv) -{ - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE | GLUT_DEPTH); - glutInitWindowSize(1024, 1024); - glutCreateWindow("CPU Subdivision Example"); - - // - // Setup glut, glew and some initial GL state - // - glutDisplayFunc(glutDisplay); - glutReshapeFunc(reshape); - glewInit(); - - initOsd(); - - // - // Start the main glut drawing loop - // - glutIdleFunc(idle); - glutMainLoop(); -} - diff --git a/examples/evalTest/notes.md b/examples/evalTest/notes.md deleted file mode 100644 index 54504464..00000000 --- a/examples/evalTest/notes.md +++ /dev/null @@ -1,38 +0,0 @@ -Setup: -====== - * clone docco - git clone https://github.com/jashkenas/docco.git - * install node.js - http://nodejs.org/ - * npm install commander - * sudo easy_install Pygments - -Generate documentation: -======================= -$ ~/src/docco/bin/docco simpleCpuSubdivision.cpp - - - -Trina's Setup -(setup above didn't work for me, here's what I did, YMMV) - -To Generate docco html file: - -* sudo easy_install Pygments - -* install node from http://nodejs.org/ -* put source into /usr/local/src - - % cd /usr/local/src/node-VERSION - % ./configure - % make - % make install - % npm install -g docco - -* docco should now be in /usr/local/bin -* rehash -* cd /your/source/code/directory -* docco yoursource.cpp - voila! -* docs go into /your/source/code/directory/docs - diff --git a/examples/evalTest/shader.glsl b/examples/evalTest/shader.glsl deleted file mode 100644 index 6e311b61..00000000 --- a/examples/evalTest/shader.glsl +++ /dev/null @@ -1,142 +0,0 @@ -// -// Copyright (C) Pixar. All rights reserved. -// -// This license governs use of the accompanying software. If you -// use the software, you accept this license. If you do not accept -// the license, do not use the software. -// -// 1. Definitions -// The terms "reproduce," "reproduction," "derivative works," and -// "distribution" have the same meaning here as under U.S. -// copyright law. A "contribution" is the original software, or -// any additions or changes to the software. -// A "contributor" is any person or entity that distributes its -// contribution under this license. -// "Licensed patents" are a contributor's patent claims that read -// directly on its contribution. -// -// 2. Grant of Rights -// (A) Copyright Grant- Subject to the terms of this license, -// including the license conditions and limitations in section 3, -// each contributor grants you a non-exclusive, worldwide, -// royalty-free copyright license to reproduce its contribution, -// prepare derivative works of its contribution, and distribute -// its contribution or any derivative works that you create. -// (B) Patent Grant- Subject to the terms of this license, -// including the license conditions and limitations in section 3, -// each contributor grants you a non-exclusive, worldwide, -// royalty-free license under its licensed patents to make, have -// made, use, sell, offer for sale, import, and/or otherwise -// dispose of its contribution in the software or derivative works -// of the contribution in the software. -// -// 3. Conditions and Limitations -// (A) No Trademark License- This license does not grant you -// rights to use any contributor's name, logo, or trademarks. -// (B) If you bring a patent claim against any contributor over -// patents that you claim are infringed by the software, your -// patent license from such contributor to the software ends -// automatically. -// (C) If you distribute any portion of the software, you must -// retain all copyright, patent, trademark, and attribution -// notices that are present in the software. -// (D) If you distribute any portion of the software in source -// code form, you may do so only under this license by including a -// complete copy of this license with your distribution. If you -// distribute any portion of the software in compiled or object -// code form, you may only do so under a license that complies -// with this license. -// (E) The software is licensed "as-is." You bear the risk of -// using it. The contributors give no express warranties, -// guarantees or conditions. You may have additional consumer -// rights under your local laws which this license cannot change. -// To the extent permitted under your local laws, the contributors -// exclude the implied warranties of merchantability, fitness for -// a particular purpose and non-infringement. -// - -//-------------------------------------------------------------- -// Vertex Shader -//-------------------------------------------------------------- -#ifdef VERTEX_SHADER - -layout (location=0) in vec3 position; -layout (location=1) in vec3 normal; - -uniform mat4 objectToClipMatrix; -uniform mat4 objectToEyeMatrix; - -out vec3 vPosition; -out vec3 vNormalEye; - -void main() -{ - // vertex position in object space - vPosition = position; - - // vertex position in clip space - gl_Position = objectToClipMatrix * vec4(position, 1); - - // surface normal in eye space - vNormalEye = (objectToEyeMatrix * vec4(normal, 0)).xyz; -} - -#endif - -//-------------------------------------------------------------- -// Fragment Shader -//-------------------------------------------------------------- -#ifdef FRAGMENT_SHADER - -layout (location=0) out vec4 FragColor; -in vec3 vNormalEye; -in vec3 vPosition; - -#define NUM_LIGHTS 2 - -struct LightSource { - vec4 position; - vec4 ambient; - vec4 diffuse; - vec4 specular; -}; - -uniform LightSource lightSource[NUM_LIGHTS]; - -vec4 -lighting(vec3 Peye, vec3 Neye) -{ - vec4 color = vec4(0); - vec4 material = vec4(0.4, 0.4, 0.8, 1); - - for (int i = 0; i < NUM_LIGHTS; ++i) { - - vec4 Plight = lightSource[i].position; - - vec3 l = (Plight.w == 0.0) - ? normalize(Plight.xyz) : normalize(Plight.xyz - Peye); - - vec3 n = normalize(Neye); - vec3 h = normalize(l + vec3(0,0,1)); // directional viewer - - float d = max(0.0, dot(n, l)); - float s = pow(max(0.0, dot(n, h)), 500.0f); - - color += lightSource[i].ambient * material - + d * lightSource[i].diffuse * material - + s * lightSource[i].specular; - } - - color.a = 1; - return color; -} - -void -main() -{ - vec3 N = (gl_FrontFacing ? vNormalEye : -vNormalEye); - FragColor = lighting(vPosition, N); - FragColor = vec4(1,0,0,1); -} - -#endif From 06701a885559f15a3a76766c69bb0acde7987b5e Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 17:26:58 -0700 Subject: [PATCH 22/32] Removed examples/evalTest from examples/CMakeLists --- examples/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8361f4d3..54f40640 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -59,7 +59,6 @@ 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(evalTest) add_subdirectory(limitEval) if(OPENGL_4_3_FOUND) # the paintTest example requires GL functionality not available on OSX From 61b8fb4713a41609381a31d24dff1d6d0a656df3 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 23:00:38 -0700 Subject: [PATCH 23/32] Removed extraneous clipFlag declaration. --- opensubdiv/osd/glslPatchBoundary.glsl | 1 - 1 file changed, 1 deletion(-) diff --git a/opensubdiv/osd/glslPatchBoundary.glsl b/opensubdiv/osd/glslPatchBoundary.glsl index 0e28227a..039b269f 100644 --- a/opensubdiv/osd/glslPatchBoundary.glsl +++ b/opensubdiv/osd/glslPatchBoundary.glsl @@ -165,7 +165,6 @@ layout(equal_spacing) in; in block { ControlVertex v; - int clipFlag; } inpt[]; out block { From 38c951a06cef93b28095bcfcb541a97a946a0cf5 Mon Sep 17 00:00:00 2001 From: David G Yu Date: Mon, 10 Jun 2013 23:33:34 -0700 Subject: [PATCH 24/32] Fixed patch color override for uniform subdivision --- examples/glViewer/viewer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/glViewer/viewer.cpp b/examples/glViewer/viewer.cpp index 9d276bce..99fd3937 100644 --- a/examples/glViewer/viewer.cpp +++ b/examples/glViewer/viewer.cpp @@ -1269,7 +1269,7 @@ display() { GLuint diffuseColor = glGetUniformLocation(program, "diffuseColor"); - if (g_displayPatchColor) { + if (g_displayPatchColor and primType == GL_PATCHES) { float const * color = getAdaptivePatchColor( desc ); glProgramUniform4f(program, diffuseColor, color[0], color[1], color[2], color[3]); } else { @@ -1670,7 +1670,7 @@ initHUD() } for (int i = 0; i < (int)g_defaultShapes.size(); ++i) { - g_hud.AddRadioButton(4, g_defaultShapes[i].name.c_str(), i==0, -220, 10+i*16, callbackModel, i, 'n'); + g_hud.AddRadioButton(4, g_defaultShapes[i].name.c_str(), i==g_currentShape, -220, 10+i*16, callbackModel, i, 'n'); } } From fab0527f91179ed1b839fe7cf12dbb7b2fda6d3c Mon Sep 17 00:00:00 2001 From: manuelk Date: Tue, 11 Jun 2013 15:59:43 -0700 Subject: [PATCH 25/32] minor FarPatchTables::PatchMap code refactor : - replace use of std::multimap with an std::sort - refactor some methods into PatchParam --- opensubdiv/far/patchParam.h | 22 +++-- opensubdiv/far/patchTables.h | 102 +++++++++++++--------- opensubdiv/far/patchTablesFactory.h | 16 +++- opensubdiv/osd/cpuEvalLimitController.cpp | 11 +-- 4 files changed, 99 insertions(+), 52 deletions(-) diff --git a/opensubdiv/far/patchParam.h b/opensubdiv/far/patchParam.h index e1ee7098..f0bd338c 100644 --- a/opensubdiv/far/patchParam.h +++ b/opensubdiv/far/patchParam.h @@ -119,6 +119,10 @@ struct FarPatchParam { /// True if the parent coarse face is a non-quad bool NonQuadRoot() const { return (field >> 4) & 0x1; } + + /// Returns the fratcion of normalized parametric space covered by the + /// sub-patch. + float GetParamFraction() const; /// Returns the level of subdivision of the patch unsigned char GetDepth() const { return (field & 0xf); } @@ -171,18 +175,22 @@ struct FarPatchParam { void Clear() { faceIndex = 0; bitField.Clear(); - } + } }; +inline float +FarPatchParam::BitField::GetParamFraction( ) const { + if (NonQuadRoot()) { + return 1.0f / float( 1 << (GetDepth()-1) ); + } else { + return 1.0f / float( 1 << GetDepth() ); + } +} + inline bool FarPatchParam::BitField::Normalize( float & u, float & v ) const { - float frac; - if (NonQuadRoot()) { - frac = 1.0f / float( 1 << (GetDepth()-1) ); - } else { - frac = 1.0f / float( 1 << GetDepth() ); - } + float frac = GetParamFraction(); // Are the coordinates within the parametric space covered by the patch ? float pu = (float)GetU()*frac; diff --git a/opensubdiv/far/patchTables.h b/opensubdiv/far/patchTables.h index b3677fe8..b19107a2 100644 --- a/opensubdiv/far/patchTables.h +++ b/opensubdiv/far/patchTables.h @@ -64,6 +64,7 @@ #include #include +#include #include #include @@ -370,7 +371,20 @@ public: bool GetChildPatchesHandles( int faceid, int * npatches, PatchHandle const ** patches ) const; private: - typedef std::multimap MultiMap; + + // private struct used to build the map + struct HandleKey { + + unsigned int faceid; + float u, v; + PatchHandle handle; + + bool operator < (HandleKey const &other) const { + if (faceid < other.faceid) + return true; + return false; + } + }; // Patch handle allowing location of individual patch data inside patch // arrays or in serialized form @@ -618,8 +632,8 @@ FarPatchTables::PatchMap::PatchMap( FarPatchTables const & patchTables ) { // Create a PatchHandle for each patch in the primitive - int npatches = (int)patchTables.GetNumPatches(); - _handles.reserve(npatches); + int npatches = (int)patchTables.GetNumPatches(), + nfaces = 0; FarPatchTables::PatchArrayVector const & patchArrays = patchTables.GetPatchArrayVector(); @@ -628,50 +642,61 @@ FarPatchTables::PatchMap::PatchMap( FarPatchTables const & patchTables ) { patchTables.GetPatchParamTable(); assert( not paramTable.empty() ); - int nfaces =0; - MultiMap mmap; + // iterate over PatchArrayVector and store handles & patches in a temporary vector + std::vector keys(npatches); - for (int arrayid = 0; arrayid < (int)patchArrays.size(); ++arrayid) { + for (int arrayid=0, current=0; arrayid<(int)patchArrays.size(); ++arrayid) { FarPatchTables::PatchArray const & pa = patchArrays[arrayid]; - int ringsize = pa.GetDescriptor().GetNumControlVertices(); + int ringsize = pa.GetDescriptor().GetNumControlVertices(); + + for (unsigned int j=0; j < pa.GetNumPatches(); ++j) { - for (unsigned int j=0; j < pa.GetNumPatches(); ++j) { + FarPatchParam const & param = paramTable[pa.GetPatchIndex()+j]; - int faceId = paramTable[pa.GetPatchIndex()+j].faceIndex; - - PatchHandle handle = { arrayid, j*ringsize, (unsigned int)mmap.size() }; - - mmap.insert( std::pair(faceId, handle)); + HandleKey & key = keys[current]; + + int faceId = param.faceIndex; + + key.faceid = faceId; + key.handle.array = arrayid; + key.handle.vertexOffset = j*ringsize; + key.handle.serialIndex = (unsigned int)current; nfaces = std::max(nfaces, faceId); + + ++current; } } ++nfaces; + + // and sort each patch by face & parameter + std::sort(keys.begin(), keys.end()); - _handles.resize( mmap.size() ); + // copy the serialized array into our final vector + _handles.resize( npatches ); + _offsets.reserve( nfaces ); _offsets.push_back(0); - - // Serialize the multi-map - - unsigned int handlesIdx = 0, faceId=mmap.begin()->first; - - for (MultiMap::const_iterator it=mmap.begin(); it!=mmap.end(); ++it, ++handlesIdx) { - - assert(it->first >= faceId); - - if (it->first != faceId) { - - faceId = it->first; + + unsigned int faceid=keys[0].faceid; + + for (int i=0; i < npatches; ++i) { + + HandleKey const & key = keys[i]; + + assert( key.faceid >= faceid ); + + if (key.faceid!=faceid) { + faceid = key.faceid; // position the offset marker to the new face - _offsets.push_back( handlesIdx ); + _offsets.push_back(i); } // copy the patch id into the table - _handles[handlesIdx] = it->second; + _handles[i] = key.handle; } } @@ -682,10 +707,14 @@ FarPatchTables::PatchMap::GetChildPatchesHandles( int faceid, int * npatches, Pa if (_handles.empty() or _offsets.empty() or (faceid>=(int)_offsets.size())) return false; - *npatches = (faceid==(int)_offsets.size()-1 ? - (unsigned int)_handles.size()-1 : _offsets[faceid+1]) - _offsets[faceid] + 1; - - *patches = &_handles[ _offsets[faceid] ]; + if (npatches) { + *npatches = (faceid==(int)_offsets.size()-1 ? + (unsigned int)_handles.size()-1 : _offsets[faceid+1]) - _offsets[faceid]+1; + } + + if (patches) { + *patches = &_handles[ _offsets[faceid] ]; + } return true; } @@ -752,13 +781,8 @@ FarPatchTables::findPatchArray( FarPatchTables::Descriptor desc ) { // Returns the total number of patches stored in the tables inline int FarPatchTables::GetNumPatches() const { - - int result=0; - for (int i=0; i<(int)_patchArrays.size(); ++i) { - result += _patchArrays[i].GetNumPatches(); - } - - return result; + // there is one PatchParam record for each patch in the mesh + return (int)GetPatchParamTable().size(); } // Returns the total number of control vertex indices in the tables diff --git a/opensubdiv/far/patchTablesFactory.h b/opensubdiv/far/patchTablesFactory.h index 720c989c..c5d78eb3 100644 --- a/opensubdiv/far/patchTablesFactory.h +++ b/opensubdiv/far/patchTablesFactory.h @@ -156,6 +156,9 @@ private: // The number of patch arrays in the mesh int getNumPatchArrays() const; + + // The number of patches in the mesh + static int getNumPatches( FarPatchTables::PatchArrayVector const & parrays ); // Reserves tables based on the contents of the PatchArrayVector static void allocateTables( FarPatchTables * tables, int fvarwidth ); @@ -254,7 +257,7 @@ template void FarPatchTablesFactory::allocateTables( FarPatchTables * tables, int fvarwidth ) { int nverts = tables->GetNumControlVertices(), - npatches = tables->GetNumPatches(); + npatches = getNumPatches(tables->GetPatchArrayVector()); if (nverts==0 or npatches==0) return; @@ -637,6 +640,17 @@ FarPatchTablesFactory::getNumPatchArrays() const { return result; } +template int +FarPatchTablesFactory::getNumPatches( FarPatchTables::PatchArrayVector const & parrays ) { + + int result=0; + for (int i=0; i<(int)parrays.size(); ++i) { + result += parrays[i].GetNumPatches(); + } + + return result; +} + template void FarPatchTablesFactory::pushPatchArray( FarPatchTables::Descriptor desc, FarPatchTables::PatchArrayVector & parray, diff --git a/opensubdiv/osd/cpuEvalLimitController.cpp b/opensubdiv/osd/cpuEvalLimitController.cpp index 900d5207..b2d7f293 100644 --- a/opensubdiv/osd/cpuEvalLimitController.cpp +++ b/opensubdiv/osd/cpuEvalLimitController.cpp @@ -81,13 +81,14 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c return 0; OsdCpuEvalLimitContext::EvalData const & data = context->GetVertexData(); - + for (int i=0; iGetPatchArrayVector().size() ); FarPatchParam::BitField bits = context->GetPatchBitFields()[ handle.serialIndex ]; - assert( handle.array < context->GetPatchArrayVector().size() ); + float u=coords.u, v=coords.v; @@ -192,9 +193,9 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c } // Note : currently we only support bilinear boundary interpolation rules - // for face-varying data. Although Hbr supports 3 addition smooth rule sets, - // the feature-adaptive patch interpolation code currently does not support - // them, and neither does this EvalContext + // for face-varying data. Although Hbr supports 3 additional smooth rule + // sets, the feature-adaptive patch interpolation code currently does not + // support them, and neither does this EvalContext. OsdCpuEvalLimitContext::EvalData const & faceVaryingData = context->GetFaceVaryingData(); if (faceVaryingData.GetOutputData()) { From 642bb27d689a11791e1f40d3b4cbd36d94be3b1a Mon Sep 17 00:00:00 2001 From: manuelk Date: Tue, 11 Jun 2013 17:25:54 -0700 Subject: [PATCH 26/32] fix FarPatchParm : adding version.h include --- opensubdiv/far/patchParam.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opensubdiv/far/patchParam.h b/opensubdiv/far/patchParam.h index f0bd338c..8098b94f 100644 --- a/opensubdiv/far/patchParam.h +++ b/opensubdiv/far/patchParam.h @@ -58,6 +58,8 @@ #ifndef FAR_PATCH_PARAM_H #define FAR_PATCH_PARAM_H +#include "../version.h" + #include namespace OpenSubdiv { From 54bef92aab003d036a98c233ff5785dd67b507d0 Mon Sep 17 00:00:00 2001 From: manuelk Date: Thu, 13 Jun 2013 13:58:23 -0700 Subject: [PATCH 27/32] switch cpuEvalLimitController to use a quad-tree based patch access map : - remove PatchMap from FarPatchTables - add a new FarPatchMap quad-tree class (constructed from FarPatchTables) - refactor the EvalLimitController to use the quad-tree search instead of a serial loop access fixes #174 --- examples/limitEval/main.cpp | 8 +- opensubdiv/far/CMakeLists.txt | 1 + opensubdiv/far/patchMap.h | 366 ++++++++++++++++++++++ opensubdiv/far/patchParam.h | 21 +- opensubdiv/far/patchTables.h | 149 --------- opensubdiv/osd/cpuEvalLimitContext.cpp | 5 +- opensubdiv/osd/cpuEvalLimitContext.h | 10 +- opensubdiv/osd/cpuEvalLimitController.cpp | 256 +++++++-------- 8 files changed, 505 insertions(+), 311 deletions(-) create mode 100644 opensubdiv/far/patchMap.h diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 090c8ef8..f03b50b2 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -468,7 +468,7 @@ updateGeom() { if (n) { // point colors switch (g_drawMode) { - case kUV : { float * color = g_Q->BindCpuBuffer() + i * 6 + 3; + case kUV : { float * color = g_Q->BindCpuBuffer() + i*g_Q->GetNumElements() + 3; color[0] = g_coords[i].u; color[1] = 0.0f; color[2] = g_coords[i].v; } break; @@ -483,6 +483,10 @@ updateGeom() { #pragma omp atomic #endif g_nsamplesFound += n; + } else { + // "hide" unfound samples (hole tags...) as a black dot at the origin + float * sample = g_Q->BindCpuBuffer() + i*g_Q->GetNumElements(); + memset(sample, 0, g_Q->GetNumElements() * sizeof(float)); } } @@ -791,7 +795,7 @@ drawSamples() { glBindVertexArray(g_samplesVAO); glPointSize(1.0f); - glDrawArrays( GL_POINTS, 0, g_nsamplesFound); + glDrawArrays( GL_POINTS, 0, (int)g_coords.size()); glPointSize(1.0f); glBindVertexArray(0); diff --git a/opensubdiv/far/CMakeLists.txt b/opensubdiv/far/CMakeLists.txt index 9b1bbb6b..af8e1f67 100644 --- a/opensubdiv/far/CMakeLists.txt +++ b/opensubdiv/far/CMakeLists.txt @@ -69,6 +69,7 @@ set(PUBLIC_HEADER_FILES mesh.h multiMeshFactory.h patchParam.h + patchMap.h patchTables.h patchTablesFactory.h subdivisionTables.h diff --git a/opensubdiv/far/patchMap.h b/opensubdiv/far/patchMap.h new file mode 100644 index 00000000..9578d355 --- /dev/null +++ b/opensubdiv/far/patchMap.h @@ -0,0 +1,366 @@ +// +// Copyright (C) Pixar. All rights reserved. +// +// This license governs use of the accompanying software. If you +// use the software, you accept this license. If you do not accept +// the license, do not use the software. +// +// 1. Definitions +// The terms "reproduce," "reproduction," "derivative works," and +// "distribution" have the same meaning here as under U.S. +// copyright law. A "contribution" is the original software, or +// any additions or changes to the software. +// A "contributor" is any person or entity that distributes its +// contribution under this license. +// "Licensed patents" are a contributor's patent claims that read +// directly on its contribution. +// +// 2. Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, +// including the license conditions and limitations in section 3, +// each contributor grants you a non-exclusive, worldwide, +// royalty-free copyright license to reproduce its contribution, +// prepare derivative works of its contribution, and distribute +// its contribution or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, +// including the license conditions and limitations in section 3, +// each contributor grants you a non-exclusive, worldwide, +// royalty-free license under its licensed patents to make, have +// made, use, sell, offer for sale, import, and/or otherwise +// dispose of its contribution in the software or derivative works +// of the contribution in the software. +// +// 3. Conditions and Limitations +// (A) No Trademark License- This license does not grant you +// rights to use any contributor's name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over +// patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends +// automatically. +// (C) If you distribute any portion of the software, you must +// retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source +// code form, you may do so only under this license by including a +// complete copy of this license with your distribution. If you +// distribute any portion of the software in compiled or object +// code form, you may only do so under a license that complies +// with this license. +// (E) The software is licensed "as-is." You bear the risk of +// using it. The contributors give no express warranties, +// guarantees or conditions. You may have additional consumer +// rights under your local laws which this license cannot change. +// To the extent permitted under your local laws, the contributors +// exclude the implied warranties of merchantability, fitness for +// a particular purpose and non-infringement. +// + +#ifndef FAR_PATCH_MAP_H +#define FAR_PATCH_MAP_H + +#include "../version.h" + +#include "../far/patchTables.h" + +#include + +namespace OpenSubdiv { +namespace OPENSUBDIV_VERSION { + +/// \brief An quadtree-based map connecting coarse faces to their sub-patches +/// +/// FarPatchTables::PatchArrays contain lists of patches that represent the limit +/// surface of a mesh, sorted by their topological type. These arrays break the +/// connection between coarse faces and their sub-patches. +/// +/// The PatchMap provides a quad-tree based lookup structure that, given a singular +/// parametric location, can efficiently return a handle to the sub-patch that +/// contains this location. +/// +class FarPatchMap { +public: + + /// Handle that can be used as unique patch identifier within FarPatchTables + struct Handle { + unsigned int patchArrayIdx, // OsdPatchArray containing the patch + patchIdx, // Absolute index of the patch + vertexOffset; // Offset to the first CV of the patch + }; + + /// Constructor + /// + /// @param patchTables A valid set of FarPatchTables + /// + FarPatchMap( FarPatchTables const & patchTables ); + + /// Returns a handle to the sub-patch of the face at the given (u,v). + /// Note : the faceid corresponds to quadrangulated face indices (ie. quads + /// count as 1 index, non-quads add as many indices as they have vertices) + /// + /// @param faceid The index of the face + /// + /// @param u Local u parameter + /// + /// @param v Local v parameter + /// + /// @return A patch handle or NULL if the face does not exist or the + /// limit surface is tagged as a hole at the given location + /// + Handle const * FindPatch( int faceid, float u, float v ) const; + +private: + void initialize( FarPatchTables const & patchTables ); + + // Quadtree node with 4 children + struct QuadNode { + struct Child { + unsigned int isSet:1, // true if the child has been set + isLeaf:1, // true if the child is a QuadNode + idx:30; // child index (either QuadNode or Handle) + }; + + // sets all the children to point to the patch of index patchIdx + void SetChild(int patchIdx); + + // sets the child in "quadrant" to point to the node or patch of the given index + void SetChild(unsigned char quadrant, int child, bool isLeaf=true); + + Child children[4]; + }; + + typedef std::vector QuadTree; + + // adds a child to a parent node and pushes it back on the tree + static QuadNode * addChild( QuadTree & quadtree, QuadNode * parent, int quadrant ); + + // given a median, transforms the (u,v) to the quadrant they point to, and + // return the quadrant index. + // + // Quadrants indexing: + // + // (0,0) o-----o-----o + // | | | + // | 0 | 3 | + // | | | + // o-----o-----o + // | | | + // | 1 | 2 | + // | | | + // o-----o-----o (1,1) + // + template static int resolveQuadrant(T & median, T & u, T & v); + + std::vector _handles; // all the patches in the FarPatchTable + std::vector _quadtree; // quadtree nodes +}; + +// Constructor +inline +FarPatchMap::FarPatchMap( FarPatchTables const & patchTables ) { + initialize( patchTables ); +} + +// sets all the children to point to the patch of index patchIdx +inline void +FarPatchMap::QuadNode::SetChild(int patchIdx) { + for (int i=0; i<4; ++i) { + children[i].isSet=true; + children[i].isLeaf=true; + children[i].idx=patchIdx; + } +} + +// sets the child in "quadrant" to point to the node or patch of the given index +inline void +FarPatchMap::QuadNode::SetChild(unsigned char quadrant, int idx, bool isLeaf) { + assert(quadrant<4); + children[quadrant].isSet = true; + children[quadrant].isLeaf = isLeaf; + children[quadrant].idx = idx; +} + +// adds a child to a parent node and pushes it back on the tree +inline FarPatchMap::QuadNode * +FarPatchMap::addChild( QuadTree & quadtree, QuadNode * parent, int quadrant ) { + quadtree.push_back(QuadNode()); + int idx = quadtree.size()-1; + parent->SetChild(quadrant, idx, false); + return &(quadtree[idx]); +} + +// given a median, transforms the (u,v) to the quadrant they point to, and +// return the quadrant index. +template int +FarPatchMap::resolveQuadrant(T & median, T & u, T & v) { + int quadrant = -1; + + if (u(int)_quadtree.size()) + return NULL; + + assert( (u>=0.0f) and (u<=1.0f) and (v>=0.0f) and (v<=1.0f) ); + + QuadNode const * node = &_quadtree[faceid]; + + float half = 0.5f; + + // 0xFF : we should never have depths greater than k_InfinitelySharp + for (int depth=0; depth<0xFF; ++depth) { + + float delta = half * 0.5f; + + int quadrant = resolveQuadrant( half, u, v ); + assert(quadrant>=0); + + // is the quadrant a hole ? + if (not node->children[quadrant].isSet) + return 0; + + if (node->children[quadrant].isLeaf) { + return &_handles[node->children[quadrant].idx]; + } else { + node = &_quadtree[node->children[quadrant].idx]; + } + + half = delta; + } + + assert(0); + return 0; +} + +// Constructor +inline void +FarPatchMap::initialize( FarPatchTables const & patchTables ) { + + int nfaces = 0, npatches = (int)patchTables.GetNumPatches(); + + if (not npatches) + return; + + FarPatchTables::PatchArrayVector const & patchArrays = + patchTables.GetPatchArrayVector(); + + FarPatchTables::PatchParamTable const & paramTable = + patchTables.GetPatchParamTable(); + + // populate subpatch handles vector + _handles.resize(npatches); + for (int arrayIdx=0, current=0; arrayIdx<(int)patchArrays.size(); ++arrayIdx) { + + FarPatchTables::PatchArray const & parray = patchArrays[arrayIdx]; + + int ringsize = parray.GetDescriptor().GetNumControlVertices(); + + for (unsigned int j=0; j < parray.GetNumPatches(); ++j) { + + FarPatchParam const & param = paramTable[parray.GetPatchIndex()+j]; + + Handle & h = _handles[current]; + + h.patchArrayIdx = arrayIdx; + h.patchIdx = (unsigned int)current; + h.vertexOffset = j * ringsize; + + nfaces = std::max(nfaces, (int)param.faceIndex); + + ++current; + } + } + ++nfaces; + + // temporary vector to hold the quadtree while under construction + std::vector quadtree; + + // reserve memory for the octree nodes (size is a worse-case approximation) + quadtree.reserve( nfaces + npatches ); + + // each coarse face has a root node associated to it that we need to initialize + quadtree.resize(nfaces); + + // populate the quadtree from the FarPatchArrays sub-patches + for (int i=0, handleIdx=0; i<(int)patchArrays.size(); ++i) { + + FarPatchTables::PatchArray const & parray = patchArrays[i]; + + for (unsigned int j=0; j < parray.GetNumPatches(); ++j, ++handleIdx) { + + FarPatchParam const & param = paramTable[parray.GetPatchIndex()+j]; + + FarPatchParam::BitField bits = param.bitField; + + unsigned char depth = bits.GetDepth(); + + QuadNode * node = &quadtree[ param.faceIndex ]; + + if (depth==0) { + // special case : regular BSpline face w/ no sub-patches + node->SetChild( handleIdx ); + continue; + } + + short u = bits.GetU(), + v = bits.GetV(), + pdepth = bits.NonQuadRoot() ? depth-2 : depth-1, + half = 1 << pdepth; + + for (unsigned char k=0; k> 1; + + int quadrant = resolveQuadrant(half, u, v); + assert(quadrant>=0); + + half = delta; + + if (k==pdepth) { + // we have reached the depth of the sub-patch : add a leaf + assert( not node->children[quadrant].isSet ); + node->SetChild(quadrant, handleIdx, true); + break; + } else { + // travel down the child node of the corresponding quadrant + if (not node->children[quadrant].isSet) { + // create a new branch in the quadrant + node = addChild(quadtree, node, quadrant); + } else { + // travel down an existing branch + node = &(quadtree[ node->children[quadrant].idx ]); + } + } + } + } + } + + // copy the resulting quadtree to eliminate un-unused vector capacity + _quadtree = quadtree; +} + +} // end namespace OPENSUBDIV_VERSION +using namespace OPENSUBDIV_VERSION; + +} // end namespace OpenSubdiv + +#endif /* FAR_PATCH_PARAM */ diff --git a/opensubdiv/far/patchParam.h b/opensubdiv/far/patchParam.h index f0bd338c..dfac0194 100644 --- a/opensubdiv/far/patchParam.h +++ b/opensubdiv/far/patchParam.h @@ -127,19 +127,13 @@ struct FarPatchParam { /// Returns the level of subdivision of the patch unsigned char GetDepth() const { return (field & 0xf); } - /// If the (u,v) pair is within the parameteric space of the sub-patch - /// described by the bitfield, then (u,v) is normalized to this sub- - /// parametric space. If the (u,v) pair was outside of the parametric - /// range, then it is unchanged and false is returned. + /// The (u,v) pair is normalized to this sub-parametric space. /// /// @param u u parameter /// /// @param v v parameter /// - /// @return true if the given (u,v) pair was within the sub-patch parametric - /// space, false if the pair was outside the sub-patch range. - /// - bool Normalize( float & u, float & v ) const; + void Normalize( float & u, float & v ) const; /// Rotate (u,v) pair to compensate for transition pattern and boundary /// orientations. @@ -187,25 +181,18 @@ FarPatchParam::BitField::GetParamFraction( ) const { } } -inline bool +inline void FarPatchParam::BitField::Normalize( float & u, float & v ) const { float frac = GetParamFraction(); - // Are the coordinates within the parametric space covered by the patch ? + // top left corner float pu = (float)GetU()*frac; - if ( u(pu+frac) ) - return false; - float pv = (float)GetV()*frac; - if ( v(pv+frac) ) - return false; // normalize u,v coordinates u = (u - pu) / frac, v = (v - pv) / frac; - - return true; } inline void diff --git a/opensubdiv/far/patchTables.h b/opensubdiv/far/patchTables.h index b19107a2..0b2c123e 100644 --- a/opensubdiv/far/patchTables.h +++ b/opensubdiv/far/patchTables.h @@ -338,62 +338,6 @@ public: typedef std::vector PatchArrayVector; - - /// Unique patch identifier within a PatchArrayVector - struct PatchHandle { - - unsigned int array, // OsdPatchArray containing the patch - vertexOffset, // Offset to the first CV of the patch - serialIndex; // Serialized Index of the patch - }; - - - /// \brief Maps sub-patches to coarse faces - class PatchMap { - - public: - // Constructor - PatchMap( FarPatchTables const & patchTables ); - - /// \brief Returns the number and list of patch indices for a given face. - /// - /// PatchMaps map coarse faces to their childrn feature adaptive patches. - /// Coarse faces are indexed using their ptex face ID to resolve parametric - /// ambiguity on non-quad faces. Note : this "map" is actually a vector, so - /// queries are O(1) order. - /// - /// @param faceid the face index to search for - /// - /// @param npatches the number of children patches found for the faceid - /// - /// @param patches a set of pointers to the individual patch handles - /// - bool GetChildPatchesHandles( int faceid, int * npatches, PatchHandle const ** patches ) const; - - private: - - // private struct used to build the map - struct HandleKey { - - unsigned int faceid; - float u, v; - PatchHandle handle; - - bool operator < (HandleKey const &other) const { - if (faceid < other.faceid) - return true; - return false; - } - }; - - // Patch handle allowing location of individual patch data inside patch - // arrays or in serialized form - std::vector _handles; - - // offset to the first handle of the child patches for each coarse face - std::vector _offsets; - }; - /// Constructor /// /// @param patchArrays Vector of descriptors and ranges for arrays of patches @@ -626,99 +570,6 @@ FarPatchTables::Descriptor::operator ++ () { return *this; } -// Constructor -inline -FarPatchTables::PatchMap::PatchMap( FarPatchTables const & patchTables ) { - - // Create a PatchHandle for each patch in the primitive - - int npatches = (int)patchTables.GetNumPatches(), - nfaces = 0; - - FarPatchTables::PatchArrayVector const & patchArrays = - patchTables.GetPatchArrayVector(); - - FarPatchTables::PatchParamTable const & paramTable = - patchTables.GetPatchParamTable(); - assert( not paramTable.empty() ); - - // iterate over PatchArrayVector and store handles & patches in a temporary vector - std::vector keys(npatches); - - for (int arrayid=0, current=0; arrayid<(int)patchArrays.size(); ++arrayid) { - - FarPatchTables::PatchArray const & pa = patchArrays[arrayid]; - - int ringsize = pa.GetDescriptor().GetNumControlVertices(); - - for (unsigned int j=0; j < pa.GetNumPatches(); ++j) { - - FarPatchParam const & param = paramTable[pa.GetPatchIndex()+j]; - - HandleKey & key = keys[current]; - - int faceId = param.faceIndex; - - key.faceid = faceId; - key.handle.array = arrayid; - key.handle.vertexOffset = j*ringsize; - key.handle.serialIndex = (unsigned int)current; - - nfaces = std::max(nfaces, faceId); - - ++current; - } - } - ++nfaces; - - // and sort each patch by face & parameter - std::sort(keys.begin(), keys.end()); - - // copy the serialized array into our final vector - _handles.resize( npatches ); - - _offsets.reserve( nfaces ); - _offsets.push_back(0); - - unsigned int faceid=keys[0].faceid; - - for (int i=0; i < npatches; ++i) { - - HandleKey const & key = keys[i]; - - assert( key.faceid >= faceid ); - - if (key.faceid!=faceid) { - faceid = key.faceid; - - // position the offset marker to the new face - _offsets.push_back(i); - } - - // copy the patch id into the table - _handles[i] = key.handle; - } -} - -// Returns the number and list of patch indices for a given face. -inline bool -FarPatchTables::PatchMap::GetChildPatchesHandles( int faceid, int * npatches, PatchHandle const ** patches ) const { - - if (_handles.empty() or _offsets.empty() or (faceid>=(int)_offsets.size())) - return false; - - if (npatches) { - *npatches = (faceid==(int)_offsets.size()-1 ? - (unsigned int)_handles.size()-1 : _offsets[faceid+1]) - _offsets[faceid]+1; - } - - if (patches) { - *patches = &_handles[ _offsets[faceid] ]; - } - - return true; -} - // Returns a pointer to the vertex indices of uniformly subdivided faces inline unsigned int const * FarPatchTables::GetFaceVertices(int level) const { diff --git a/opensubdiv/osd/cpuEvalLimitContext.cpp b/opensubdiv/osd/cpuEvalLimitContext.cpp index bd5822bb..fb01cb79 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.cpp +++ b/opensubdiv/osd/cpuEvalLimitContext.cpp @@ -150,14 +150,15 @@ OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmes } } + // Copy the face-varying table if necessary if (requireFVarData) { _fvarwidth = farmesh->GetTotalFVarWidth(); if (_fvarwidth>0) { _fvarData = patchTables->GetFVarDataTable(); } } - - _patchMap = new FarPatchTables::PatchMap( *patchTables ); + + _patchMap = new FarPatchMap( *patchTables ); } OsdCpuEvalLimitContext::~OsdCpuEvalLimitContext() { diff --git a/opensubdiv/osd/cpuEvalLimitContext.h b/opensubdiv/osd/cpuEvalLimitContext.h index c71eff00..f740ebdb 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.h +++ b/opensubdiv/osd/cpuEvalLimitContext.h @@ -62,6 +62,7 @@ #include "../osd/evalLimitContext.h" #include "../osd/vertexDescriptor.h" #include "../far/patchTables.h" +#include "../far/patchMap.h" #include #include @@ -84,7 +85,6 @@ public: static OsdCpuEvalLimitContext * Create(FarMesh const * farmesh, bool requireFVarData=false); - /// Destructor virtual ~OsdCpuEvalLimitContext(); /// Limit evaluation data descriptor @@ -301,9 +301,9 @@ public: return _fvarwidth; } - /// Returns a map object that can connect a faceId to a list of children patches - const FarPatchTables::PatchMap * GetPatchesMap() const { - return _patchMap; + /// Returns a map that can connect a faceId to a list of children patches + FarPatchMap const & GetPatchMap() const { + return *_patchMap; } /// Returns the highest valence of the vertices in the buffers @@ -326,7 +326,7 @@ private: FarPatchTables::FVarDataTable _fvarData; - FarPatchTables::PatchMap * _patchMap; // map of the sub-patches given a face index + FarPatchMap * _patchMap; // map of the sub-patches given a face index EvalVertexData _vertexData; // vertex-interpolated data descriptor EvalData _varyingData, // varying-interpolated data descriptor diff --git a/opensubdiv/osd/cpuEvalLimitController.cpp b/opensubdiv/osd/cpuEvalLimitController.cpp index b2d7f293..1f349bd6 100644 --- a/opensubdiv/osd/cpuEvalLimitController.cpp +++ b/opensubdiv/osd/cpuEvalLimitController.cpp @@ -72,153 +72,137 @@ int OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & coords, OsdCpuEvalLimitContext const *context, unsigned int index ) { - - int npatches=0; - FarPatchTables::PatchHandle const * patchHandles; - - // Get the list of all children patches of the face described in coords - if (not context->GetPatchesMap()->GetChildPatchesHandles(coords.face, &npatches, &patchHandles)) + float u=coords.u, + v=coords.v; + + FarPatchMap::Handle const * handle = context->GetPatchMap().FindPatch( coords.face, u, v ); + + // the map may not be able to return a handle if there is a hole or the face + // index is incorrect + if (not handle) return 0; + + FarPatchParam::BitField bits = context->GetPatchBitFields()[ handle->patchIdx ]; - OsdCpuEvalLimitContext::EvalData const & data = context->GetVertexData(); + bits.Normalize( u, v ); - for (int i=0; iGetPatchArrayVector()[ handle->patchArrayIdx ]; - FarPatchTables::PatchHandle const & handle = patchHandles[i]; - assert( handle.array < context->GetPatchArrayVector().size() ); + unsigned int const * cvs = &context->GetControlVertices()[ parray.GetVertIndex() + handle->vertexOffset ]; + + OsdCpuEvalLimitContext::EvalVertexData const & vertexData = context->GetVertexData(); - FarPatchParam::BitField bits = context->GetPatchBitFields()[ handle.serialIndex ]; + // Position lookup pointers at the indexed vertex + float const * inQ = vertexData.GetInputData(); + float * outQ = const_cast(vertexData.GetOutputData(index)); + float * outdQu = const_cast(vertexData.GetOutputDU(index)); + float * outdQv = const_cast(vertexData.GetOutputDV(index)); + + // Based on patch type - go execute interpolation + switch( parray.GetDescriptor().GetType() ) { + + case FarPatchTables::REGULAR : if (vertexData.IsBound()) { + evalBSpline( v, u, cvs, + vertexData.GetInputDesc(), + inQ, + vertexData.GetOutputDesc(), + outQ, outdQu, outdQv ); + } break; + + case FarPatchTables::BOUNDARY : if (vertexData.IsBound()) { + evalBoundary( v, u, cvs, + vertexData.GetInputDesc(), + inQ, + vertexData.GetOutputDesc(), + outQ, outdQu, outdQv ); + } break; + + case FarPatchTables::CORNER : if (vertexData.IsBound()) { + evalCorner( v, u, cvs, + vertexData.GetInputDesc(), + inQ, + vertexData.GetOutputDesc(), + outQ, outdQu, outdQv); + } break; - float u=coords.u, - v=coords.v; - - // check if the patch contains the point - if (not bits.Normalize(u,v)) - continue; + case FarPatchTables::GREGORY : if (vertexData.IsBound()) { + evalGregory( v, u, cvs, + context->GetVertexValenceBuffer(), + context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle->vertexOffset, + context->GetMaxValence(), + vertexData.GetInputDesc(), + inQ, + vertexData.GetOutputDesc(), + outQ, outdQu, outdQv); + } break; - assert( (u>=0.0f) and (u<=1.0f) and (v>=0.0f) and (v<=1.0f) ); + case FarPatchTables::GREGORY_BOUNDARY : + if (vertexData.IsBound()) { + evalGregoryBoundary(v, u, cvs, + context->GetVertexValenceBuffer(), + context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle->vertexOffset, + context->GetMaxValence(), + vertexData.GetInputDesc(), + inQ, + vertexData.GetOutputDesc(), + outQ, outdQu, outdQv); + } break; - bits.Rotate(u, v); - - FarPatchTables::PatchArray const & parray = context->GetPatchArrayVector()[ handle.array ]; - - unsigned int const * cvs = &context->GetControlVertices()[ parray.GetVertIndex() + handle.vertexOffset ]; - - OsdCpuEvalLimitContext::EvalVertexData const & vertexData = context->GetVertexData(); - - // Position lookup pointers at the indexed vertex - float const * inQ = vertexData.GetInputData(); - float * outQ = const_cast(vertexData.GetOutputData(index)); - float * outdQu = const_cast(vertexData.GetOutputDU(index)); - float * outdQv = const_cast(vertexData.GetOutputDV(index)); - - // Based on patch type - go execute interpolation - switch( parray.GetDescriptor().GetType() ) { - - case FarPatchTables::REGULAR : if (vertexData.IsBound()) { - evalBSpline( v, u, cvs, - data.GetInputDesc(), - inQ, - data.GetOutputDesc(), - outQ, outdQu, outdQv ); - } break; - - case FarPatchTables::BOUNDARY : if (vertexData.IsBound()) { - evalBoundary( v, u, cvs, - data.GetInputDesc(), - inQ, - data.GetOutputDesc(), - outQ, outdQu, outdQv ); - } break; - - case FarPatchTables::CORNER : if (vertexData.IsBound()) { - evalCorner( v, u, cvs, - data.GetInputDesc(), - inQ, - data.GetOutputDesc(), - outQ, outdQu, outdQv); - } break; - - - case FarPatchTables::GREGORY : if (vertexData.IsBound()) { - evalGregory( v, u, cvs, - context->GetVertexValenceBuffer(), - context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle.vertexOffset, - context->GetMaxValence(), - data.GetInputDesc(), - inQ, - data.GetOutputDesc(), - outQ, outdQu, outdQv); - } break; - - case FarPatchTables::GREGORY_BOUNDARY : - if (vertexData.IsBound()) { - evalGregoryBoundary(v, u, cvs, - context->GetVertexValenceBuffer(), - context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle.vertexOffset, - context->GetMaxValence(), - data.GetInputDesc(), - inQ, - data.GetOutputDesc(), - outQ, outdQu, outdQv); - } break; - - default: - assert(0); - } - - OsdCpuEvalLimitContext::EvalData const & varyingData = context->GetVaryingData(); - if (varyingData.IsBound()) { - - static int indices[5][4] = { {5, 6,10, 9}, // regular - {1, 2, 6, 5}, // boundary - {1, 2, 5, 4}, // corner - {0, 1, 2, 3}, // gregory - {0, 1, 2, 3} };// gregory boundary - - int type = (int)(parray.GetDescriptor().GetType() - FarPatchTables::REGULAR); - - unsigned int zeroRing[4] = { cvs[indices[type][0]], - cvs[indices[type][1]], - cvs[indices[type][2]], - cvs[indices[type][3]] }; - - evalBilinear( v, u, zeroRing, - varyingData.GetInputDesc(), - varyingData.GetInputData(), - varyingData.GetOutputDesc(), - const_cast(varyingData.GetOutputData(index)) ); - - } - - // Note : currently we only support bilinear boundary interpolation rules - // for face-varying data. Although Hbr supports 3 additional smooth rule - // sets, the feature-adaptive patch interpolation code currently does not - // support them, and neither does this EvalContext. - OsdCpuEvalLimitContext::EvalData const & faceVaryingData = context->GetFaceVaryingData(); - if (faceVaryingData.GetOutputData()) { - - FarPatchTables::FVarDataTable const & fvarData = context->GetFVarData(); - - if (not fvarData.empty()) { - - float const * fvar = &fvarData[ handle.serialIndex * 4 * context->GetFVarWidth() ]; - - static unsigned int zeroRing[4] = {0,1,2,3}; - - evalBilinear( v, u, zeroRing, - faceVaryingData.GetInputDesc(), - fvar, - faceVaryingData.GetOutputDesc(), - const_cast(faceVaryingData.GetOutputData(index)) ); - } - } - - return 1; + default: + assert(0); } - return 0; + OsdCpuEvalLimitContext::EvalData const & varyingData = context->GetVaryingData(); + if (varyingData.IsBound()) { + + static int indices[5][4] = { {5, 6,10, 9}, // regular + {1, 2, 6, 5}, // boundary + {1, 2, 5, 4}, // corner + {0, 1, 2, 3}, // gregory + {0, 1, 2, 3} };// gregory boundary + + int type = (int)(parray.GetDescriptor().GetType() - FarPatchTables::REGULAR); + + unsigned int zeroRing[4] = { cvs[indices[type][0]], + cvs[indices[type][1]], + cvs[indices[type][2]], + cvs[indices[type][3]] }; + + evalBilinear( v, u, zeroRing, + varyingData.GetInputDesc(), + varyingData.GetInputData(), + varyingData.GetOutputDesc(), + const_cast(varyingData.GetOutputData(index)) ); + + } + + // Note : currently we only support bilinear boundary interpolation rules + // for face-varying data. Although Hbr supports 3 additional smooth rule + // sets, the feature-adaptive patch interpolation code currently does not + // support them, and neither does this EvalContext. + OsdCpuEvalLimitContext::EvalData const & faceVaryingData = context->GetFaceVaryingData(); + if (faceVaryingData.GetOutputData()) { + + FarPatchTables::FVarDataTable const & fvarData = context->GetFVarData(); + + if (not fvarData.empty()) { + + float const * fvar = &fvarData[ handle->patchIdx * 4 * context->GetFVarWidth() ]; + + static unsigned int zeroRing[4] = {0,1,2,3}; + + evalBilinear( v, u, zeroRing, + faceVaryingData.GetInputDesc(), + fvar, + faceVaryingData.GetOutputDesc(), + const_cast(faceVaryingData.GetOutputData(index)) ); + } + } + + return 1; } } // end namespace OPENSUBDIV_VERSION From cf13a8d7551eda6838c45cb0d3d0f20461cac3f3 Mon Sep 17 00:00:00 2001 From: manuelk Date: Thu, 13 Jun 2013 16:22:59 -0700 Subject: [PATCH 28/32] Add check in shape_utils that detects dicsonnected vertices in a shape mesh and exits with an error message. A more permanent fix will be to handle fully non-manifold topology at the Hbr level, but that is beyond the scope of fixing this problem. fixes #175 --- regression/common/shape_utils.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 40f828f4..15679a85 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -862,6 +862,12 @@ createTopology( shape const * sh, OpenSubdiv::HbrMesh * mesh, Scheme scheme) applyTags( mesh, sh ); mesh->Finish(); + + // check for disconnected vertices + if (mesh->GetNumDisconnectedVertices()) { + printf("The specified subdivmesh contains disconnected surface components.\n"); + exit(1); + } } //------------------------------------------------------------------------------ From 185e55b859757426dcff79b64f3b0b69ab5a3f0a Mon Sep 17 00:00:00 2001 From: David G Yu Date: Fri, 14 Jun 2013 09:54:38 -0700 Subject: [PATCH 29/32] Fixed VS2010 error/warning --- opensubdiv/far/patchMap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensubdiv/far/patchMap.h b/opensubdiv/far/patchMap.h index 9578d355..991da505 100644 --- a/opensubdiv/far/patchMap.h +++ b/opensubdiv/far/patchMap.h @@ -183,7 +183,7 @@ FarPatchMap::QuadNode::SetChild(unsigned char quadrant, int idx, bool isLeaf) { inline FarPatchMap::QuadNode * FarPatchMap::addChild( QuadTree & quadtree, QuadNode * parent, int quadrant ) { quadtree.push_back(QuadNode()); - int idx = quadtree.size()-1; + int idx = (int)quadtree.size()-1; parent->SetChild(quadrant, idx, false); return &(quadtree[idx]); } From 077f95b8f0145753438c0df54a043e957ca8cf6b Mon Sep 17 00:00:00 2001 From: David G Yu Date: Fri, 14 Jun 2013 09:55:55 -0700 Subject: [PATCH 30/32] Fixed a couple bugs/typos in simple_math.h --- examples/common/simple_math.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/common/simple_math.h b/examples/common/simple_math.h index d3afb851..a8bdeab8 100644 --- a/examples/common/simple_math.h +++ b/examples/common/simple_math.h @@ -268,9 +268,9 @@ apply(float *v, const float *m) { float r[4]; r[0] = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12]; - r[1] = v[1] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13]; - r[2] = v[2] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14]; - r[3] = v[3] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[14]; + r[1] = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13]; + r[2] = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14]; + r[3] = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15]; v[0] = r[0]; v[1] = r[1]; v[2] = r[2]; From bbe4435b191a99aacae7a2670912e88c85f1d884 Mon Sep 17 00:00:00 2001 From: manuelk Date: Mon, 17 Jun 2013 18:13:13 -0700 Subject: [PATCH 31/32] minor API refactor of for EvalLimit : - Replaced EvalData and EvalVertexData classes with a simpler DataStream class that only accesses a single data stream, binds and unbinds it - DataStream has both an input and an output version which avoids much of the const-ness const-related ambiguity of the previous design pattern - Vertex, varying and face-varying data now all have a dedicate struct (VertexData, VaryingData, FaceVaryingData) as a way of gathering the various data-streams required to perform sampling - renamd some "Buffers" into "Tables" for better naming consistency with Far --- examples/limitEval/main.cpp | 18 +- opensubdiv/osd/cpuEvalLimitContext.cpp | 68 +++-- opensubdiv/osd/cpuEvalLimitContext.h | 335 ++++++++++++---------- opensubdiv/osd/cpuEvalLimitController.cpp | 144 +++++----- opensubdiv/osd/cpuEvalLimitController.h | 2 +- 5 files changed, 310 insertions(+), 257 deletions(-) diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index f03b50b2..802a802c 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -442,19 +442,19 @@ updateGeom() { // Bind/Unbind of the vertex buffers to the context needs to happen // outside of the parallel loop - g_evalCtx->BindVertexBuffers( g_idesc, g_vertexData, g_odesc, g_Q, g_dQu, g_dQv ); + g_evalCtx->GetVertexData().Bind( g_idesc, g_vertexData, g_odesc, g_Q, g_dQu, g_dQv ); // The varying data ends-up interleaved in the same g_Q output buffer because // g_Q has a stride of 6 and g_vdesc sets the offset to 3, while g_odesc sets // the offset to 0 switch (g_drawMode) { - case kVARYING : g_evalCtx->BindVaryingBuffers( g_idesc, g_varyingData, g_vdesc, g_Q ); break; + case kVARYING : g_evalCtx->GetVaryingData().Bind( g_idesc, g_varyingData, g_vdesc, g_Q ); break; - case kFACEVARYING : g_evalCtx->BindFaceVaryingBuffers( g_fvidesc, g_fvodesc, g_Q ); + case kFACEVARYING : g_evalCtx->GetFaceVaryingData().Bind( g_fvidesc, g_fvodesc, g_Q ); case kUV : - default : g_evalCtx->UnbindVaryingBuffers(); break; + default : g_evalCtx->GetVaryingData().Unbind(); break; } #define USE_OPENMP @@ -490,7 +490,15 @@ updateGeom() { } } - g_evalCtx->UnbindVertexBuffers(); + g_evalCtx->GetVertexData().Unbind(); + + switch (g_drawMode) { + case kVARYING : g_evalCtx->GetVaryingData().Unbind(); break; + + case kFACEVARYING : g_evalCtx->GetFaceVaryingData().Unbind(); break; + + default : break; + } g_Q->BindVBO(); diff --git a/opensubdiv/osd/cpuEvalLimitContext.cpp b/opensubdiv/osd/cpuEvalLimitContext.cpp index fb01cb79..ec85e006 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.cpp +++ b/opensubdiv/osd/cpuEvalLimitContext.cpp @@ -78,39 +78,6 @@ OsdCpuEvalLimitContext::Create(FarMesh const * farmesh, bool requireF return new OsdCpuEvalLimitContext(farmesh, requireFVarData); } -void -OsdCpuEvalLimitContext::EvalData::Unbind() { - - _inDesc.Reset(); - _inQ=0; - - _outDesc.Reset(); - _outQ = 0; -} - -void -OsdCpuEvalLimitContext::EvalVertexData::Unbind() { - - EvalData::Unbind(); - - _outdQu = _outdQv = 0; -} - -void -OsdCpuEvalLimitContext::UnbindVertexBuffers() { - _vertexData.Unbind(); -} - -void -OsdCpuEvalLimitContext::UnbindVaryingBuffers() { - _varyingData.Unbind(); -} - -void -OsdCpuEvalLimitContext::UnbindFaceVaryingBuffers() { - _faceVaryingData.Unbind(); -} - OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmesh, bool requireFVarData) : OsdEvalLimitContext(farmesh) { @@ -122,9 +89,9 @@ OsdCpuEvalLimitContext::OsdCpuEvalLimitContext(FarMesh const * farmes _patchArrays = patchTables->GetPatchArrayVector(); - _vertexValenceBuffer = patchTables->GetVertexValenceTable(); + _vertexValenceTable = patchTables->GetVertexValenceTable(); - _quadOffsetBuffer = patchTables->GetQuadOffsetTable(); + _quadOffsetTable = patchTables->GetQuadOffsetTable(); _maxValence = patchTables->GetMaxValence(); @@ -165,5 +132,36 @@ OsdCpuEvalLimitContext::~OsdCpuEvalLimitContext() { delete _patchMap; } +void +OsdCpuEvalLimitContext::VertexData::Unbind() { + + inDesc.Reset(); + in.Unbind(); + + outDesc.Reset(); + out.Unbind(); + outDu.Unbind(); + outDv.Unbind(); +} + +void +OsdCpuEvalLimitContext::VaryingData::Unbind() { + + inDesc.Reset(); + in.Unbind(); + + outDesc.Reset(); + out.Unbind(); +} + +void +OsdCpuEvalLimitContext::FaceVaryingData::Unbind() { + + inDesc.Reset(); + + outDesc.Reset(); + out.Unbind(); +} + } // end namespace OPENSUBDIV_VERSION } // end namespace OpenSubdiv diff --git a/opensubdiv/osd/cpuEvalLimitContext.h b/opensubdiv/osd/cpuEvalLimitContext.h index f740ebdb..5a113e17 100644 --- a/opensubdiv/osd/cpuEvalLimitContext.h +++ b/opensubdiv/osd/cpuEvalLimitContext.h @@ -87,185 +87,220 @@ public: virtual ~OsdCpuEvalLimitContext(); - /// Limit evaluation data descriptor - class EvalData { + + + /// A container able to bind vertex buffer data as input or output streams. + class DataStream { public: - OsdVertexBufferDescriptor const & GetInputDesc() const { - return _inDesc; + /// Constructor + DataStream() : _data(0) { } + + /// Binds the stream to the context (and moves the data to the appropriate + /// compute device) + /// + /// @param data a valid OsdVertexBuffer + /// + template void Bind( BUFFER * data ) { + _data = data ? data->BindCpuBuffer() : 0; } - float const * GetInputData() const { - return _inQ; - } - - OsdVertexBufferDescriptor const & GetOutputDesc() const { - return _outDesc; - } - - float const * GetOutputData(int index=0) const { - return _outQ + index * _outDesc.stride; - } - - template - void BindInputData( BUFFER * inQ ) { - _inQ = inQ ? inQ->BindCpuBuffer() : 0; - } - - template - void BindOutputData( BUFFER * outQ ) { - _outQ = outQ ? outQ->BindCpuBuffer() : 0; - } - + /// True if the stream has been bound bool IsBound() const { - return _inQ and _outQ; + return (_data!=NULL); } - private: - friend class OsdCpuEvalLimitContext; - - EvalData() : _inQ(0), _outQ(0) { } + /// Unbinds the stream + void Unbind() { + _data=0; + } - OsdVertexBufferDescriptor _inDesc; // input data - float * _inQ; - - OsdVertexBufferDescriptor _outDesc; // output data - float * _outQ; - - /// Resets the descriptors & pointers - void Unbind(); + protected: + float * _data; }; - - /// Limit evaluation data descriptor with derivatives - class EvalVertexData : public EvalData { + + /// \brief Input (const) data stream + class InputDataStream : public DataStream { public: - float const * GetOutputDU(int index=0) const { - return _outdQu + index * _outDesc.stride; + /// Const accessor + float const * GetData() const { + return _data; } - - float const * GetOutputDV(int index=0) const { - return _outdQv + index * _outDesc.stride; - } - - template - void BindOutputDerivData( BUFFER * outdQu, BUFFER * outdQv ) { - _outdQu = outdQu ? outdQu->BindCpuBuffer() : 0; - _outdQv = outdQv ? outdQv->BindCpuBuffer() : 0; - } - - private: - friend class OsdCpuEvalLimitContext; - - EvalVertexData() : _outdQu(0), _outdQv(0) { } - - /// Resets the descriptors & pointers - void Unbind(); - - float * _outdQu, // U derivative of output data - * _outdQv; // V derivative of output data }; + + /// \brief Output (const) data stream + class OutputDataStream : public DataStream { + public: + /// Non-cont accessor + float * GetData() { + return _data; + } + }; + + /// Vertex-interpolated streams + struct VertexData { + /// input vertex-interpolated data descriptor + OsdVertexBufferDescriptor inDesc; - /// Binds the vertex-interpolated data buffers. - /// - /// @param inDesc vertex buffer data descriptor shared by all input data buffers - /// - /// @param inQ input vertex data - /// - /// @param outDesc vertex buffer data descriptor shared by all output data buffers - /// - /// @param outQ output vertex data - /// - /// @param outdQu optional output derivative along "u" of the vertex data - /// - /// @param outdQv optional output derivative along "v" of the vertex data - /// - template - void BindVertexBuffers( OsdVertexBufferDescriptor const & inDesc, VERTEX_BUFFER *inQ, - OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ, - OUTPUT_BUFFER *outdQu=0, - OUTPUT_BUFFER *outdQv=0) { - _vertexData._inDesc = inDesc; - _vertexData.BindInputData( inQ ); - _vertexData._outDesc = outDesc; - _vertexData.BindOutputData( outQ ); - _vertexData.BindOutputDerivData( outdQu, outdQv ); - } + /// input vertex-interpolated data stream + InputDataStream in; - /// Unbind the vertex data buffers - void UnbindVertexBuffers(); + /// output vertex-interpolated data descriptor + OsdVertexBufferDescriptor outDesc; + + /// output vertex-interpolated data stream and parametric derivative streams + OutputDataStream out, + outDu, + outDv; + + /// Binds the vertex-interpolated data streams + /// + /// @param iDesc data descriptor shared by all input data buffers + /// + /// @param inQ input vertex data + /// + /// @param oDesc data descriptor shared by all output data buffers + /// + /// @param outQ output vertex data + /// + /// @param outdQu output derivative along "u" of the vertex data (optional) + /// + /// @param outdQv output derivative along "v" of the vertex data (optional) + /// + template + void Bind( OsdVertexBufferDescriptor const & iDesc, VERTEX_BUFFER *inQ, + OsdVertexBufferDescriptor const & oDesc, OUTPUT_BUFFER *outQ, + OUTPUT_BUFFER *outdQu=0, + OUTPUT_BUFFER *outdQv=0) { + inDesc = iDesc; + in.Bind( inQ ); + + outDesc = oDesc; + out.Bind( outQ ); + outDu.Bind( outdQu ); + outDv.Bind( outdQv ); + } + + /// True if both the mandatory input and output streams have been bound + bool IsBound() const { + return in.IsBound() and out.IsBound(); + } + + /// Unbind the vertex data streams + void Unbind(); + }; /// Returns an Eval data descriptor of the vertex-interpolated data currently /// bound to this EvalLimitContext. - EvalVertexData const & GetVertexData() const { + VertexData & GetVertexData() { return _vertexData; } - /// Binds the varying-interpolated data buffers. - /// - /// @param inDesc varying buffer data descriptor shared by all input data buffers - /// - /// @param inQ input varying data - /// - /// @param outDesc varying buffer data descriptor shared by all output data buffers - /// - /// @param outQ output varying data - /// - template - void BindVaryingBuffers( OsdVertexBufferDescriptor const & inDesc, VARYING_BUFFER *inQ, - OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ) { - _varyingData._inDesc = inDesc; - _varyingData.BindInputData( inQ ); - _varyingData._outDesc = outDesc; - _varyingData.BindOutputData( outQ ); - } - /// Unbind the varying data buffers - void UnbindVaryingBuffers(); + /// Varying-interpolated streams + struct VaryingData { + /// input varying-interpolated data descriptor + OsdVertexBufferDescriptor inDesc; + + /// input varying-interpolated data stream + InputDataStream in; + + /// output varying-interpolated data descriptor + OsdVertexBufferDescriptor outDesc; + + /// output varying-interpolated data stream + OutputDataStream out; + + /// Binds the varying-interpolated data streams + /// + /// @param iDesc data descriptor shared by all input data buffers + /// + /// @param inQ input varying data + /// + /// @param oDesc data descriptor shared by all output data buffers + /// + /// @param outQ output varying data + /// + template + void Bind( OsdVertexBufferDescriptor const & iDesc, VARYING_BUFFER *inQ, + OsdVertexBufferDescriptor const & oDesc, OUTPUT_BUFFER *outQ ) { + inDesc = iDesc; + in.Bind( inQ ); + + outDesc = oDesc; + out.Bind( outQ ); + } + + /// True if both the mandatory input and output streams have been bound + bool IsBound() const { + return in.IsBound() and out.IsBound(); + } + + /// Unbind the vertex data streams + void Unbind(); + }; + /// Returns an Eval data descriptor of the varying-interpolated data currently /// bound to this EvalLimitContext. - EvalData const & GetVaryingData() const { + VaryingData & GetVaryingData() { return _varyingData; } - /// Binds the face-varying-interpolated data buffers. - /// - /// Note : currently we only support bilinear boundary interpolation rules - /// for face-varying data. Although Hbr supports 3 addition smooth rule sets, - /// the feature-adaptive patch interpolation code currently does not support - /// them, and neither does this EvalContext - /// - /// @param inDesc varying buffer data descriptor shared by all input data buffers - /// - /// @param inQ input varying data - /// - /// @param outDesc varying buffer data descriptor shared by all output data buffers - /// - /// @param outQ output varying data - /// - template - void BindFaceVaryingBuffers( OsdVertexBufferDescriptor const & inDesc, - OsdVertexBufferDescriptor const & outDesc, OUTPUT_BUFFER *outQ) { - _faceVaryingData._inDesc = inDesc; - _faceVaryingData._outDesc = outDesc; - _faceVaryingData.BindOutputData( outQ ); - } + /// Face-Varying-interpolated streams + struct FaceVaryingData { + + /// input face-varying-interpolated data descriptor + OsdVertexBufferDescriptor inDesc; - /// Unbind the varying data buffers - void UnbindFaceVaryingBuffers(); + /// output face-varying-interpolated data descriptor + OsdVertexBufferDescriptor outDesc; + /// output face-varying-interpolated data stream and parametric derivative streams + OutputDataStream out; + + /// Binds the face-varying-interpolated data streams + /// + /// Note : currently we only support bilinear boundary interpolation rules + /// for face-varying data. Although Hbr supports 3 addition smooth rule sets, + /// the feature-adaptive patch interpolation code currently does not support + /// them, and neither does this EvalContext + /// + /// @param iDesc data descriptor shared by all input data buffers + /// + /// @param oDesc data descriptor shared by all output data buffers + /// + /// @param outQ output face-varying data + /// + template + void Bind( OsdVertexBufferDescriptor const & iDesc, + OsdVertexBufferDescriptor const & oDesc, OUTPUT_BUFFER *outQ ) { + inDesc = iDesc; + + outDesc = oDesc; + out.Bind( outQ ); + } + + /// True if the output stream has been bound + bool IsBound() const { + return out.IsBound(); + } + + /// Unbind the vertex data streams + void Unbind(); + }; + /// Returns an Eval data descriptor of the face-varying-interpolated data /// currently bound to this EvalLimitContext. - EvalData const & GetFaceVaryingData() const { + FaceVaryingData & GetFaceVaryingData() { return _faceVaryingData; } - /// Returns the vector of patch arrays const FarPatchTables::PatchArrayVector & GetPatchArrayVector() const { return _patchArrays; @@ -282,13 +317,13 @@ public: } /// Returns the vertex-valence buffer used for Gregory patch computations - const int * GetVertexValenceBuffer() const { - return &_vertexValenceBuffer[0]; + FarPatchTables::VertexValenceTable const & GetVertexValenceTable() const { + return _vertexValenceTable; } /// Returns the Quad-Offsets buffer used for Gregory patch computations - const unsigned int *GetQuadOffsetBuffer() const { - return &_quadOffsetBuffer[0]; + FarPatchTables::QuadOffsetTable const & GetQuadOffsetTable() const { + return _quadOffsetTable; } /// Returns the face-varying data patch table @@ -321,16 +356,16 @@ private: FarPatchTables::PTable _patches; // patch control vertices std::vector _patchBitFields; // per-patch parametric info - FarPatchTables::VertexValenceTable _vertexValenceBuffer; // extra Gregory patch data buffers - FarPatchTables::QuadOffsetTable _quadOffsetBuffer; + FarPatchTables::VertexValenceTable _vertexValenceTable; // extra Gregory patch data buffers + FarPatchTables::QuadOffsetTable _quadOffsetTable; FarPatchTables::FVarDataTable _fvarData; - FarPatchMap * _patchMap; // map of the sub-patches given a face index + FarPatchMap * _patchMap; // map of the sub-patches given a face index - EvalVertexData _vertexData; // vertex-interpolated data descriptor - EvalData _varyingData, // varying-interpolated data descriptor - _faceVaryingData; // face-varying-interpolated data descriptor + VertexData _vertexData; // vertex-interpolated data descriptor + VaryingData _varyingData; // varying-interpolated data descriptor + FaceVaryingData _faceVaryingData; // face-varying-interpolated data descriptor int _maxValence, _fvarwidth; diff --git a/opensubdiv/osd/cpuEvalLimitController.cpp b/opensubdiv/osd/cpuEvalLimitController.cpp index 1f349bd6..f1570824 100644 --- a/opensubdiv/osd/cpuEvalLimitController.cpp +++ b/opensubdiv/osd/cpuEvalLimitController.cpp @@ -70,7 +70,7 @@ OsdCpuEvalLimitController::~OsdCpuEvalLimitController() { int OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & coords, - OsdCpuEvalLimitContext const *context, + OsdCpuEvalLimitContext * context, unsigned int index ) { float u=coords.u, v=coords.v; @@ -92,70 +92,80 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c unsigned int const * cvs = &context->GetControlVertices()[ parray.GetVertIndex() + handle->vertexOffset ]; - OsdCpuEvalLimitContext::EvalVertexData const & vertexData = context->GetVertexData(); + OsdCpuEvalLimitContext::VertexData & vertexData = context->GetVertexData(); - // Position lookup pointers at the indexed vertex - float const * inQ = vertexData.GetInputData(); - float * outQ = const_cast(vertexData.GetOutputData(index)); - float * outdQu = const_cast(vertexData.GetOutputDU(index)); - float * outdQv = const_cast(vertexData.GetOutputDV(index)); + if (vertexData.IsBound()) { + + int offset = vertexData.outDesc.stride * index; + + // Based on patch type - go execute interpolation + switch( parray.GetDescriptor().GetType() ) { - // Based on patch type - go execute interpolation - switch( parray.GetDescriptor().GetType() ) { + case FarPatchTables::REGULAR : if (vertexData.IsBound()) { + evalBSpline( v, u, cvs, + vertexData.inDesc, + vertexData.in.GetData(), + vertexData.outDesc, + vertexData.out.GetData()+offset, + vertexData.outDu.GetData()+offset, + vertexData.outDv.GetData()+offset ); + } break; - case FarPatchTables::REGULAR : if (vertexData.IsBound()) { - evalBSpline( v, u, cvs, - vertexData.GetInputDesc(), - inQ, - vertexData.GetOutputDesc(), - outQ, outdQu, outdQv ); - } break; + case FarPatchTables::BOUNDARY : if (vertexData.IsBound()) { + evalBoundary( v, u, cvs, + vertexData.inDesc, + vertexData.in.GetData(), + vertexData.outDesc, + vertexData.out.GetData()+offset, + vertexData.outDu.GetData()+offset, + vertexData.outDv.GetData()+offset ); + } break; - case FarPatchTables::BOUNDARY : if (vertexData.IsBound()) { - evalBoundary( v, u, cvs, - vertexData.GetInputDesc(), - inQ, - vertexData.GetOutputDesc(), - outQ, outdQu, outdQv ); - } break; - - case FarPatchTables::CORNER : if (vertexData.IsBound()) { - evalCorner( v, u, cvs, - vertexData.GetInputDesc(), - inQ, - vertexData.GetOutputDesc(), - outQ, outdQu, outdQv); - } break; + case FarPatchTables::CORNER : if (vertexData.IsBound()) { + evalCorner( v, u, cvs, + vertexData.inDesc, + vertexData.in.GetData(), + vertexData.outDesc, + vertexData.out.GetData()+offset, + vertexData.outDu.GetData()+offset, + vertexData.outDv.GetData()+offset ); + } break; - case FarPatchTables::GREGORY : if (vertexData.IsBound()) { - evalGregory( v, u, cvs, - context->GetVertexValenceBuffer(), - context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle->vertexOffset, - context->GetMaxValence(), - vertexData.GetInputDesc(), - inQ, - vertexData.GetOutputDesc(), - outQ, outdQu, outdQv); - } break; + case FarPatchTables::GREGORY : if (vertexData.IsBound()) { + evalGregory( v, u, cvs, + &context->GetVertexValenceTable()[0], + &context->GetQuadOffsetTable()[ parray.GetQuadOffsetIndex() + handle->vertexOffset ], + context->GetMaxValence(), + vertexData.inDesc, + vertexData.in.GetData(), + vertexData.outDesc, + vertexData.out.GetData()+offset, + vertexData.outDu.GetData()+offset, + vertexData.outDv.GetData()+offset ); + } break; - case FarPatchTables::GREGORY_BOUNDARY : - if (vertexData.IsBound()) { - evalGregoryBoundary(v, u, cvs, - context->GetVertexValenceBuffer(), - context->GetQuadOffsetBuffer() + parray.GetQuadOffsetIndex() + handle->vertexOffset, - context->GetMaxValence(), - vertexData.GetInputDesc(), - inQ, - vertexData.GetOutputDesc(), - outQ, outdQu, outdQv); - } break; + case FarPatchTables::GREGORY_BOUNDARY : + if (vertexData.IsBound()) { + evalGregoryBoundary(v, u, cvs, + &context->GetVertexValenceTable()[0], + &context->GetQuadOffsetTable()[ parray.GetQuadOffsetIndex() + handle->vertexOffset ], + context->GetMaxValence(), + vertexData.inDesc, + vertexData.in.GetData(), + vertexData.outDesc, + vertexData.out.GetData()+offset, + vertexData.outDu.GetData()+offset, + vertexData.outDv.GetData()+offset ); + } break; - default: - assert(0); + default: + assert(0); + } } - OsdCpuEvalLimitContext::EvalData const & varyingData = context->GetVaryingData(); + OsdCpuEvalLimitContext::VaryingData & varyingData = context->GetVaryingData(); + if (varyingData.IsBound()) { static int indices[5][4] = { {5, 6,10, 9}, // regular @@ -166,16 +176,18 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c int type = (int)(parray.GetDescriptor().GetType() - FarPatchTables::REGULAR); + int offset = varyingData.outDesc.stride * index; + unsigned int zeroRing[4] = { cvs[indices[type][0]], cvs[indices[type][1]], cvs[indices[type][2]], cvs[indices[type][3]] }; evalBilinear( v, u, zeroRing, - varyingData.GetInputDesc(), - varyingData.GetInputData(), - varyingData.GetOutputDesc(), - const_cast(varyingData.GetOutputData(index)) ); + varyingData.inDesc, + varyingData.in.GetData(), + varyingData.outDesc, + varyingData.out.GetData()+offset); } @@ -183,22 +195,22 @@ OsdCpuEvalLimitController::_EvalLimitSample( OpenSubdiv::OsdEvalCoords const & c // for face-varying data. Although Hbr supports 3 additional smooth rule // sets, the feature-adaptive patch interpolation code currently does not // support them, and neither does this EvalContext. - OsdCpuEvalLimitContext::EvalData const & faceVaryingData = context->GetFaceVaryingData(); - if (faceVaryingData.GetOutputData()) { + OsdCpuEvalLimitContext::FaceVaryingData & faceVaryingData = context->GetFaceVaryingData(); + if (faceVaryingData.IsBound()) { FarPatchTables::FVarDataTable const & fvarData = context->GetFVarData(); if (not fvarData.empty()) { - float const * fvar = &fvarData[ handle->patchIdx * 4 * context->GetFVarWidth() ]; + int offset = faceVaryingData.outDesc.stride * index; static unsigned int zeroRing[4] = {0,1,2,3}; evalBilinear( v, u, zeroRing, - faceVaryingData.GetInputDesc(), - fvar, - faceVaryingData.GetOutputDesc(), - const_cast(faceVaryingData.GetOutputData(index)) ); + faceVaryingData.inDesc, + &fvarData[ handle->patchIdx * 4 * context->GetFVarWidth() ], + faceVaryingData.outDesc, + faceVaryingData.out.GetData()+offset); } } diff --git a/opensubdiv/osd/cpuEvalLimitController.h b/opensubdiv/osd/cpuEvalLimitController.h index 8d7f9a1d..ab1e47bf 100644 --- a/opensubdiv/osd/cpuEvalLimitController.h +++ b/opensubdiv/osd/cpuEvalLimitController.h @@ -130,7 +130,7 @@ public: private: int _EvalLimitSample( OpenSubdiv::OsdEvalCoords const & coords, - OsdCpuEvalLimitContext const * context, + OsdCpuEvalLimitContext * context, unsigned int index ); }; From 12e25f076a901c2b14405926a26c8c571efd37fd Mon Sep 17 00:00:00 2001 From: manuelk Date: Mon, 17 Jun 2013 19:35:29 -0700 Subject: [PATCH 32/32] Release 1.2.3 --- opensubdiv/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensubdiv/version.h b/opensubdiv/version.h index 2a7d41c0..c076936e 100644 --- a/opensubdiv/version.h +++ b/opensubdiv/version.h @@ -58,6 +58,6 @@ #ifndef OPENSUBDIV_VERSION_H #define OPENSUBDIV_VERSION_H -#define OPENSUBDIV_VERSION v1_2_2 +#define OPENSUBDIV_VERSION v1_2_3 #endif /* OPENSUBDIV_VERSION_H */