C
Chris Forone
hello,
i have some strange behavior in my multithreaded app. i do some
matrix-multiplications in a methode. if i use local arrays there it
works, but if i use a static member array (some kind of reusable array)
it doesnt work anymore. some code snippets:
[matrix multiplication]
template <typename T>
inline void MultiplyMatrix(T(&first)[16], T(&second)[16])
{
GLfloat result[16];
for (std::size_t i(0); i < 16; i += 4)
for (std::size_t j(0); j < 4; ++j)
result[i + j] = first * second[j]
+ first[i + 1] * second[j + 4]
+ first[i + 2] * second[j + 8]
+ first[i + 3] * second[j + 12];
std::copy(result, result + 16, first);
}
[here i use matrix multiplication, write to local/static array]
void Object:raw() const
{
GLfloat localTempMatrix[] =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
localTempMatrix[12] = position[Coordinate::X];
localTempMatrix[13] = position[Coordinate::Y];
MultiplyMatrix(localTempMatrix, projectionMatrix);
GLint programId(0);
glGetIntegerv(GL_CURRENT_PROGRAM, &programId);
glUniformMatrix4fv(glGetUniformLocation(programId, "matrix"), 1,
GL_FALSE, localTempMatrix);
....
}
thanks a lot!
cheers, chris
i have some strange behavior in my multithreaded app. i do some
matrix-multiplications in a methode. if i use local arrays there it
works, but if i use a static member array (some kind of reusable array)
it doesnt work anymore. some code snippets:
[matrix multiplication]
template <typename T>
inline void MultiplyMatrix(T(&first)[16], T(&second)[16])
{
GLfloat result[16];
for (std::size_t i(0); i < 16; i += 4)
for (std::size_t j(0); j < 4; ++j)
result[i + j] = first * second[j]
+ first[i + 1] * second[j + 4]
+ first[i + 2] * second[j + 8]
+ first[i + 3] * second[j + 12];
std::copy(result, result + 16, first);
}
[here i use matrix multiplication, write to local/static array]
void Object:raw() const
{
GLfloat localTempMatrix[] =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
localTempMatrix[12] = position[Coordinate::X];
localTempMatrix[13] = position[Coordinate::Y];
MultiplyMatrix(localTempMatrix, projectionMatrix);
GLint programId(0);
glGetIntegerv(GL_CURRENT_PROGRAM, &programId);
glUniformMatrix4fv(glGetUniformLocation(programId, "matrix"), 1,
GL_FALSE, localTempMatrix);
....
}
thanks a lot!
cheers, chris