Browse Source

Fixed attribute application in renderer

Ivan Safrin 10 năm trước cách đây
mục cha
commit
af2c4106f4

+ 1 - 1
include/polycode/core/PolyRenderer.h

@@ -4,7 +4,7 @@ Copyright (C) 2015 by Ivan Safrin
 Permission is hereby granted, free of charge, to any person obtaining a copy
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+to use, copy, modify, merge, publish, distribute, sublicense, and/or se ll
 copies of the Software, and to permit persons to whom the Software is
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 furnished to do so, subject to the following conditions:
 
 

+ 20 - 20
src/core/PolyRenderer.cpp

@@ -184,26 +184,25 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
                 
                 
                 ShaderPass shaderPass;
                 ShaderPass shaderPass;
 
 
-                if(s < material->getNumShaderPasses()) {
-                    shaderPass = material->getShaderPass(s);
-                } else {
-                    shaderPass = buffer->drawCalls[i].shaderPasses[s];
-                    graphicsInterface->setBlendingMode(shaderPass.blendingMode);
-                }
-                
-                //shaderPass = buffer->drawCalls[i].shaderPasses[s];
+                shaderPass = buffer->drawCalls[i].shaderPasses[s];
                 //graphicsInterface->setBlendingMode(shaderPass.blendingMode);
                 //graphicsInterface->setBlendingMode(shaderPass.blendingMode);
                 
                 
                 ShaderBinding *localShaderBinding = buffer->drawCalls[i].shaderPasses[s].shaderBinding;
                 ShaderBinding *localShaderBinding = buffer->drawCalls[i].shaderPasses[s].shaderBinding;
-
+                ShaderBinding *materialShaderBinding = shaderPass.materialShaderBinding;
+                
+                if(buffer->globalMaterial) {
+                    if(s < buffer->globalMaterial->getNumShaderPasses()) {
+                        shaderPass = buffer->globalMaterial->getShaderPass(s);
+                        localShaderBinding = shaderPass.shaderBinding;
+                    }
+                }
+                
                 if(!shaderPass.shader || !localShaderBinding) {
                 if(!shaderPass.shader || !localShaderBinding) {
                     continue;
                     continue;
                 }
                 }
                 
                 
                 graphicsInterface->useShader(shaderPass.shader);
                 graphicsInterface->useShader(shaderPass.shader);
                 graphicsInterface->setWireframeMode(shaderPass.wireframe);
                 graphicsInterface->setWireframeMode(shaderPass.wireframe);
-                
-                ShaderBinding *materialShaderBinding = shaderPass.materialShaderBinding;
 
 
                 // set global params
                 // set global params
                 for(int p=0; p < shaderPass.shader->expectedParams.size(); p++) {
                 for(int p=0; p < shaderPass.shader->expectedParams.size(); p++) {
@@ -223,19 +222,17 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
                                 graphicsInterface->setParamInShader(shaderPass.shader, localParam->param, localParam);
                                 graphicsInterface->setParamInShader(shaderPass.shader, localParam->param, localParam);
                             }
                             }
                         }
                         }
-
                     }
                     }
                 }
                 }
                 
                 
                 bool rebindAttributes = false;
                 bool rebindAttributes = false;
                 
                 
-                if(localShaderBinding->targetShader != shaderPass.shader) {
-                    localShaderBinding->targetShader = shaderPass.shader;
+                if(buffer->drawCalls[i].shaderPasses[s].shaderBinding->targetShader != shaderPass.shader) {
+                    buffer->drawCalls[i].shaderPasses[s].shaderBinding->targetShader = shaderPass.shader;
                     rebindAttributes = true;
                     rebindAttributes = true;
                 }
                 }
                 
                 
                 for(int p=0; p < localShaderBinding->getNumLocalParams(); p++) {
                 for(int p=0; p < localShaderBinding->getNumLocalParams(); p++) {
-                    
                     LocalShaderParam *localParam = localShaderBinding->getLocalParam(p);
                     LocalShaderParam *localParam = localShaderBinding->getLocalParam(p);
                     if(localParam) {
                     if(localParam) {
                         if(!localParam->param || rebindAttributes) {
                         if(!localParam->param || rebindAttributes) {
@@ -246,14 +243,17 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
                         }
                         }
                     }
                     }
                 }
                 }
-                
+
                 if(rebindAttributes || localShaderBinding->resetAttributes ) {
                 if(rebindAttributes || localShaderBinding->resetAttributes ) {
                     buffer->drawCalls[i].shaderPasses[s].setExpectedAttributes();
                     buffer->drawCalls[i].shaderPasses[s].setExpectedAttributes();
                     localShaderBinding->resetAttributes = false;
                     localShaderBinding->resetAttributes = false;
                 }
                 }
+                
+                // TODO: this is all garbage, REWRITE
+
+                for(int a=0; a < buffer->drawCalls[i].shaderPasses[s].shaderBinding->getNumAttributeBindings(); a++) {
 
 
-                for(int a=0; a < localShaderBinding->getNumAttributeBindings(); a++) {
-                    AttributeBinding *attributeBinding = localShaderBinding->getAttributeBinding(a);
+                    AttributeBinding *attributeBinding = buffer->drawCalls[i].shaderPasses[s].shaderBinding->getAttributeBinding(a);
                     
                     
                     if(attributeBinding) {
                     if(attributeBinding) {
                         if(attributeBinding->enabled  || rebindAttributes) {
                         if(attributeBinding->enabled  || rebindAttributes) {
@@ -270,6 +270,7 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
                             if(attributeBinding->attribute) {
                             if(attributeBinding->attribute) {
                                 attributeBinding->enabled = true;
                                 attributeBinding->enabled = true;
                                 if(attributeBinding->vertexData->data.size() / attributeBinding->vertexData->countPerVertex >= buffer->drawCalls[i].mesh->getVertexCount()) {
                                 if(attributeBinding->vertexData->data.size() / attributeBinding->vertexData->countPerVertex >= buffer->drawCalls[i].mesh->getVertexCount()) {
+                                    
                                     graphicsInterface->setAttributeInShader(shaderPass.shader, attributeBinding->attribute, attributeBinding);
                                     graphicsInterface->setAttributeInShader(shaderPass.shader, attributeBinding->attribute, attributeBinding);
                                 }
                                 }
                             } else {
                             } else {
@@ -284,8 +285,7 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
                 } else {
                 } else {
                     graphicsInterface->drawArrays(buffer->drawCalls[i].mesh->getMeshType(), buffer->drawCalls[i].mesh->getVertexCount());
                     graphicsInterface->drawArrays(buffer->drawCalls[i].mesh->getMeshType(), buffer->drawCalls[i].mesh->getVertexCount());
                 }
                 }
-                
-                
+
                 for(int a=0; a < shaderPass.shader->expectedAttributes.size(); a++) {
                 for(int a=0; a < shaderPass.shader->expectedAttributes.size(); a++) {
                     ProgramAttribute attribute = shaderPass.shader->expectedAttributes[a];
                     ProgramAttribute attribute = shaderPass.shader->expectedAttributes[a];
                     graphicsInterface->disableAttribute(shaderPass.shader, attribute);
                     graphicsInterface->disableAttribute(shaderPass.shader, attribute);