DGL
https://delphigl.com/forum/

glVertexPointer, glNormalPointer and glTexCoordPointer
https://delphigl.com/forum/viewtopic.php?f=19&t=4172
Seite 1 von 1

Autor:  McCLaw [ Do Mai 19, 2005 22:07 ]
Betreff des Beitrags:  glVertexPointer, glNormalPointer and glTexCoordPointer

Hi All

Is is possible to use the above mentioned functions with arrays of pointers?

EG:

Code:
  1.  
  2.     glEnableClientState(GL_VERTEX_ARRAY);
  3.     glEnableClientState(GL_NORMAL_ARRAY);
  4.     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  5.       glVertexPointer(3, GL_FLOAT, 0, lSubMesh.Vertices);
  6.       glNormalPointer(GL_FLOAT,0,lSubMesh.Normals);
  7.       glTexCoordPointer(3,GL_FLOAT,0,lSubMesh.TexCoords);
  8.  
  9.       glDrawElements(GL_TRIANGLES,Length(lSubMesh.Indices),GL_UNSIGNED_INT,lSubMesh.Indices);
  10.  
  11.     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  12.     glDisableClientState(GL_NORMAL_ARRAY);
  13.     glDisableClientState(GL_VERTEX_ARRAY);
  14.  


Where lSubMesh.Vertices, lSubMesh.Normals and lSubMesh.TexCoords are defined as :

Code:
  1.  
  2. TAVectorArray = Array of TAffineVector;
  3. TPAVectorArray = Array of PAffineVector;
  4. PAVectorArray = ^TAVectorArray;
  5.  
  6. FTexCoords : TPAVectorArray;
  7. FVertices : TPAVectorArray;
  8. FNormals : TPAVectorArray;
  9.  


And the Arrays are populated like this:

Code:
  1.  
  2. procedure TRGLSubMesh.ChangePointerArrays(aVertices, aNormals,
  3.   aTexCoords: PAVectorArray);
  4. var
  5.   lFace : TRGLFace;
  6.   i, lIndex : Integer;
  7. begin
  8.   lFace := Faces.Face[Faces.Count - 1];
  9.   for i := 0 to 2 do
  10.   begin
  11.     lIndex := Length(FTexCoords);
  12.     SetLength(FTexCoords,Length(FTexCoords) + 1);
  13.     SetLength(FVertices,Length(FVertices) + 1);
  14.     SetLength(FNormals,Length(FNormals) + 1);
  15.     SetLength(FIndices,Length(FIndices) + 1);
  16.     FTexCoords[lIndex] := @aTexCoords^[lFace.TextureIndexes[i]];
  17.     FNormals[lIndex] := @aNormals^[lFace.NormalIndexes[i]];
  18.     FVertices[lIndex] := @aVertices^[lFace.VerticeIndexs[i]];
  19.     FIndices[lIndex] := lIndex;
  20.   end;
  21. end;
  22.  


Any help or guidance would be greatly appreciated :)

Autor:  Tokter [ Do Mai 19, 2005 23:22 ]
Betreff des Beitrags: 

glVertexPointer expects to get the address of your first vertex and not the address of a pointer that points to the vertex. Unless I misunderstood your problem, I don't think that's possible.

Autor:  AL [ Sa Mai 21, 2005 16:20 ]
Betreff des Beitrags: 

Tokter is right. It doesn't work. Those functions want their data in one chunk.

But there is another thing:

Code:
  1.  
  2.     SetLength(FTexCoords,Length(FTexCoords) + 1);
  3.     SetLength(FVertices,Length(FVertices) + 1);
  4.     SetLength(FNormals,Length(FNormals) + 1);
  5.  


If you do stuff like that too often (by loading a whole map that way for example), it will lead you to very big memoryfragmentation problems...

Autor:  LarsMiddendorf [ Sa Mai 21, 2005 16:29 ]
Betreff des Beitrags: 

And use VBO to store the arrays in video memory.

Autor:  Grizzly [ Sa Mai 21, 2005 19:23 ]
Betreff des Beitrags: 

AL hat geschrieben:
Tokter is right. It doesn't work. Those functions want their data in one chunk.
Code:
  1.  
  2.     SetLength(FTexCoords,Length(FTexCoords) + 1);
  3.     SetLength(FVertices,Length(FVertices) + 1);
  4.     SetLength(FNormals,Length(FNormals) + 1);
  5.  


If you do stuff like that too often (by loading a whole map that way for example), it will lead you to very big memoryfragmentation problems...


not too mention that calls of setlength are not fast

Autor:  McCLaw [ Mo Mai 23, 2005 18:56 ]
Betreff des Beitrags: 

LarsMiddendorf hat geschrieben:
And use VBO to store the arrays in video memory.


The code above is used for my character animation class, so i'm not sure VBO will work here.

If it will, I'm all ears :) :D


The problem is fixed :)

You guys where 100% the data needs to be in sequential blocks in memory for GL to read it, Its a pity that the pointer idea didnt work because it makes the memory footprint VERY small. :(

I eventually went back to normal vert arrays, and am now trying to reduce the load on the memory, by reusing arrays and animations for multiple characters etc...

Thanx for the help :)

Autor:  LarsMiddendorf [ Mo Mai 23, 2005 21:07 ]
Betreff des Beitrags: 

You can also use VBO's with dynamic data. Use GL_DYNAMIC_DRAW if the data is used multiple times and GL_STREAM_DRAW if it is used only once. When updating a buffer, it is the best to use glBufferSubData or to map the buffer and to copy the array directly.
The driver should give you a new buffer when using WRITE_ONLY_ARB with glMapBuffer, so that the new buffer can filled while the hw is rendering the old.
This can give you a quite large speed increase. There ist an old NV_Vertex_Array_Range demo that uses the same technique and it was many times faster than using the default vertex arrays although the application was writing directly to AGP oder video memory every frame.

Autor:  McCLaw [ Mi Mai 25, 2005 18:39 ]
Betreff des Beitrags: 

Ahh yes :)

Thank you Lars

That will help me LOTS :)

VBO's are still a bit of mystery to me, but from what I have read they work almost the same as Vert arrays, so I should be able to understand them, without too much hastle

Thanx again

PS: Current statistics for my anim class using 41 characters (All wth two animations blending) totaling 109 000 Triangles are:

GFX Card: GF 6800 GT
FPS: 160
Memory Usage: WAAAYYYYYYYY TOOOO MUCH!
CPU: AMD 64 3500 +
MEM : 1023

Havent tested on my older cards/PC's yet, so i'll post those stats later.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/