Procházet zdrojové kódy

Arrays of non-struct data params work

Marko Pintera před 13 roky
rodič
revize
5ab4c6ed7e

+ 6 - 3
CamelotClient/CamelotClient.cpp

@@ -161,7 +161,7 @@ int CALLBACK WinMain(
 																				\
 							 uniform mainFragBlock								\
 							 {													\
-							 float test1;										\
+							 float test1[2];									\
 							 InputStruct input[2];								\
 							 mat4 matViewProjection;							\
 							 float test2;										\
@@ -171,8 +171,8 @@ int CALLBACK WinMain(
 							 out vec2 texcoord0; \
 							 void main() \
 							 { \
-								texcoord0 = cm_texcoord0 * input[1].uvMultiplier; \
-								gl_Position = cm_position * (matViewProjection * input[1].matMultiplier[1]); \
+							 texcoord0 = cm_texcoord0 * test1[0]; \
+							 gl_Position = cm_position * (matViewProjection * test1[1]); \
 							 }";
 
 	HighLevelGpuProgramHandle vertProgRef= HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
@@ -196,6 +196,7 @@ int CALLBACK WinMain(
 
 #if defined GL
 	testShader->addParameter("input", "input", GPDT_STRUCT, 2, 12);
+	testShader->addParameter("test1", "test1", GPDT_FLOAT1, 2);
 #endif
 
 	testShader->addParameter("samp", "samp", GPOT_SAMPLER2D);
@@ -251,6 +252,8 @@ int CALLBACK WinMain(
 
 	testMaterial->setStructData("input", dbgMultipliers1, sizeof(dbgMultipliers1), 0);
 	testMaterial->setStructData("input", dbgMultipliers2, sizeof(dbgMultipliers2), 1);
+	testMaterial->setFloat("test1", 1.0f, 0);
+	testMaterial->setFloat("test1", 1.0f, 1);
 #endif
 
 	//testMaterialRef = gResources().load("C:\\testMaterial.mat");

+ 12 - 2
CamelotGLRenderer/Source/GLSL/include/CmGLSLParamParser.h

@@ -225,7 +225,7 @@ namespace CamelotEngine
 				}
 			}
 			
-			String cleanParamName = nameElements[nameElements.size() - 1]; // Param name without namespaces or array indexes
+			String cleanParamName = paramName; // Param name without array indexes
 
 			// Check if the parameter is in an array
 			UINT32 arrayIdx = 0;
@@ -307,11 +307,21 @@ namespace CamelotEngine
 			}
 			else
 			{
+				// If array index is larger than 0 and uniform is not a part of a struct,
+				// it means we already processed it (struct arrays are processed differently)
+				if(!inStruct && arrayIdx != 0)
+					continue;
+
 				GLint blockIndex;
 				glGetActiveUniformsiv(glProgram, 1, &index, GL_UNIFORM_BLOCK_INDEX, &blockIndex);
 
 				GpuParamDataDesc gpuParam;
-				gpuParam.name = paramName;
+
+				if(isInArray)
+					gpuParam.name = cleanParamName;
+				else
+					gpuParam.name = paramName;
+
 				determineParamInfo(gpuParam, paramName, glProgram, index);
 
 				if(blockIndex != -1)