__pLight = new (std::nothrow) Light(*pLight);
}
}
+
+ _LightImpl* pLightImpl = _LightImpl::GetInstance(*__pLight);
+
+ float position[4];
+ float* pPosition = pLightImpl->GetPosition();
+
+ position[0] = (__transform.matrix[0][0] * pPosition[0]) + (__transform.matrix[1][0] * pPosition[1]) +
+ (__transform.matrix[2][0] * pPosition[2]) + (__transform.matrix[3][0] * pPosition[3]);
+ position[1] = (__transform.matrix[0][1] * pPosition[0]) + (__transform.matrix[1][1] * pPosition[1]) +
+ (__transform.matrix[2][1] * pPosition[2]) + (__transform.matrix[3][1] * pPosition[3]);
+ position[2] = (__transform.matrix[0][2] * pPosition[0]) + (__transform.matrix[1][2] * pPosition[1]) +
+ (__transform.matrix[2][2] * pPosition[2]) + (__transform.matrix[3][2] * pPosition[3]);
+ position[3] = (__transform.matrix[0][3] * pPosition[0]) + (__transform.matrix[1][3] * pPosition[1]) +
+ (__transform.matrix[2][3] * pPosition[2]) + (__transform.matrix[3][3] * pPosition[3]);
+
+ pLightImpl->SetWorldPosition(position);
+ }
+ else
+ {
+ delete __pLight;
+ __pLight = null;
}
Material* pMaterial =element.GetSharedData().geometry.GetMaterial();
}
}
}
+ else
+ {
+ delete __pMaterial;
+ __pMaterial = null;
+ }
if (element.__decomposedMatrixToTop.GetMatrixType() >= MATRIX4_Scale || __pMesh)
{
, __pIndices(null)
, __vertexCount(0)
, __pProgram(null)
- , __uMVP(-1)
- , __uOpacity(-1)
- , __uColor(-1)
, __aPosition(-1)
, __aTexCoord(-1)
, __aColor(-1)
_ShaderProgramImpl* pProgramImpl = _ShaderProgramImpl::GetInstance(*__pProgram);
- __uMVP = pProgramImpl->__uniformLocation[UNIFORM_MAT4_MVP];
- __uOpacity = pProgramImpl->__uniformLocation[UNIFORM_FLOAT_OPACITY];
- __uColor = pProgramImpl->__uniformLocation[UNIFORM_VEC4_COLOR];
-
__aPosition = pProgramImpl->__attributeLocation[ATTRIBUTE_VEC4_POSITION];
__aTexCoord = pProgramImpl->__attributeLocation[ATTRIBUTE_VEC2_TEXTURE_COORD];
__aColor = pProgramImpl->__attributeLocation[ATTRIBUTE_VEC4_COLOR];
__pGlContext->UseShaderProgram(__pRenderQueue[i].__pProgram);
- // Set uniform
- glUniformMatrix4fv(__pRenderQueue[i].__uMVP, 1, GL_FALSE, __pRenderQueue[i].__mvp.GetItems());
- glUniform1f(__pRenderQueue[i].__uOpacity, __pRenderQueue[i].__opacity);
- glUniform4f(__pRenderQueue[i].__uColor, __pRenderQueue[i].__objectColor.Red(), __pRenderQueue[i].__objectColor.Green(),
- __pRenderQueue[i].__objectColor.Blue(), __pRenderQueue[i].__objectColor.Alpha());
-
- glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__modelview.GetItems());
- glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_INV_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__invModelview.GetItems());
-
// Set attribute
glVertexAttribPointer(__pRenderQueue[i].__aPosition, 3, GL_FLOAT, GL_FALSE, VERTEX_BUFFER_STRIDE * sizeof(float), __pRenderQueue[i].__pVertices);
glVertexAttribPointer(__pRenderQueue[i].__aTexCoord, 2, GL_FLOAT, GL_FALSE, TEX_COORD_BUFFER_STRIDE * sizeof(float), __pRenderQueue[i].__pTexCoords);
glVertexAttribPointer(__pRenderQueue[i].__aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), __pRenderQueue[i].__pColors);
glVertexAttribPointer(__pRenderQueue[i].__aNormal, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), __pRenderQueue[i].__pNormals);
+ // Set uniform
+ glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MVP], 1, GL_FALSE, __pRenderQueue[i].__mvp.GetItems());
+ glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_OPACITY], __pRenderQueue[i].__opacity);
+ glUniform4f(pProgramImpl->__uniformLocation[UNIFORM_VEC4_COLOR], __pRenderQueue[i].__objectColor.Red(), __pRenderQueue[i].__objectColor.Green(),
+ __pRenderQueue[i].__objectColor.Blue(), __pRenderQueue[i].__objectColor.Alpha());
+
+ glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__modelview.GetItems());
+ glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_INV_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__invModelview.GetItems());
+
if (__pRenderQueue[i].__pLight)
{
_LightImpl* pLightImpl = _LightImpl::GetInstance(*__pRenderQueue[i].__pLight);
glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_AMBIENT], 1, pLightImpl->GetAmbient());
glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_DIFFUSE], 1, pLightImpl->GetDiffuse());
glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_SPECULAR], 1, pLightImpl->GetSpecular());
- glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_POSITION], 1, pLightImpl->GetPosition());
+ glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_POSITION], 1, pLightImpl->GetWorldPosition());
glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_DIRECTION], 1, pLightImpl->GetDirection());
glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_EXPONENT], pLightImpl->GetExponent());
glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_CUTOFF], pLightImpl->GetCutOff());
__specular[0] = 1.0f; __specular[1] = 1.0f; __specular[2] = 1.0f; __specular[3] = 1.0f;
__position[0] = 0.0f; __position[1] = 0.0f; __position[2] = 1.0f; __position[3] = 0.0f;
- __direction[0] = 0.0f; __direction[1] = 0.0f; __direction[2] = -1.0f;
+ __worldPosition[0] = 0.0f; __worldPosition[1] = 0.0f; __worldPosition[2] = 1.0f; __worldPosition[3] = 0.0f;
+ __direction[0] = 0.0f; __direction[1] = 0.0f; __direction[2] = -1.0f;
__attenuation[0] = 1.0f; __attenuation[1] = 0.0f; __attenuation[2] = 0.0f;
}
memcpy(__specular, src.__specular, sizeof(__specular));
memcpy(__position, src.__position, sizeof(__position));
- memcpy(__direction, src.__direction, sizeof(__direction));
+ memcpy(__worldPosition, src.__worldPosition, sizeof(__worldPosition));
+ memcpy(__direction, src.__direction, sizeof(__direction));
memcpy(__attenuation, src.__attenuation, sizeof(__attenuation));
}
return (float*)__position;
}
+float
+_LightImpl::SetWorldPosition(const float position[4])
+{
+ __worldPosition[0] = position[0];
+ __worldPosition[1] = position[1];
+ __worldPosition[2] = position[2];
+ __worldPosition[3] = position[3];
+}
+
+float*
+_LightImpl::GetWorldPosition(void) const
+{
+ return (float*)__worldPosition;
+}
+
void
_LightImpl::SetDirection(const float direction[3])
{