ソースを参照

Got SceneLabels working with the new renderer, caching uniform and attribute bindings

Ivan Safrin 10 年 前
コミット
8389c645df

BIN
Assets/Default asset pack/default.pak


+ 2 - 4
Assets/Default asset pack/default/Unlit.frag

@@ -1,8 +1,6 @@
-uniform sampler2D texture;
-uniform vec2 scroll;
-
+uniform sampler2D diffuse;
 varying vec2 texCoordVar;
 
 void main() {
-	gl_FragColor = texture2D( texture, texCoordVar + scroll);
+	gl_FragColor = texture2D(diffuse, texCoordVar);
 }

+ 1 - 1
Core/Contents/Include/PolyCocoaCore.h

@@ -111,7 +111,7 @@ namespace Polycode {
         bool createRenderContext();
         
 		void enableMouse(bool newval);
-		unsigned int getTicks();		
+		unsigned int getTicks();
 		bool systemUpdate();
 		
 		void Render();

+ 5 - 9
Core/Contents/Include/PolyEntity.h

@@ -647,13 +647,7 @@ namespace Polycode {
 			* If this flag is set to false, this entity will not check the depth buffer when it's rendering.
 			*/			
 			bool depthTest;
-			
-			/**
-			* Entity blending mode. Possible values are Renderer::BLEND_MODE_NONE, Renderer::BLEND_MODE_NORMAL, Renderer::BLEND_MODE_LIGHTEN, Renderer::BLEND_MODE_COLOR, Renderer::BLEND_MODE_PREMULTIPLIED, Renderer::BLEND_MODE_MULTIPLY. See the Renderer class for details on individual blending modes.
-                This blending mode is overridden by the material.
-			*/
-			int blendingMode;	
-			
+
 			/**
 			* If set to false, the children of this entity will not multiply by this entity's color. Set to true by default.
 			*/ 
@@ -694,8 +688,10 @@ namespace Polycode {
 			* @param newBlendingMode New blending mode to set. Possible values are Renderer::BLEND_MODE_NORMAL, Renderer::BLEND_MODE_LIGHTEN, Renderer::BLEND_MODE_COLOR, Renderer::BLEND_MODE_PREMULTIPLIED, Renderer::BLEND_MODE_MULTIPLY. See the Renderer class for details on individual blending modes.
 			* @see Renderer			
 			*/
-			void setBlendingMode(int newBlendingMode);
-			
+			void setBlendingMode(unsigned int newBlendingMode);
+
+			unsigned int getBlendingMode();
+        
             /**
              * Returns the first child entity that has the specified string id.
              * @param id Specified id to search for.

+ 19 - 1
Core/Contents/Include/PolyGPUDrawBuffer.h

@@ -26,6 +26,7 @@
 #include "PolyShader.h"
 #include "PolyRectangle.h"
 #include "PolyMaterial.h"
+#include "PolyColor.h"
 
 namespace Polycode {
     
@@ -37,9 +38,22 @@ namespace Polycode {
         bool alphaTest;
         bool backfaceCull;
         bool depthOnly;
+        unsigned int blendingMode;
         Color drawColor;
     };
     
+    class _PolyExport GPUShaderParam {
+    public:
+        ProgramParam *programParam;
+        LocalShaderParam *localParam;
+    };
+    
+    class _PolyExport GPUShaderAttribute {
+    public:
+        ProgramAttribute *programAttribute;
+        AttributeBinding *attributeBinding;
+    };
+    
     class _PolyExport GPUDrawCall {
     public:
         unsigned int numVertices;
@@ -49,11 +63,12 @@ namespace Polycode {
         GPUDrawOptions options;
         Matrix4 modelMatrix;
         Material *material;
+        std::vector<GPUShaderParam> shaderParams;
+        std::vector<GPUShaderAttribute> shaderAttributes;
         ShaderBinding *shaderBinding;
         IndexDataArray *indexArray;
     };
     
-    
     class _PolyExport GPUDrawBuffer {
     public:
         GPUDrawBuffer();
@@ -61,6 +76,9 @@ namespace Polycode {
         
         Matrix4 projectionMatrix;
         Matrix4 viewMatrix;
+        Color clearColor;
+        bool clearDepthBuffer;
+        bool clearColorBuffer;
         
         Polycode::Rectangle viewport;
         std::vector<GPUDrawCall> drawCalls;

+ 4 - 3
Core/Contents/Include/PolyOpenGLGraphicsInterface.h

@@ -58,14 +58,15 @@ namespace Polycode {
         
         void createTexture(Texture *texture, int filteringMode, int anisotropy, bool createMipmaps);
         void setViewport(unsigned int x,unsigned  int y,unsigned  int width, unsigned height);
-        void clearBuffers(bool colorBuffer, bool depthBuffer, bool stencilBuffer);
-        void setParamInShader(Shader *shader, const ProgramParam &param, LocalShaderParam *localParam);
-        void setAttributeInShader(Shader *shader, const ProgramAttribute &attribute, AttributeBinding *attributeBinding);
+        void clearBuffers(const Color &clearColor, bool colorBuffer, bool depthBuffer, bool stencilBuffer);
+        void setParamInShader(Shader *shader, ProgramParam *param, LocalShaderParam *localParam);
+        void setAttributeInShader(Shader *shader, ProgramAttribute *attribute, AttributeBinding *attributeBinding);
         void disableAttribute(Shader *shader, const ProgramAttribute &attribute);
         void useShader(Shader *shader);
         void createProgram(ShaderProgram *program);
         void createShader(Shader *shader);
         void beginDrawCall();
+        void setBlendingMode(unsigned int blendingMode);
         
         void drawIndices(int type, IndexDataArray *indexArray);
         void drawArrays(int type, unsigned int vertexCount);

+ 21 - 3
Core/Contents/Include/PolyRenderer.h

@@ -40,15 +40,16 @@ namespace Polycode {
     class _PolyExport GraphicsInterface : public PolyBase {
         public:
             GraphicsInterface();
-            virtual void setParamInShader(Shader *shader, const ProgramParam &param, LocalShaderParam *localParam) = 0;
-            virtual void setAttributeInShader(Shader *shader, const ProgramAttribute &attribute, AttributeBinding *attributeBinding) = 0;
+            virtual void setParamInShader(Shader *shader, ProgramParam *param, LocalShaderParam *localParam) = 0;
+            virtual void setAttributeInShader(Shader *shader, ProgramAttribute *attribute, AttributeBinding *attributeBinding) = 0;
             virtual void disableAttribute(Shader *shader, const ProgramAttribute &attribute) = 0;
             virtual void createTexture(Texture *texture, int filteringMode, int anisotropy, bool createMipmaps) = 0;
             virtual void setViewport(unsigned int x,unsigned  int y,unsigned  int width, unsigned height) = 0;
-            virtual void clearBuffers(bool colorBuffer, bool depthBuffer, bool stencilBuffer) = 0;
+            virtual void clearBuffers(const Color &clearColor, bool colorBuffer, bool depthBuffer, bool stencilBuffer) = 0;
             virtual void createProgram(ShaderProgram *program) = 0;
             virtual void createShader(Shader *shader) = 0;
             virtual void useShader(Shader *shader) = 0;
+            virtual void setBlendingMode(unsigned int blendingMode) = 0;
         
             virtual void drawIndices(int type, IndexDataArray *indexArray) = 0;
             virtual void drawArrays(int type, unsigned int vertexCount) = 0;
@@ -74,6 +75,13 @@ namespace Polycode {
         bool createMipmaps;
     };
     
+    class RenderThreadDebugInfo {
+        public:
+            unsigned int buffersProcessed;
+            unsigned int drawCallsProcessed;
+            unsigned int timeTaken;
+    };
+    
     class _PolyExport RenderThread : public Threaded {
         public:
             RenderThread();
@@ -82,8 +90,12 @@ namespace Polycode {
             void enqueueJob(int jobType, void *data);
             void processJob(const RendererThreadJob &job);
         
+            ShaderBinding *getShaderBinding();
+        
             void processDrawBuffer(GPUDrawBuffer *buffer);
         
+            RenderThreadDebugInfo getFrameInfo();
+        
             static const int JOB_REQUEST_CONTEXT_CHANGE = 0;
             static const int JOB_CREATE_TEXTURE = 1;
             static const int JOB_PROCESS_DRAW_BUFFER = 2;
@@ -91,7 +103,13 @@ namespace Polycode {
             static const int JOB_CREATE_PROGRAM = 4;
             static const int JOB_CREATE_SHADER = 5;
         
+        
         protected:
+        
+            unsigned int frameStart;
+            RenderThreadDebugInfo lastFrameDebugInfo;
+            RenderThreadDebugInfo currentDebugFrameInfo;
+        
             Core *core;
             RendererOptions options;
             CoreMutex *jobQueueMutex;

+ 1 - 1
Core/Contents/Include/PolySceneLabel.h

@@ -50,7 +50,7 @@ namespace Polycode {
 
             int getTextWidthForString(String text);
         
-			virtual ~SceneLabel();			
+			virtual ~SceneLabel();
 		
 			/**
 			* Sets new text for the labe.

+ 4 - 0
Core/Contents/Include/PolySceneMesh.h

@@ -225,6 +225,8 @@ namespace Polycode {
             bool backfaceCulled;
         
             bool sendBoneMatricesToMaterial;
+        
+            void cacheShaderParams();
 			
 		protected:
 		
@@ -235,6 +237,8 @@ namespace Polycode {
 			Skeleton *skeleton;
 			ShaderBinding *localShaderOptions;
             String fileName;
+            std::vector<GPUShaderParam> shaderParams;
+            std::vector<GPUShaderAttribute> shaderAttributes;
         
             std::vector<Matrix4> materialBoneMatrices;
         

+ 6 - 0
Core/Contents/Include/PolyShader.h

@@ -40,8 +40,11 @@ namespace Polycode {
 	class _PolyExport ProgramParam {
 		public:
 	
+        ProgramParam();
+        
         String name;
         int type;
+        void *platformData;
 
         static void *createParamData(int type);
         
@@ -57,8 +60,11 @@ namespace Polycode {
 	
     class _PolyExport ProgramAttribute {
         public:
+            ProgramAttribute();
+        
             int size;
             String name;
+            void *platformData;
     };
     
 	typedef struct {

+ 7 - 4
Core/Contents/Source/PolyEntity.cpp

@@ -60,9 +60,9 @@ void Entity::initEntity() {
 	billboardRoll = false;
 	billboardIgnoreScale = false;
 	drawCall.options.depthOnly = false;
+	drawCall.options.blendingMode = Entity::defaultBlendingMode;    
 	depthWrite = true;
 	ignoreParentMatrix = false;
-	blendingMode = Entity::defaultBlendingMode;
 	lockMatrix = false;
 	colorAffectsChildren = true;
 	visibilityAffectsChildren = true;
@@ -113,7 +113,6 @@ void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) co
 	clone->billboardRoll = billboardRoll;
 	clone->depthWrite = depthWrite;
 	clone->depthTest = depthTest;
-	clone->blendingMode = blendingMode;
 	clone->colorAffectsChildren = colorAffectsChildren;
 	clone->visibilityAffectsChildren = visibilityAffectsChildren;
 	clone->setUserData(getUserData());
@@ -336,8 +335,12 @@ void Entity::setColor(Number r, Number g, Number b, Number a) {
 	color.setColor(r,g,b,a);
 }
 
-void Entity::setBlendingMode(int newBlendingMode) {
-	blendingMode = newBlendingMode;
+void Entity::setBlendingMode(unsigned int newBlendingMode) {
+	drawCall.options.blendingMode = newBlendingMode;
+}
+
+unsigned int Entity::getBlendingMode() {
+    return drawCall.options.blendingMode;
 }
 
 Entity::~Entity() {

+ 46 - 18
Core/Contents/Source/PolyOpenGLGraphicsInterface.cpp

@@ -49,14 +49,11 @@ void OpenGLGraphicsInterface::setUniformMatrix(GLint paramLocation, const Polyco
 #endif
 }
 
-void OpenGLGraphicsInterface::setParamInShader(Shader *shader, const ProgramParam &param, LocalShaderParam *localParam) {
+void OpenGLGraphicsInterface::setParamInShader(Shader *shader, ProgramParam *param, LocalShaderParam *localParam) {
 
-    // TODO: ALSO DO NOT LOOK UP BY STRING!
+    GLuint paramLocation = *((GLuint*) param->platformData);
     
-    GLuint shaderID = *((GLuint*) shader->platformData);
-    int paramLocation = glGetUniformLocation(shaderID, param.name.c_str());
-    
-    switch(param.type) {
+    switch(param->type) {
         case ProgramParam::PARAM_NUMBER:
             if(localParam) {
                 glUniform1f(paramLocation, localParam->getNumber());
@@ -110,7 +107,7 @@ void OpenGLGraphicsInterface::setParamInShader(Shader *shader, const ProgramPara
             }
         break;
         case ProgramParam::PARAM_TEXTURE:
-            
+            glEnable(GL_TEXTURE_2D);
             glUniform1i(paramLocation, textureIndex);
             glActiveTexture(GL_TEXTURE0 + textureIndex);
             
@@ -129,6 +126,35 @@ void OpenGLGraphicsInterface::setParamInShader(Shader *shader, const ProgramPara
     }
 }
 
+void OpenGLGraphicsInterface::setBlendingMode(unsigned int blendingMode) {
+    if(blendingMode == Renderer::BLEND_MODE_NONE) {
+        glDisable(GL_BLEND);
+    } else {
+        glEnable(GL_BLEND);
+    }
+    
+    switch(blendingMode) {
+        case Renderer::BLEND_MODE_NORMAL:
+            glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+            break;
+        case Renderer::BLEND_MODE_LIGHTEN:
+            glBlendFunc (GL_SRC_ALPHA, GL_ONE);
+            break;
+        case Renderer::BLEND_MODE_COLOR:
+            glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR);
+            break;
+        case Renderer::BLEND_MODE_PREMULTIPLIED:
+            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+            break;
+        case Renderer::BLEND_MODE_MULTIPLY:
+            glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
+            break;
+        default:
+            glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+            break;
+    }
+}
+
 void OpenGLGraphicsInterface::beginDrawCall() {
     textureIndex = 0;
 }
@@ -138,20 +164,14 @@ void OpenGLGraphicsInterface::useShader(Shader *shader) {
     glUseProgram(shaderID);
 }
 
-void OpenGLGraphicsInterface::setAttributeInShader(Shader *shader, const ProgramAttribute &attribute, AttributeBinding *attributeBinding) {
-    // TODO: ALSO DO NOT LOOK UP BY STRING!
-    GLuint shaderID = *((GLuint*) shader->platformData);
-    int attribLocation = glGetAttribLocation(shaderID, attribute.name.c_str());
-    
+void OpenGLGraphicsInterface::setAttributeInShader(Shader *shader, ProgramAttribute *attribute, AttributeBinding *attributeBinding) {
+    GLuint attribLocation = *((GLuint*) attribute->platformData);
     glVertexAttribPointer(attribLocation, attributeBinding->vertexData->countPerVertex, GL_FLOAT, false, 0, attributeBinding->vertexData->data.data());
     glEnableVertexAttribArray(attribLocation);
 }
 
 void OpenGLGraphicsInterface::disableAttribute(Shader *shader, const ProgramAttribute &attribute) {
-    
-    // TODO: ALSO DO NOT LOOK UP BY STRING!
-    GLuint shaderID = *((GLuint*) shader->platformData);
-    int attribLocation = glGetAttribLocation(shaderID, attribute.name.c_str());
+    GLuint attribLocation = *((GLuint*) attribute.platformData);
     glDisableVertexAttribArray(attribLocation);
 }
 
@@ -363,8 +383,12 @@ void OpenGLGraphicsInterface::createShader(Shader *shader) {
         glGetActiveUniform(shaderID, GLuint(i), sizeof(name)-1, &name_len, &num, &type, name );
         name[name_len] = 0;
    
+        int paramLocation = glGetUniformLocation(shaderID, name);
+        
         ProgramParam param;
         param.name = String(name);
+        param.platformData = (void*) new GLuint;
+        *((GLuint*)param.platformData) = paramLocation;
         param.type = getPolycodeParamType(type);
         shader->expectedParams.push_back(param);
     }
@@ -381,8 +405,12 @@ void OpenGLGraphicsInterface::createShader(Shader *shader) {
         glGetActiveAttrib(shaderID, i, sizeof(name)-1, &name_len, &num, &type, name);
         name[name_len] = 0;
 
+        int attribLocation = glGetAttribLocation(shaderID, name);
+        
         ProgramAttribute attribute;
         attribute.name = String(name);
+        attribute.platformData = (void*) new GLuint;
+        *((GLuint*)attribute.platformData) = attribLocation;
         attribute.size = getAttributeSize(type);
         shader->expectedAttributes.push_back(attribute);
     }
@@ -409,7 +437,7 @@ void OpenGLGraphicsInterface::enableDepthWrite(bool val) {
     }
 }
 
-void OpenGLGraphicsInterface::clearBuffers(bool colorBuffer, bool depthBuffer, bool stencilBuffer) {
+void OpenGLGraphicsInterface::clearBuffers(const Color &clearColor, bool colorBuffer, bool depthBuffer, bool stencilBuffer) {
     GLbitfield clearMask = 0;
     
     if(colorBuffer) {
@@ -425,7 +453,7 @@ void OpenGLGraphicsInterface::clearBuffers(bool colorBuffer, bool depthBuffer, b
     }
     
     
-    glClearColor(0.5, 0.5, 0.5, 1.0);
+    glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
     glClear(clearMask);
 }
 

+ 27 - 51
Core/Contents/Source/PolyRenderer.cpp

@@ -67,10 +67,16 @@ void RenderThread::runThread() {
     }
 }
 
+ShaderBinding *RenderThread::getShaderBinding() {
+    return rendererShaderBinding;
+}
+
 void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
-    interface->setViewport(buffer->viewport.x, buffer->viewport.y, buffer->viewport.w, buffer->viewport.h);
-    interface->clearBuffers(true, true, true);
     
+    ++currentDebugFrameInfo.buffersProcessed;
+    
+    interface->setViewport(buffer->viewport.x, buffer->viewport.y, buffer->viewport.w, buffer->viewport.h);
+    interface->clearBuffers(buffer->clearColor, buffer->clearColorBuffer, buffer->clearDepthBuffer, true);
     
     projectionMatrixParam->setMatrix4(buffer->projectionMatrix);
     viewMatrixParam->setMatrix4(buffer->viewMatrix);
@@ -78,72 +84,31 @@ void RenderThread::processDrawBuffer(GPUDrawBuffer *buffer) {
     for(int i=0; i < buffer->drawCalls.size(); i++) {
         
         interface->beginDrawCall();
+        
+        interface->setBlendingMode(buffer->drawCalls[i].options.blendingMode);
         interface->enableDepthTest(buffer->drawCalls[i].options.depthTest);
         interface->enableDepthWrite(buffer->drawCalls[i].options.depthWrite);
         
         modelMatrixParam->setMatrix4(buffer->drawCalls[i].modelMatrix);
         
         if(buffer->drawCalls[i].material) {
-            ShaderBinding *localShaderBinding = buffer->drawCalls[i].shaderBinding;
             
             for(int s=0; s < buffer->drawCalls[i].material->getNumShaders(); s++) {
+        
+                ++currentDebugFrameInfo.drawCallsProcessed;
                 
                 Shader *shader = buffer->drawCalls[i].material->getShader(s);
-                
                 interface->useShader(shader);
                 
-                ShaderBinding *materialShaderBinding = buffer->drawCalls[i].material->getShaderBinding(s);
-
-                
-                // !!!!!!!!!!!!!!!!!!!!!!!!
-                // TODO: Don't do string lookups on every frame for all this stuff, find a better way!!
-                // !!!!!!!!!!!!!!!!!!!!!!!!
-                
                 // set shader uniforms
    
-                for(int p=0; p < shader->expectedParams.size(); p++) {
-                    ProgramParam param = shader->expectedParams[p];
-                    
-                    LocalShaderParam *localParam = NULL;
-                    localParam = rendererShaderBinding->getLocalParamByName(param.name);
-
-                    // material options override renderer options
-                    
-                    LocalShaderParam *materialOptionsParam = materialShaderBinding->getLocalParamByName(param.name);
-                    if(materialOptionsParam) {
-                        localParam = materialOptionsParam;
-                    }
-                    
-                    // local options override material options
-                    
-                    LocalShaderParam *localOptionsParam = localShaderBinding->getLocalParamByName(param.name);
-                    if(localOptionsParam) {
-                        localParam = localOptionsParam;
-                    }
-                    
-                    interface->setParamInShader(shader, param, localParam);
+                for(int p=0; p < buffer->drawCalls[i].shaderParams.size(); p++) {
+                    interface->setParamInShader(shader, buffer->drawCalls[i].shaderParams[p].programParam, buffer->drawCalls[i].shaderParams[p].localParam);
                     
                 }
                 
-                 for(int a=0; a < shader->expectedAttributes.size(); a++) {
-                     ProgramAttribute attribute = shader->expectedAttributes[a];
-                     
-                     
-                     AttributeBinding *attributeBinding = NULL;
-                     attributeBinding = materialShaderBinding->getAttributeBindingByName(attribute.name);
-                     
-                     // local options override material options
-                     
-                     AttributeBinding *localAttributeBinding = localShaderBinding->getAttributeBindingByName(attribute.name);
-                     
-                     if(localAttributeBinding) {
-                         attributeBinding = localAttributeBinding;
-                     }
-                     
-                     if(attributeBinding) {
-                         interface->setAttributeInShader(shader, attribute, attributeBinding);
-                     }
-
+                 for(int a=0; a < buffer->drawCalls[i].shaderAttributes.size(); a++) {
+                        interface->setAttributeInShader(shader, buffer->drawCalls[i].shaderAttributes[a].programAttribute,  buffer->drawCalls[i].shaderAttributes[a].attributeBinding);
                  }
                 
                 if(buffer->drawCalls[i].indexed) {
@@ -189,6 +154,13 @@ void RenderThread::processJob(const RendererThreadJob &job) {
         case JOB_FLUSH_CONTEXT:
         {
             core->flushRenderContext();
+            
+            currentDebugFrameInfo.timeTaken = Services()->getCore()->getTicks() - frameStart;
+            lastFrameDebugInfo = currentDebugFrameInfo;
+            currentDebugFrameInfo.buffersProcessed = 0;
+            currentDebugFrameInfo.drawCallsProcessed = 0;
+            currentDebugFrameInfo.timeTaken = 0;
+            frameStart = Services()->getCore()->getTicks();
         }
         break;
         case JOB_CREATE_PROGRAM:
@@ -206,6 +178,10 @@ void RenderThread::processJob(const RendererThreadJob &job) {
     }
 }
 
+RenderThreadDebugInfo RenderThread::getFrameInfo() {
+    return lastFrameDebugInfo;
+}
+
 void RenderThread::enqueueJob(int jobType, void *data) {
     Services()->getCore()->lockMutex(jobQueueMutex);
     RendererThreadJob job;

+ 3 - 0
Core/Contents/Source/PolyScene.cpp

@@ -222,6 +222,9 @@ void Scene::Render(Camera *targetCamera) {
         targetCamera = activeCamera;
     
     GPUDrawBuffer *drawBuffer = new GPUDrawBuffer();
+    drawBuffer->clearColor = clearColor;
+    drawBuffer->clearColorBuffer = useClearColor;
+    drawBuffer->clearDepthBuffer = useClearDepth;
     
     drawBuffer->viewport = targetCamera->getViewport();
 ///    drawBuffer->projectionMatrix = targetCamera->

+ 1 - 1
Core/Contents/Source/PolySceneEntityInstance.cpp

@@ -532,7 +532,7 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit
 
 
 	if(!targetEntity) {	
-		entity->blendingMode = (*entry)["blendMode"]->intVal;
+		entity->setBlendingMode((*entry)["blendMode"]->intVal);
 
         entity->setScale((*entry)["sX"]->NumberVal, (*entry)["sY"]->NumberVal, (*entry)["sZ"]->NumberVal);
         entity->setPosition((*entry)["pX"]->NumberVal, (*entry)["pY"]->NumberVal, (*entry)["pZ"]->NumberVal);

+ 10 - 8
Core/Contents/Source/PolySceneLabel.cpp

@@ -97,6 +97,7 @@ Number SceneLabel::getLabelActualHeight() {
     return actualHeight;
 }
 
+
 void SceneLabel::updateFromLabel() {
 
 	MaterialManager *materialManager = CoreServices::getInstance()->getMaterialManager();
@@ -109,18 +110,19 @@ void SceneLabel::updateFromLabel() {
 		texture = materialManager->createTextureFromImage(label, materialManager->clampDefault, false);		
 	}
 
-    // RENDERER_TODO
-    /*
-	if(material) {
-		localShaderOptions->clearTexture("diffuse");
-		localShaderOptions->addTexture("diffuse", texture);	
-	}
-     */
-
 	setPrimitiveOptions(type, label->getWidth()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(),label->getHeight()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
 	
     setLocalBoundingBox(label->getWidth()*labelScale / CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(), label->getHeight()*labelScale/ CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(), 0.001);
     
+    
+    if(localShaderOptions) {
+        LocalShaderParam *diffuseParam = localShaderOptions->getLocalParamByName("diffuse");
+        if(!diffuseParam) {
+            diffuseParam = localShaderOptions->addParam(ProgramParam::PARAM_TEXTURE, "diffuse");
+        }
+        diffuseParam->setTexture(texture);
+    }
+    
         // RENDERER_TODO
     /*
 	if(useVertexBuffer)

+ 74 - 0
Core/Contents/Source/PolySceneMesh.cpp

@@ -58,6 +58,7 @@ SceneMesh::SceneMesh(const String& fileName) : Entity(), texture(NULL), material
     backfaceCulled = true;
 	alphaTest = false;
     sendBoneMatricesToMaterial = false;
+    setMaterialByName("Unlit");
 }
 
 SceneMesh::SceneMesh(Mesh *mesh) : Entity(), texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL), skeletalVertexPositions(3, RenderDataArray::VERTEX_DATA_ARRAY), skeletalVertexNormals(3, RenderDataArray::NORMAL_DATA_ARRAY) {
@@ -76,6 +77,7 @@ SceneMesh::SceneMesh(Mesh *mesh) : Entity(), texture(NULL), material(NULL), skel
     backfaceCulled = true;
 	alphaTest = false;
     sendBoneMatricesToMaterial = false;
+    setMaterialByName("Unlit");
 }
 
 SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL), skeletalVertexPositions(3, RenderDataArray::VERTEX_DATA_ARRAY), skeletalVertexNormals(3, RenderDataArray::NORMAL_DATA_ARRAY) {
@@ -92,6 +94,7 @@ SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL), skeleton(NUL
     backfaceCulled = true;
 	alphaTest = false;
     sendBoneMatricesToMaterial = false;
+    setMaterialByName("Unlit");    
 }
 
 void SceneMesh::setMesh(Mesh *mesh) {
@@ -333,6 +336,74 @@ bool SceneMesh::customHitDetection(const Ray &ray) {
 	return false;
 }
 
+void SceneMesh::cacheShaderParams() {
+    
+    shaderParams.clear();
+    shaderAttributes.clear();
+    
+    if(!material) {
+        return;
+    }
+    
+    if(material->getNumShaders() == 0) {
+        return;
+    }
+    
+    // TODO: do this for every shader
+    
+    Shader *shader = material->getShader(0);
+    ShaderBinding *materialShaderBinding = material->getShaderBinding(0);
+    ShaderBinding *rendererShaderBinding = Services()->getRenderer()->getRenderThread()->getShaderBinding();
+    
+    for(int p=0; p < shader->expectedParams.size(); p++) {
+        
+        LocalShaderParam *localParam = NULL;
+        localParam = rendererShaderBinding->getLocalParamByName(shader->expectedParams[p].name);
+        
+        // material options override renderer options
+        
+        LocalShaderParam *materialOptionsParam = materialShaderBinding->getLocalParamByName(shader->expectedParams[p].name);
+        if(materialOptionsParam) {
+            localParam = materialOptionsParam;
+        }
+        
+        // local options override material options
+        LocalShaderParam *localOptionsParam = localShaderOptions->getLocalParamByName(shader->expectedParams[p].name);
+        if(localOptionsParam) {
+            localParam = localOptionsParam;
+        }
+        
+        GPUShaderParam shaderParam;
+        shaderParam.programParam = &shader->expectedParams[p];
+        shaderParam.localParam = localParam;
+        shaderParams.push_back(shaderParam);
+        
+    }
+    
+    for(int a=0; a < shader->expectedAttributes.size(); a++) {
+        
+        AttributeBinding *attributeBinding = NULL;
+        attributeBinding = materialShaderBinding->getAttributeBindingByName(shader->expectedAttributes[a].name);
+        
+        // local options override material options
+        
+        AttributeBinding *localAttributeBinding = localShaderOptions->getAttributeBindingByName(shader->expectedAttributes[a].name);
+        
+        if(localAttributeBinding) {
+            attributeBinding = localAttributeBinding;
+        }
+        
+        if(attributeBinding) {
+            GPUShaderAttribute attribute;
+            attribute.attributeBinding = attributeBinding;
+            attribute.programAttribute = &shader->expectedAttributes[a];
+            shaderAttributes.push_back(attribute);
+        }
+        
+    }
+    
+}
+
 void SceneMesh::Render(GPUDrawBuffer *buffer) {
     
     drawCall.options.alphaTest = alphaTest;
@@ -357,6 +428,9 @@ void SceneMesh::Render(GPUDrawBuffer *buffer) {
     drawCall.material = material;
     drawCall.shaderBinding = localShaderOptions;
     
+    drawCall.shaderParams = shaderParams;
+    drawCall.shaderAttributes = shaderAttributes;
+    
     buffer->drawCalls.push_back(drawCall);
     
     /*

+ 7 - 0
Core/Contents/Source/PolyShader.cpp

@@ -29,6 +29,13 @@ ShaderRenderTarget::ShaderRenderTarget() : PolyBase() {
 	texture = NULL;
 }
 
+ProgramParam::ProgramParam() : type(PARAM_UNKNOWN), platformData(NULL) {
+}
+
+ProgramAttribute::ProgramAttribute() : platformData(NULL) {
+    
+}
+
 void *ProgramParam::createParamData(int type) {
 	switch (type) {
 		case PARAM_NUMBER:

BIN
Examples/C++/Resources/default.pak