PDA

View Full Version : how to make my vas to vars ?



HamsterofDeath
12-31-2003, 04:41 AM
at first, another question. will this work ?
(i'm using gl4java, just ignore the gl.* and glEnum.*)




public void setStates(GLFunc gl)
{
gl.glEnableClientState(GLEnum.GL_VERTEX_ARRAY);
if (hasNormals)
{
gl.glEnableClientState(GLEnum.GL_NORMAL_ARRAY);
}
if (hasColors)
{
gl.glEnableClientState(GLEnum.GL_COLOR_ARRAY);
}
if (hasFog)
{
gl.glEnableClientState(GLEnum.GL_FOG_COORDINATE_AR RAY_EXT);
}
if (hasUnit0TexCoords)
{
gl.glActiveTexture(0);
gl.glEnableClientState(GLEnum.GL_TEXTURE_COORD_ARR AY);
}
if (hasUnit1TexCoords)
{
gl.glActiveTexture(1);
gl.glEnableClientState(GLEnum.GL_TEXTURE_COORD_ARR AY);
}
if (hasUnit1TexCoords)
{
gl.glActiveTexture(2);
gl.glEnableClientState(GLEnum.GL_TEXTURE_COORD_ARR AY);
}
if (hasUnit1TexCoords)
{
gl.glActiveTexture(3);
gl.glEnableClientState(GLEnum.GL_TEXTURE_COORD_ARR AY);
}
}

or do i have to use glActiveTextureARB ? whats the difference ?

---
next question : i already have working vertex arrays. how can i make them faster by using vars ?
can i still manipulate single elements inside this array ?
-----
final question :
when i'm done, i want to use an interleaved array, storing all data that is needed, making use of indexed access, AND use all this as a var.
is it possible, and if yes, how ?

Jan
12-31-2003, 05:39 AM
Donīt use VAR, itīs outdated.

Use VBO (Vertex Buffer Objects) instead. Itīs much easier to implement, itīs an ARB extension and itīs the way drivers like the data most (because the drivers optimize it most, VAR will certainly get dropped in the near future.

Here is some information on VBO: http://developer.nvidia.com/object/using_VBOs.html

Jan.

HamsterofDeath
12-31-2003, 05:56 AM
i thought var and vbo is the same...

well, ok....


[This message has been edited by HamsterofDeath (edited 12-31-2003).]

zeckensack
12-31-2003, 05:57 AM
Three issues with your coude:
1)Earlier calls to setstate() may have left some arrays enabled, so you must make sure to disable them if they're not needed.


public void setStates(GLFunc gl)
{
gl.glEnableClientState(GLEnum.GL_VERTEX_ARRAY);
if (hasNormals)
{
gl.glEnableClientState(GLEnum.GL_NORMAL_ARRAY);
}
else
{
gl.glDisableClientState(GLEnum.GL_NORMAL_ARRAY);
}
.
.
.

2)For setting array pointers and enables, you need to use glClientActiveTexture. glActiveTexture (w/o Client) routes texture bindings and texture environment state, not vertex array state.


if (hasUnit0TexCoords)
{
gl.glClientActiveTexture(0);
gl.glEnableClientState(GLEnum.GL_TEXTURE_COORD_ARR AY);
}
This will most likely require changes to other places in your code, wherever you set your texture coord pointers.

3)"if (hasUnit1TexCoords)" occurs three times. C&P related typos, I guess http://www.opengl.org/discussion_boards/ubb/smile.gif

HamsterofDeath
12-31-2003, 06:32 AM
1) i know. i have a disableStates()-function that is called after drawing
2) thx
3) c&p = evil, but : no, this is the only place where i set texture pointers so far
-----
2 questions remain :
1. is there a small example creating a vbo, and manipulating vertex data inside the array ? is the usage of vbos equal when using ati/nvidia-cards ?
2. i've build an interleaved array out of my vertex/normal/color etc.-arrays

when telling opengl what the gaps between the elements are, i have to use



void glVertexPointer(
GLint size,
GLenum type,
GLsizei stride,
const GLvoid *pointer)


in my case, gl.glVertexPointer(3,GL_FLOAT,?,myarray);

3 is for 3 floats, x,y & z coordinate
float means, the data is stored in floats
? is what i don't know.
is it the number of array indices i'll have to add until i get from my old z to the next x ? or is it the number of floats between the old z and the new x ?
if i store x,y,z,texx,texy,x2,y2,z2,texx2,texy2, is the stride value 2 or 3 ?

01-01-2004, 08:31 AM
The only drawback of VBO : you need quite newer drivers (from about august 2003).

VBO is completely independant of the hardware from the programmer point of view, so use them to get the most of the drivers' optimizations.