Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   static/local array (http://www.velocityreviews.com/forums/t956389-static-local-array.html)

Chris Forone 01-10-2013 09:03 AM

static/local array
 
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[i] * 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

Chris Forone 01-10-2013 10:28 AM

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

cheers, chris


All times are GMT. The time now is 12:49 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.