Unions and Pointer

W

whisper

Hello all,

I'm trying to use a class from Intel called SPVector3.
It hass some optimiztions for Vector Math that uses SSE.

The problem is that its declared like this:

class SPVector3 {
public:
union {
__m128 vec;
struct {
float x,y,z;
// float _spacer_;
};
};

SPVector3() {}
SPVector3(const SPVector3& v) : vec(v.vec) {}
SPVector3(const __m128 &m) : vec(m) {}
SPVector3(const F32vec4 &m) : vec(m) {}
SPVector3(const float x, const float y, const float z) :
vec(F32vec4(0.0f,z,y,x)) {}
SPVector3(const float *arr) :
vec(_mm_loadl_pi(_mm_movelh_ps(_mm_load_ss(arr+2),_mm_load_ss(arr+2)),
(__m64*)arr)) {}
operator __m128() const { return vec; }
operator F32vec4() const { return vec; }

// functions and operators...
};

But I need to pass a pointer to an opengl fuction that looks like:

void glVertexPointer(
GLint size, //The number of coordinates per vertex
GLenum type, //The data type of each coordinate in the array
GLsizei stride, //The byte offset between consecutive vertices
const GLvoid *pointer
);

How can I convert from SPVector3 to this pointer ?

wpr
 
I

Ivan Vecerina

whisper said:
I'm trying to use a class from Intel called SPVector3.
It hass some optimiztions for Vector Math that uses SSE.

The problem is that its declared like this:

class SPVector3 {
public:
union {
__m128 vec;
struct {
float x,y,z;
// float _spacer_;
};
}; ....
};

But I need to pass a pointer to an opengl fuction that looks like:

void glVertexPointer(
GLint size, //The number of coordinates per vertex
GLenum type, //The data type of each coordinate in the array
GLsizei stride, //The byte offset between consecutive vertices
const GLvoid *pointer
);
This should not be a problem (leaving portability aside).
My guess would be to try:
- size = 3.
- type = GL_FLOAT or something like that.
- stride = sizeof(SPVector3)
- pointer = address of the first element (or & firstElem->x)
 
R

Rolf Magnus

whisper said:
Hello all,

I'm trying to use a class from Intel called SPVector3.
It hass some optimiztions for Vector Math that uses SSE.

The problem is that its declared like this:

class SPVector3 {
public:
union {
__m128 vec;
struct {
float x,y,z;
// float _spacer_;
};
};

SPVector3() {}
SPVector3(const SPVector3& v) : vec(v.vec) {}
SPVector3(const __m128 &m) : vec(m) {}
SPVector3(const F32vec4 &m) : vec(m) {}
SPVector3(const float x, const float y, const float z) :
vec(F32vec4(0.0f,z,y,x)) {}
SPVector3(const float *arr) :
vec(_mm_loadl_pi(_mm_movelh_ps(_mm_load_ss(arr+2),_mm_load_ss(arr+2)),
(__m64*)arr)) {}
operator __m128() const { return vec; }
operator F32vec4() const { return vec; }

// functions and operators...
};

But I need to pass a pointer to an opengl fuction that looks like:

void glVertexPointer(
GLint size, //The number of coordinates per vertex
GLenum type, //The data type of each coordinate in the array
GLsizei stride, //The byte offset between consecutive vertices
const GLvoid *pointer
);

How can I convert from SPVector3 to this pointer ?

SPVector3 only contains one vector, not an array of vectors, which would be
what glVertexPointer expects, unless you really want an array with only one
single vector. If you have an array of SPVector3, you should be able to do:

glVertexPointer(3, GL_FLOAT, sizeof(SPVector3), yourarray);

Btw, I'd say this is more an OpenGL question than a standard C++ question,
so x-post and f'up2 comp.graphics.api.opengl.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top