static/local array


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::Draw() 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
 
Ad

Advertisements

C

Chris Forone

ok, i now use the new std::array<float, 16> and it works perfect. thanks
a lot!

cheers, chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top