By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,193 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,193 IT Pros & Developers. It's quick & easy.

Unions and Pointer

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"whisper" <ml**********@yahoo.com.br> wrote in message
news:6a**************************@posting.google.c om...
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)
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 23 '05 #2

P: n/a
whisper wrote:
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.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.