For my particle system I have recently switched over to SoA format to use SIMD improvements. Originally I used a vector filled with vertices for the buffer.
class XY
{
public:
float x1; float y1;
float x2; float y2;
float x3; float y3;
float x4; float y4;
};
This worked fine and dandy when I was using just vectors to hold all the data of my particles. But when I switched over, I needed to change that to SIMD SoA format so I didn't hurt the calculation speed.
class XY_SSE
{
public:
float *x1; float *y1;
float *x2; float *y2;
float *x3; float *y3;
float *x4; float *y4;
public:
XY_SSE()
{
x1 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
x2 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
x3 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
x4 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
y1 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
y2 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
y3 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
y4 = (float*)_mm_malloc(MAX_PARTICLES * sizeof(float), BOUNDARY_ALIGNMENT);
}
~XY_SSE()
{
_mm_free(x1);
_mm_free(x2);
_mm_free(x3);
_mm_free(x4);
_mm_free(y1);
_mm_free(y2);
_mm_free(y3);
_mm_free(y4);
}
};
Now the only problem is giving the coordinate data to the buffer. For some reason, I cannot get it to work.
glEnable(GL_BLEND);
glColor4f(1.0, 1.0, 1.0, cprf_Blend_I);
glBindTexture(GL_TEXTURE_2D, Type.TexNum->imageDataNear);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glGenBuffersARB( 1, &m_nVBOVertices );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
//glBufferDataARB( GL_ARRAY_BUFFER_ARB, pSize, &VBOVertices[0], GL_STREAM_DRAW_ARB ); this was the original way of doing things, VBOVerticies is just an std::vector<XY>
glBufferDataARB( GL_ARRAY_BUFFER_ARB, pSize, &vSSE, GL_STREAM_DRAW_ARB );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
glVertexPointer( 2, GL_FLOAT, 0, 0 );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords );
glTexCoordPointer( 2, GL_FLOAT, 0, 0 );
glDrawArrays( GL_QUADS, 0, pSize4);
glDeleteBuffersARB(1, &m_nVBOVertices);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisable(GL_BLEND);
vSSE is an XY_SSE SoA. I have tried everything from just vSSE, &vSSE, &*vSSE, &vSSE->x[0], &vSSE[0] and none work. Some give me very weird results of odd shaped squares that extend way past the edge of the screen.
Any advice on how to get this to work properly would be very appreciated.
Jake
[Edited by - jake_Ghost on June 29, 2008 11:21:47 AM]