diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-07-22 16:08:18 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-07-22 16:08:18 +0300 |
commit | 165f710519c04192150e685bbb9de3cb52e8bc79 (patch) | |
tree | 1a3feacb82a84463b6d0422f8dc9ef6df67d9e5a | |
parent | ccd51bb9224899b4b7d50170267d94d9b9f2567f (diff) |
OpenSubdiv: Make drawing code a bit more flexible for FVar width
-rw-r--r-- | intern/opensubdiv/opensubdiv_gpu_capi.cc | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc index 16a86f66265..452a8ba35d5 100644 --- a/intern/opensubdiv/opensubdiv_gpu_capi.cc +++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc @@ -112,6 +112,7 @@ struct OpenSubdiv_GLMeshFVarData glDeleteTextures(1, &texture_buffer); } texture_buffer = 0; + fvar_width = 0; channel_offsets.clear(); } @@ -122,6 +123,8 @@ struct OpenSubdiv_GLMeshFVarData { Release(); + this->fvar_width = fvar_width; + /* Expand fvar data to per-patch array */ const int max_level = refiner->GetMaxLevel(); const int num_channels = patch_table->GetNumFVarChannels(); @@ -166,6 +169,7 @@ struct OpenSubdiv_GLMeshFVarData } GLuint texture_buffer; std::vector<size_t> channel_offsets; + int fvar_width; }; /* TODO(sergey): This is actually duplicated code from BLI. */ @@ -430,22 +434,25 @@ void bindProgram(OpenSubdiv_GLMesh *gl_mesh, int program) } /* Face-vertex data */ - if (gl_mesh->fvar_data != NULL && gl_mesh->fvar_data->texture_buffer) { - glActiveTexture(GL_TEXTURE31); - glBindTexture(GL_TEXTURE_BUFFER, gl_mesh->fvar_data->texture_buffer); - glActiveTexture(GL_TEXTURE0); - } - - /* See notes below about why we use such values. */ - /* TOO(sergey): Get proper value for FVar width. */ - glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), 2); - if (gl_mesh->fvar_data != NULL && - gl_mesh->fvar_data->channel_offsets.size() > 0 && - g_active_uv_index >= 0) - { - glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), - gl_mesh->fvar_data->channel_offsets[g_active_uv_index]); + if (gl_mesh->fvar_data != NULL) { + if (gl_mesh->fvar_data->texture_buffer) { + glActiveTexture(GL_TEXTURE31); + glBindTexture(GL_TEXTURE_BUFFER, gl_mesh->fvar_data->texture_buffer); + glActiveTexture(GL_TEXTURE0); + } + + glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), + gl_mesh->fvar_data->fvar_width); + if (gl_mesh->fvar_data->channel_offsets.size() > 0 && + g_active_uv_index >= 0) + { + glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), + gl_mesh->fvar_data->channel_offsets[g_active_uv_index]); + } else { + glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), 0); + } } else { + glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), 0); glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), 0); } } @@ -611,24 +618,22 @@ static GLuint prepare_patchDraw(OpenSubdiv_GLMesh *gl_mesh, } /* Face-vertex data */ - if (gl_mesh->fvar_data != NULL && - gl_mesh->fvar_data->texture_buffer) - { - glActiveTexture(GL_TEXTURE31); - glBindTexture(GL_TEXTURE_BUFFER, - gl_mesh->fvar_data->texture_buffer); - glActiveTexture(GL_TEXTURE0); + if (gl_mesh->fvar_data != NULL) { + if (gl_mesh->fvar_data->texture_buffer) { + glActiveTexture(GL_TEXTURE31); + glBindTexture(GL_TEXTURE_BUFFER, + gl_mesh->fvar_data->texture_buffer); + glActiveTexture(GL_TEXTURE0); + } GLint location = glGetUniformLocation(program, "osd_fvar_count"); if (location != -1) { - /* TODO(sergey): This is width of FVar data, which happened to be 2. */ - glUniform1i(location, 2); + glUniform1i(location, gl_mesh->fvar_data->fvar_width); } location = glGetUniformLocation(program, "osd_active_uv_offset"); if (location != -1) { - if (gl_mesh->fvar_data != NULL && - gl_mesh->fvar_data->channel_offsets.size() > 0 && + if (gl_mesh->fvar_data->channel_offsets.size() > 0 && g_active_uv_index >= 0) { glUniform1i(location, @@ -637,6 +642,9 @@ static GLuint prepare_patchDraw(OpenSubdiv_GLMesh *gl_mesh, glUniform1i(location, 0); } } + } else { + glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), 0); + glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), 0); } } return program; |