History

Merge pull request #4601 from samcake/temp1

Introducing gpu::State and using it in the Model rendering path and more...

Andrew Meadows committed 11 years ago

Commit a47170b2 parents 2f4c305 256434737 files · +1981 −767Browse files

Showing the changes to libraries/render-utils/src/Model.cpp (1 of 37 files). Show all

Unified · Split

libraries/render-utils/src/Model.cpp+233−252
@@ -96,50 +96,89 @@ Model::~Model() { · 95 unmodified lines
9696 deleteGeometry();
9797 }
9898
99−gpu::ShaderPointer Model::_program;
100−gpu::ShaderPointer Model::_normalMapProgram;
101−gpu::ShaderPointer Model::_specularMapProgram;
102−gpu::ShaderPointer Model::_normalSpecularMapProgram;
103−gpu::ShaderPointer Model::_translucentProgram;
104−
105−gpu::ShaderPointer Model::_lightmapProgram;
106−gpu::ShaderPointer Model::_lightmapNormalMapProgram;
107−gpu::ShaderPointer Model::_lightmapSpecularMapProgram;
108−gpu::ShaderPointer Model::_lightmapNormalSpecularMapProgram;
109−
110−gpu::ShaderPointer Model::_shadowProgram;
111−
112−gpu::ShaderPointer Model::_skinProgram;
113−gpu::ShaderPointer Model::_skinNormalMapProgram;
114−gpu::ShaderPointer Model::_skinSpecularMapProgram;
115−gpu::ShaderPointer Model::_skinNormalSpecularMapProgram;
116−gpu::ShaderPointer Model::_skinTranslucentProgram;
117−
118−gpu::ShaderPointer Model::_skinShadowProgram;
119−
120−Model::Locations Model::_locations;
121−Model::Locations Model::_normalMapLocations;
122−Model::Locations Model::_specularMapLocations;
123−Model::Locations Model::_normalSpecularMapLocations;
124−Model::Locations Model::_translucentLocations;
125−Model::Locations Model::_shadowLocations;
126−
127−Model::Locations Model::_lightmapLocations;
128−Model::Locations Model::_lightmapNormalMapLocations;
129−Model::Locations Model::_lightmapSpecularMapLocations;
130−Model::Locations Model::_lightmapNormalSpecularMapLocations;
131−
132−
133−Model::SkinLocations Model::_skinLocations;
134−Model::SkinLocations Model::_skinNormalMapLocations;
135−Model::SkinLocations Model::_skinSpecularMapLocations;
136−Model::SkinLocations Model::_skinNormalSpecularMapLocations;
137−Model::SkinLocations Model::_skinTranslucentLocations;
138−Model::SkinLocations Model::_skinShadowLocations;
99+Model::RenderPipelineLib Model::_renderPipelineLib;
100+const GLint MATERIAL_GPU_SLOT = 3;
101+
102+void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key,
103+ gpu::ShaderPointer& vertexShader,
104+ gpu::ShaderPointer& pixelShader ) {
105+
106+ gpu::Shader::BindingSet slotBindings;
107+ slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), MATERIAL_GPU_SLOT));
108+ slotBindings.insert(gpu::Shader::Binding(std::string("diffuseMap"), 0));
109+ slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), 1));
110+ slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), 2));
111+ slotBindings.insert(gpu::Shader::Binding(std::string("emissiveMap"), 3));
112+
113+ gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader));
114+ bool makeResult = gpu::Shader::makeProgram(*program, slotBindings);
115+
116+
117+ auto locations = std::shared_ptr<Locations>(new Locations());
118+ initLocations(program, *locations);
119+
120+
121+ gpu::StatePointer state = gpu::StatePointer(new gpu::State());
122+
123+ // Backface on shadow
124+ if (key.isShadow()) {
125+ state->setCullMode(gpu::State::CULL_FRONT);
126+ state->setDepthBias(1.0f);
127+ state->setDepthBiasSlopeScale(4.0f);
128+ } else {
129+ state->setCullMode(gpu::State::CULL_BACK);
130+ }
131+
132+ // Z test depends if transparent or not
133+ state->setDepthTest(true, !key.isTranslucent(), gpu::State::LESS_EQUAL);
134+
135+ // Blend on transparent
136+ state->setBlendFunction(key.isTranslucent(),
137+ gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
138+ gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
139+
140+ // Good to go add the brand new pipeline
141+ auto pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
142+ auto it = insert(value_type(key.getRaw(), RenderPipeline(pipeline, locations)));
143+
144+ // If not a shadow pass, create the mirror version from the same state, just change the FrontFace
145+ if (!key.isShadow()) {
146+
147+ RenderKey mirrorKey(key.getRaw() | RenderKey::IS_MIRROR);
148+ gpu::StatePointer mirrorState = gpu::StatePointer(new gpu::State(state->getValues()));
149+
150+ mirrorState->setFrontFaceClockwise(true);
151+
152+ // create a new RenderPipeline with the same shader side and the mirrorState
153+ auto mirrorPipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, mirrorState));
154+ auto it = insert(value_type(mirrorKey.getRaw(), RenderPipeline(mirrorPipeline, locations)));
155+ }
156+}
157+
158+
159+void Model::RenderPipelineLib::initLocations(gpu::ShaderPointer& program, Model::Locations& locations) {
160+ locations.alphaThreshold = program->getUniforms().findLocation("alphaThreshold");
161+ locations.texcoordMatrices = program->getUniforms().findLocation("texcoordMatrices");
162+ locations.emissiveParams = program->getUniforms().findLocation("emissiveParams");
163+ locations.glowIntensity = program->getUniforms().findLocation("glowIntensity");
164+
165+ locations.specularTextureUnit = program->getTextures().findLocation("specularMap");
166+ locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap");
167+
168+#if (GPU_FEATURE_PROFILE == GPU_CORE)
169+ locations.materialBufferUnit = program->getBuffers().findLocation("materialBuffer");
170+#else
171+ locations.materialBufferUnit = program->getUniforms().findLocation("materialBuffer");
172+#endif
173+ locations.clusterMatrices = program->getUniforms().findLocation("clusterMatrices");
174+
175+ locations.clusterIndices = program->getInputs().findLocation("clusterIndices");;
176+ locations.clusterWeights = program->getInputs().findLocation("clusterWeights");;
177+
178+}
139179
140180 AbstractViewStateInterface* Model::_viewState = NULL;
141181
142−const GLint MATERIAL_GPU_SLOT = 3;
143182
144183 void Model::setScale(const glm::vec3& scale) {
145184 setScaleInternal(scale);
@@ -171,33 +210,6 @@ void Model::setOffset(const glm::vec3& offset) { · 25 unmodified lines
171210 _snappedToRegistrationPoint = false;
172211 }
173212
174−void Model::initProgram(gpu::ShaderPointer& program, Model::Locations& locations) {
175− locations.alphaThreshold = program->getUniforms().findLocation("alphaThreshold");
176− locations.texcoordMatrices = program->getUniforms().findLocation("texcoordMatrices");
177− locations.emissiveParams = program->getUniforms().findLocation("emissiveParams");
178− locations.glowIntensity = program->getUniforms().findLocation("glowIntensity");
179−
180− locations.specularTextureUnit = program->getTextures().findLocation("specularMap");
181− locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap");
182−
183−#if (GPU_FEATURE_PROFILE == GPU_CORE)
184− locations.materialBufferUnit = program->getBuffers().findLocation("materialBuffer");
185−#else
186− locations.materialBufferUnit = program->getUniforms().findLocation("materialBuffer");
187−#endif
188−
189−}
190−
191−void Model::initSkinProgram(gpu::ShaderPointer& program, Model::SkinLocations& locations) {
192−
193− initProgram(program, locations);
194−
195− locations.clusterMatrices = program->getUniforms().findLocation("clusterMatrices");
196−
197− locations.clusterIndices = program->getInputs().findLocation("clusterIndices");;
198− locations.clusterWeights = program->getInputs().findLocation("clusterWeights");;
199−}
200−
201213 QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) {
202214 QVector<JointState> jointStates;
203215 for (int i = 0; i < geometry.joints.size(); ++i) {
@@ -231,7 +243,7 @@ void Model::initJointTransforms() { · 27 unmodified lines
231243 }
232244
233245 void Model::init() {
234− if (_program.isNull()) {
246+ if (_renderPipelineLib.empty()) {
235247 gpu::Shader::BindingSet slotBindings;
236248 slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), MATERIAL_GPU_SLOT));
237249 slotBindings.insert(gpu::Shader::Binding(std::string("diffuseMap"), 0));
@@ -261,75 +273,71 @@ void Model::init() { · 23 unmodified lines
261273 auto modelLightmapSpecularMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)));
262274 auto modelLightmapNormalSpecularMapPixel = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)));
263275
276+ // Fill the renderPipelineLib
277+
278+ _renderPipelineLib.addRenderPipeline(
279+ RenderKey(0),
280+ modelVertex, modelPixel);
264281
265− bool makeResult = false;
266−
267− // Programs
268− _program = gpu::ShaderPointer(gpu::Shader::createProgram(modelVertex, modelPixel));
269− makeResult = gpu::Shader::makeProgram(*_program, slotBindings);
270− initProgram(_program, _locations);
282+ _renderPipelineLib.addRenderPipeline(
283+ RenderKey(RenderKey::HAS_TANGENTS),
284+ modelNormalMapVertex, modelNormalMapPixel);
271285
272− _normalMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelNormalMapVertex, modelNormalMapPixel));
273− makeResult = gpu::Shader::makeProgram(*_normalMapProgram, slotBindings);
274− initProgram(_normalMapProgram, _normalMapLocations);
286+ _renderPipelineLib.addRenderPipeline(
287+ RenderKey(RenderKey::HAS_SPECULAR),
288+ modelVertex, modelSpecularMapPixel);
275289
276− _specularMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelVertex, modelSpecularMapPixel));
277− makeResult = gpu::Shader::makeProgram(*_specularMapProgram, slotBindings);
278− initProgram(_specularMapProgram, _specularMapLocations);
290+ _renderPipelineLib.addRenderPipeline(
291+ RenderKey(RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),
292+ modelNormalMapVertex, modelNormalSpecularMapPixel);
279293
280− _normalSpecularMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelNormalMapVertex, modelNormalSpecularMapPixel));
281− makeResult = gpu::Shader::makeProgram(*_normalSpecularMapProgram, slotBindings);
282− initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations);
294+ _renderPipelineLib.addRenderPipeline(
295+ RenderKey(RenderKey::IS_TRANSLUCENT),
296+ modelVertex, modelTranslucentPixel);
297+
298+ _renderPipelineLib.addRenderPipeline(
299+ RenderKey(RenderKey::HAS_LIGHTMAP),
300+ modelLightmapVertex, modelLightmapPixel);
301+ _renderPipelineLib.addRenderPipeline(
302+ RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS),
303+ modelLightmapNormalMapVertex, modelLightmapNormalMapPixel);
283304
284− _translucentProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelVertex, modelTranslucentPixel));
285− makeResult = gpu::Shader::makeProgram(*_translucentProgram, slotBindings);
286− initProgram(_translucentProgram, _translucentLocations);
287−
288− _shadowProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelShadowVertex, modelShadowPixel));
289− makeResult = gpu::Shader::makeProgram(*_shadowProgram, slotBindings);
290− initProgram(_shadowProgram, _shadowLocations);
305+ _renderPipelineLib.addRenderPipeline(
306+ RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_SPECULAR),
307+ modelLightmapVertex, modelLightmapSpecularMapPixel);
291308
292− _lightmapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelLightmapVertex, modelLightmapPixel));
293− makeResult = gpu::Shader::makeProgram(*_lightmapProgram, slotBindings);
294− initProgram(_lightmapProgram, _lightmapLocations);
309+ _renderPipelineLib.addRenderPipeline(
310+ RenderKey(RenderKey::HAS_LIGHTMAP | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),
311+ modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel);
295312
296− _lightmapNormalMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelLightmapNormalMapVertex, modelLightmapNormalMapPixel));
297− makeResult = gpu::Shader::makeProgram(*_lightmapNormalMapProgram, slotBindings);
298− initProgram(_lightmapNormalMapProgram, _lightmapNormalMapLocations);
313+ _renderPipelineLib.addRenderPipeline(
314+ RenderKey(RenderKey::IS_SKINNED),
315+ skinModelVertex, modelPixel);
299316
300− _lightmapSpecularMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelLightmapVertex, modelLightmapSpecularMapPixel));
301− makeResult = gpu::Shader::makeProgram(*_lightmapSpecularMapProgram, slotBindings);
302− initProgram(_lightmapSpecularMapProgram, _lightmapSpecularMapLocations);
317+ _renderPipelineLib.addRenderPipeline(
318+ RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS),
319+ skinModelNormalMapVertex, modelNormalMapPixel);
303320
304− _lightmapNormalSpecularMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel));
305− makeResult = gpu::Shader::makeProgram(*_lightmapNormalSpecularMapProgram, slotBindings);
306− initProgram(_lightmapNormalSpecularMapProgram, _lightmapNormalSpecularMapLocations);
321+ _renderPipelineLib.addRenderPipeline(
322+ RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_SPECULAR),
323+ skinModelVertex, modelSpecularMapPixel);
307324
308− _skinProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelVertex, modelPixel));
309− makeResult = gpu::Shader::makeProgram(*_skinProgram, slotBindings);
310− initSkinProgram(_skinProgram, _skinLocations);
325+ _renderPipelineLib.addRenderPipeline(
326+ RenderKey(RenderKey::IS_SKINNED | RenderKey::HAS_TANGENTS | RenderKey::HAS_SPECULAR),
327+ skinModelNormalMapVertex, modelNormalSpecularMapPixel);
311328
312− _skinNormalMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelNormalMapVertex, modelNormalMapPixel));
313− makeResult = gpu::Shader::makeProgram(*_skinNormalMapProgram, slotBindings);
314− initSkinProgram(_skinNormalMapProgram, _skinNormalMapLocations);
329+ _renderPipelineLib.addRenderPipeline(
330+ RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_TRANSLUCENT),
331+ skinModelVertex, modelTranslucentPixel);
315332
316− _skinSpecularMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelVertex, modelSpecularMapPixel));
317− makeResult = gpu::Shader::makeProgram(*_skinSpecularMapProgram, slotBindings);
318− initSkinProgram(_skinSpecularMapProgram, _skinSpecularMapLocations);
319333
320− _skinNormalSpecularMapProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelNormalMapVertex, modelNormalSpecularMapPixel));
321− makeResult = gpu::Shader::makeProgram(*_skinNormalSpecularMapProgram, slotBindings);
322− initSkinProgram(_skinNormalSpecularMapProgram, _skinNormalSpecularMapLocations);
323−
324− _skinShadowProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelShadowVertex, modelShadowPixel));
325− makeResult = gpu::Shader::makeProgram(*_skinShadowProgram, slotBindings);
326− initSkinProgram(_skinShadowProgram, _skinShadowLocations);
327−
328− _skinTranslucentProgram = gpu::ShaderPointer(gpu::Shader::createProgram(skinModelVertex, modelTranslucentPixel));
329− makeResult = gpu::Shader::makeProgram(*_skinTranslucentProgram, slotBindings);
330− initSkinProgram(_skinTranslucentProgram, _skinTranslucentLocations);
334+ _renderPipelineLib.addRenderPipeline(
335+ RenderKey(RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW),
336+ modelShadowVertex, modelShadowPixel);
331337
332− (void) makeResult; // quiet compiler
338+ _renderPipelineLib.addRenderPipeline(
339+ RenderKey(RenderKey::IS_SKINNED | RenderKey::IS_DEPTH_ONLY | RenderKey::IS_SHADOW),
340+ skinModelShadowVertex, modelShadowPixel);
333341 }
334342 }
335343
@@ -665,6 +673,8 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { · 329 unmodified lines
665673 return false;
666674 }
667675
676+ // auto glowEffectIntensity = DependencyManager::get<GlowEffect>()->getIntensity();
677+
668678 // Let's introduce a gpu::Batch to capture all the calls to the graphics api
669679 _renderBatch.clear();
670680 gpu::Batch& batch = _renderBatch;
@@ -693,42 +703,48 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { · 22 unmodified lines
693703
694704 batch.setViewTransform(_transforms[0]);
695705
696− GLBATCH(glDisable)(GL_COLOR_MATERIAL);
706+ // GLBATCH(glDisable)(GL_COLOR_MATERIAL);
697707
698− if (mode == DIFFUSE_RENDER_MODE || mode == NORMAL_RENDER_MODE) {
708+ // taking care of by the state?
709+ /* if (mode == RenderArgs::DIFFUSE_RENDER_MODE || mode == RenderArgs::NORMAL_RENDER_MODE) {
699710 GLBATCH(glDisable)(GL_CULL_FACE);
700711 } else {
701712 GLBATCH(glEnable)(GL_CULL_FACE);
702− if (mode == SHADOW_RENDER_MODE) {
713+ if (mode == RenderArgs::SHADOW_RENDER_MODE) {
703714 GLBATCH(glCullFace)(GL_FRONT);
704715 }
705716 }
706−
717+ */
718+
707719 // render opaque meshes with alpha testing
708720
709− GLBATCH(glDisable)(GL_BLEND);
710− GLBATCH(glEnable)(GL_ALPHA_TEST);
711−
712− if (mode == SHADOW_RENDER_MODE) {
721+// GLBATCH(glDisable)(GL_BLEND);
722+// GLBATCH(glEnable)(GL_ALPHA_TEST);
723+
724+ /* if (mode == RenderArgs::SHADOW_RENDER_MODE) {
713725 GLBATCH(glAlphaFunc)(GL_EQUAL, 0.0f);
714726 }
715−
727+ */
716728
717729 /*DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(
718− mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE,
719− mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE,
720− mode == DEFAULT_RENDER_MODE);
730+ mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::DIFFUSE_RENDER_MODE,
731+ mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::NORMAL_RENDER_MODE,
732+ mode == RenderArgs::DEFAULT_RENDER_MODE);
721733 */
722734 {
723735 GLenum buffers[3];
724736 int bufferCount = 0;
725− if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
737+
738+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::DIFFUSE_RENDER_MODE) {
739+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
726740 buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
727741 }
728− if (mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
742+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::NORMAL_RENDER_MODE) {
743+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
729744 buffers[bufferCount++] = GL_COLOR_ATTACHMENT1;
730745 }
731− if (mode == DEFAULT_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
746+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE) {
747+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
732748 buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
733749 }
734750 GLBATCH(glDrawBuffers)(bufferCount, buffers);
@@ -774,11 +790,11 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { · 39 unmodified lines
774790 translucentMeshPartsRendered += renderMeshes(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, true, false, args, true);
775791 translucentMeshPartsRendered += renderMeshes(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, true, true, args, true);
776792
777− GLBATCH(glDisable)(GL_ALPHA_TEST);
778− GLBATCH(glEnable)(GL_BLEND);
793+ // GLBATCH(glDisable)(GL_ALPHA_TEST);
794+ /* GLBATCH(glEnable)(GL_BLEND);
779795 GLBATCH(glDepthMask)(false);
780796 GLBATCH(glDepthFunc)(GL_LEQUAL);
781−
797+ */
782798 //DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true);
783799 {
784800 GLenum buffers[1];
@@ -787,7 +803,8 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { · 2 unmodified lines
787803 GLBATCH(glDrawBuffers)(bufferCount, buffers);
788804 }
789805
790− if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
806+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::DIFFUSE_RENDER_MODE) {
807+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
791808 const float MOSTLY_TRANSPARENT_THRESHOLD = 0.0f;
792809 translucentMeshPartsRendered += renderMeshes(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, false, false, args, true);
793810 translucentMeshPartsRendered += renderMeshes(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, false, true, args, true);
@@ -803,7 +820,7 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { · 9 unmodified lines
803820 GLBATCH(glDepthFunc)(GL_LESS);
804821 GLBATCH(glDisable)(GL_CULL_FACE);
805822
806− if (mode == SHADOW_RENDER_MODE) {
823+ if (mode == RenderArgs::SHADOW_RENDER_MODE) {
807824 GLBATCH(glCullFace)(GL_BACK);
808825 }
809826
@@ -830,6 +847,9 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { · 20 unmodified lines
830847 GLBATCH(glBindBuffer)(GL_ELEMENT_ARRAY_BUFFER, 0);
831848 GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0);
832849
850+ // Back to no program
851+ GLBATCH(glUseProgram)(0);
852+
833853 // Render!
834854 {
835855 PROFILE_RANGE("render Batch");
@@ -1738,6 +1758,9 @@ void Model::setupBatchTransform(gpu::Batch& batch, RenderArgs* args) { · 902 unmodified lines
17381758 void Model::endScene(RenderMode mode, RenderArgs* args) {
17391759 PROFILE_RANGE(__FUNCTION__);
17401760
1761+ // auto glowEffectIntensity = DependencyManager::get<GlowEffect>()->getIntensity();
1762+
1763+
17411764 #if defined(ANDROID)
17421765 #else
17431766 glPushMatrix();
@@ -1769,42 +1792,45 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { · 25 unmodified lines
17691792 _sceneRenderBatch.clear();
17701793 gpu::Batch& batch = _sceneRenderBatch;
17711794
1772− GLBATCH(glDisable)(GL_COLOR_MATERIAL);
1795+ // GLBATCH(glDisable)(GL_COLOR_MATERIAL);
17731796
1774− if (mode == DIFFUSE_RENDER_MODE || mode == NORMAL_RENDER_MODE) {
1797+ /* if (mode == RenderArgs::DIFFUSE_RENDER_MODE || mode == RenderArgs::NORMAL_RENDER_MODE) {
17751798 GLBATCH(glDisable)(GL_CULL_FACE);
17761799 } else {
17771800 GLBATCH(glEnable)(GL_CULL_FACE);
1778− if (mode == SHADOW_RENDER_MODE) {
1801+ if (mode == RenderArgs::SHADOW_RENDER_MODE) {
17791802 GLBATCH(glCullFace)(GL_FRONT);
17801803 }
1781− }
1804+ }*/
17821805
17831806 // render opaque meshes with alpha testing
17841807
1785− GLBATCH(glDisable)(GL_BLEND);
1786− GLBATCH(glEnable)(GL_ALPHA_TEST);
1808+ // GLBATCH(glDisable)(GL_BLEND);
1809+ // GLBATCH(glEnable)(GL_ALPHA_TEST);
17871810
1788− if (mode == SHADOW_RENDER_MODE) {
1811+ /* if (mode == RenderArgs::SHADOW_RENDER_MODE) {
17891812 GLBATCH(glAlphaFunc)(GL_EQUAL, 0.0f);
17901813 }
1791−
1814+*/
17921815
17931816 /*DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(
1794− mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE,
1795− mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE,
1796− mode == DEFAULT_RENDER_MODE);
1817+ mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::DIFFUSE_RENDER_MODE,
1818+ mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::NORMAL_RENDER_MODE,
1819+ mode == RenderArgs::DEFAULT_RENDER_MODE);
17971820 */
17981821 {
17991822 GLenum buffers[3];
18001823 int bufferCount = 0;
1801− if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
1824+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::DIFFUSE_RENDER_MODE) {
1825+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
18021826 buffers[bufferCount++] = GL_COLOR_ATTACHMENT0;
18031827 }
1804− if (mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
1828+ //if (mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::NORMAL_RENDER_MODE) {
1829+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
18051830 buffers[bufferCount++] = GL_COLOR_ATTACHMENT1;
18061831 }
1807− if (mode == DEFAULT_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
1832+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE) {
1833+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
18081834 buffers[bufferCount++] = GL_COLOR_ATTACHMENT2;
18091835 }
18101836 GLBATCH(glDrawBuffers)(bufferCount, buffers);
@@ -1850,11 +1876,11 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { · 39 unmodified lines
18501876 translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, true, false, args);
18511877 translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, true, true, args);
18521878
1853− GLBATCH(glDisable)(GL_ALPHA_TEST);
1854− GLBATCH(glEnable)(GL_BLEND);
1879+ // GLBATCH(glDisable)(GL_ALPHA_TEST);
1880+ /* GLBATCH(glEnable)(GL_BLEND);
18551881 GLBATCH(glDepthMask)(false);
18561882 GLBATCH(glDepthFunc)(GL_LEQUAL);
1857−
1883+ */
18581884 //DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true);
18591885 {
18601886 GLenum buffers[1];
@@ -1863,7 +1889,8 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { · 2 unmodified lines
18631889 GLBATCH(glDrawBuffers)(bufferCount, buffers);
18641890 }
18651891
1866− if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE || mode == DEBUG_RENDER_MODE) {
1892+ // if (mode == RenderArgs::DEFAULT_RENDER_MODE || mode == RenderArgs::DIFFUSE_RENDER_MODE) {
1893+ if (mode != RenderArgs::SHADOW_RENDER_MODE) {
18671894 const float MOSTLY_TRANSPARENT_THRESHOLD = 0.0f;
18681895 translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, false, false, args);
18691896 translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, false, true, args);
@@ -1879,7 +1906,7 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { · 9 unmodified lines
18791906 GLBATCH(glDepthFunc)(GL_LESS);
18801907 GLBATCH(glDisable)(GL_CULL_FACE);
18811908
1882− if (mode == SHADOW_RENDER_MODE) {
1909+ if (mode == RenderArgs::SHADOW_RENDER_MODE) {
18831910 GLBATCH(glCullFace)(GL_BACK);
18841911 }
18851912
@@ -1907,6 +1934,10 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { · 21 unmodified lines
19071934 GLBATCH(glBindBuffer)(GL_ARRAY_BUFFER, 0);
19081935 GLBATCH(glBindBuffer)(GL_ELEMENT_ARRAY_BUFFER, 0);
19091936 GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0);
1937+
1938+ // Back to no program
1939+ GLBATCH(glUseProgram)(0);
1940+
19101941 if (args) {
19111942 args->_translucentMeshPartsRendered = translucentParts;
19121943 args->_opaqueMeshPartsRendered = opaqueMeshPartsRendered;
@@ -2298,83 +2329,34 @@ QVector<int>* Model::pickMeshList(bool translucent, float alphaThreshold, bool h · 385 unmodified lines
22982329
22992330 void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
23002331 bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args,
2301− Locations*& locations, SkinLocations*& skinLocations) {
2302− gpu::ShaderPointer program = _program;
2303− locations = &_locations;
2304− gpu::ShaderPointer skinProgram = _skinProgram;
2305− skinLocations = &_skinLocations;
2306− if (mode == SHADOW_RENDER_MODE) {
2307− program = _shadowProgram;
2308− locations = &_shadowLocations;
2309− skinProgram = _skinShadowProgram;
2310− skinLocations = &_skinShadowLocations;
2311− } else if (translucent && alphaThreshold == 0.0f) {
2312− program = _translucentProgram;
2313− locations = &_translucentLocations;
2314− skinProgram = _skinTranslucentProgram;
2315− skinLocations = &_skinTranslucentLocations;
2316−
2317− } else if (hasLightmap) {
2318− if (hasTangents) {
2319− if (hasSpecular) {
2320− program = _lightmapNormalSpecularMapProgram;
2321− locations = &_lightmapNormalSpecularMapLocations;
2322− skinProgram.reset();
2323− skinLocations = NULL;
2324− } else {
2325− program = _lightmapNormalMapProgram;
2326− locations = &_lightmapNormalMapLocations;
2327− skinProgram.reset();
2328− skinLocations = NULL;
2329− }
2330− } else if (hasSpecular) {
2331− program = _lightmapSpecularMapProgram;
2332− locations = &_lightmapSpecularMapLocations;
2333− skinProgram.reset();
2334− skinLocations = NULL;
2335− } else {
2336− program = _lightmapProgram;
2337− locations = &_lightmapLocations;
2338− skinProgram.reset();
2339− skinLocations = NULL;
2340− }
2341− } else {
2342− if (hasTangents) {
2343− if (hasSpecular) {
2344− program = _normalSpecularMapProgram;
2345− locations = &_normalSpecularMapLocations;
2346− skinProgram = _skinNormalSpecularMapProgram;
2347− skinLocations = &_skinNormalSpecularMapLocations;
2348− } else {
2349− program = _normalMapProgram;
2350− locations = &_normalMapLocations;
2351− skinProgram = _skinNormalMapProgram;
2352− skinLocations = &_skinNormalMapLocations;
2353− }
2354− } else if (hasSpecular) {
2355− program = _specularMapProgram;
2356− locations = &_specularMapLocations;
2357− skinProgram = _skinSpecularMapProgram;
2358− skinLocations = &_skinSpecularMapLocations;
2359− }
2360− }
2361−
2362− gpu::ShaderPointer activeProgram = program;
2363− Locations* activeLocations = locations;
2332+ Locations*& locations) {
23642333
2365− if (isSkinned) {
2366− activeProgram = skinProgram;
2367− activeLocations = skinLocations;
2368− locations = skinLocations;
2334+ RenderKey key(mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned);
2335+ auto pipeline = _renderPipelineLib.find(key.getRaw());
2336+ if (pipeline == _renderPipelineLib.end()) {
2337+ qDebug() << "No good, couldn;t find a pipeline from the key ?" << key.getRaw();
2338+ return;
23692339 }
23702340
2371− GLuint glprogram = gpu::GLBackend::getShaderID(activeProgram);
2372− GLBATCH(glUseProgram)(glprogram);
2341+ gpu::ShaderPointer program = (*pipeline).second._pipeline->getProgram();
2342+ locations = (*pipeline).second._locations.get();
2343+
2344+ //GLuint glprogram = gpu::GLBackend::getShaderID(program);
2345+ //GLBATCH(glUseProgram)(glprogram);
23732346
2347+ // dare!
2348+ batch.setPipeline((*pipeline).second._pipeline);
23742349
2375− if ((activeLocations->alphaThreshold > -1) && (mode != SHADOW_RENDER_MODE)) {
2376− GLBATCH(glUniform1f)(activeLocations->alphaThreshold, alphaThreshold);
2350+ if ((locations->alphaThreshold > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) {
2351+ GLBATCH(glUniform1f)(locations->alphaThreshold, alphaThreshold);
23772352 }
2353+
2354+ if ((locations->glowIntensity > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) {
2355+ GLBATCH(glUniform1f)(locations->glowIntensity, DependencyManager::get<GlowEffect>()->getIntensity());
2356+ }
2357+ // if (!(translucent && alphaThreshold == 0.0f) && (mode != RenderArgs::SHADOW_RENDER_MODE)) {
2358+ // GLBATCH(glAlphaFunc)(GL_EQUAL, DependencyManager::get<GlowEffect>()->getIntensity());
2359+ // }
23782360 }
23792361
23802362 int Model::renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
@@ -2385,7 +2367,6 @@ int Model::renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool · 4 unmodified lines
23852367
23862368 bool pickProgramsNeeded = true;
23872369 Locations* locations;
2388− SkinLocations* skinLocations;
23892370
23902371 foreach(Model* model, _modelsInScene) {
23912372 QVector<int>* whichList = model->pickMeshList(translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned);
@@ -2393,24 +2374,25 @@ int Model::renderMeshesForModelsInScene(gpu::Batch& batch, RenderMode mode, bool · 1 unmodified line
23932374 QVector<int>& list = *whichList;
23942375 if (list.size() > 0) {
23952376 if (pickProgramsNeeded) {
2396− pickPrograms(batch, mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, args, locations, skinLocations);
2377+ pickPrograms(batch, mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, args, locations);
23972378 pickProgramsNeeded = false;
23982379 }
2380+
23992381 model->setupBatchTransform(batch, args);
2400− meshPartsRendered += model->renderMeshesFromList(list, batch, mode, translucent, alphaThreshold, args, locations, skinLocations);
2382+ meshPartsRendered += model->renderMeshesFromList(list, batch, mode, translucent, alphaThreshold, args, locations);
24012383 }
24022384 }
24032385 }
24042386 // if we selected a program, then unselect it
24052387 if (!pickProgramsNeeded) {
2406− GLBATCH(glUseProgram)(0);
2388+ // GLBATCH(glUseProgram)(0);
24072389 }
24082390 return meshPartsRendered;
24092391 }
24102392
24112393 int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold,
24122394 bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args,
2413− bool forceRenderMeshes) {
2395+ bool forceRenderSomeMeshes) {
24142396
24152397 PROFILE_RANGE(__FUNCTION__);
24162398 int meshPartsRendered = 0;
@@ -2429,24 +2411,23 @@ int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, fl · 12 unmodified lines
24292411 }
24302412
24312413 Locations* locations;
2432− SkinLocations* skinLocations;
24332414 pickPrograms(batch, mode, translucent, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned,
2434− args, locations, skinLocations);
2415+ args, locations);
24352416 meshPartsRendered = renderMeshesFromList(list, batch, mode, translucent, alphaThreshold,
2436− args, locations, skinLocations, forceRenderMeshes);
2437− GLBATCH(glUseProgram)(0);
2417+ args, locations, forceRenderSomeMeshes);
2418+ // GLBATCH(glUseProgram)(0);
2419+
24382420
24392421 return meshPartsRendered;
24402422 }
24412423
24422424
2443−int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMode mode, bool translucent,
2444− float alphaThreshold, RenderArgs* args, Locations* locations, SkinLocations* skinLocations,
2445− bool forceRenderMeshes) {
2425+int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, RenderArgs* args,
2426+ Locations* locations, bool forceRenderMeshes) {
24462427 PROFILE_RANGE(__FUNCTION__);
24472428
24482429 auto textureCache = DependencyManager::get<TextureCache>();
2449− auto glowEffect = DependencyManager::get<GlowEffect>();
2430+ // auto glowEffect = DependencyManager::get<GlowEffect>();
24502431 QString lastMaterialID;
24512432 int meshPartsRendered = 0;
24522433 updateVisibleJointStates();
@@ -2506,7 +2487,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod · 53 unmodified lines
25062487
25072488 const MeshState& state = _meshStates.at(i);
25082489 if (state.clusterMatrices.size() > 1) {
2509− GLBATCH(glUniformMatrix4fv)(skinLocations->clusterMatrices, state.clusterMatrices.size(), false,
2490+ GLBATCH(glUniformMatrix4fv)(locations->clusterMatrices, state.clusterMatrices.size(), false,
25102491 (const float*)state.clusterMatrices.constData());
25112492 batch.setModelTransform(Transform());
25122493 } else {
@@ -2524,7 +2505,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod · 11 unmodified lines
25242505 }
25252506
25262507 if (mesh.colors.isEmpty()) {
2527− GLBATCH(glColor4f)(1.0f, 1.0f, 1.0f, 1.0f);
2508+ GLBATCH(glColor4f)(0.0f, 1.0f, 0.0f, 1.0f);
25282509 }
25292510
25302511 qint64 offset = 0;
@@ -2538,7 +2519,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod · 7 unmodified lines
25382519 }
25392520
25402521 // apply material properties
2541− if (mode == SHADOW_RENDER_MODE) {
2522+ if (mode == RenderArgs::SHADOW_RENDER_MODE) {
25422523 /// GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0);
25432524
25442525 } else {
@@ -2550,13 +2531,13 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod · 5 unmodified lines
25502531 qCDebug(renderutils) << "NEW part.materialID:" << part.materialID;
25512532 }
25522533
2553− if (locations->glowIntensity >= 0) {
2534+/* if (locations->glowIntensity >= 0) {
25542535 GLBATCH(glUniform1f)(locations->glowIntensity, glowEffect->getIntensity());
25552536 }
25562537 if (!(translucent && alphaThreshold == 0.0f)) {
25572538 GLBATCH(glAlphaFunc)(GL_EQUAL, glowEffect->getIntensity());
25582539 }
2559−
2540+*/
25602541 if (locations->materialBufferUnit >= 0) {
25612542 batch.setUniformBuffer(locations->materialBufferUnit, material->getSchemaBuffer());
25622543 }