HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 Problem with GL_QUADS

View previous topic View next topic Go down 
AuthorMessage
emtenteo



Messages : 2
Date d'inscription : 2012-03-03

PostSubject: Problem with GL_QUADS   Sat Mar 03, 2012 1:19 am

Hi

I'm iphone developer and i want to use this lib for my project, but i got some problem with GL_QUADS render because opengles don't have GL_QUADS, i try convert GL_QUADS to GL_TRIANGLES, all particle are render good after convert but the program got crash when the capacity of group is reach max. I use the demo writing for test it. Anyone can help me? Thanks you so much.

Here is my code

SPK_GLQuadRenderer.h
Split SQUAD to two triangle
Code:

inline void GLQuadRenderer::GLCallColorAndVertex(const Particle& particle) const
{
   float x = particle.position().x;
   float y = particle.position().y;
   float z = particle.position().z;

   // quads are drawn in a counter clockwise order :
   // top right vertex
   *(gpuIterator++) = x + quadSide().x + quadUp().x;
   *(gpuIterator++) = y + quadSide().y + quadUp().y;
   *(gpuIterator++) = z + quadSide().z + quadUp().z;
   gpuIterator += 4;

   // top left vertex
   *(gpuIterator++) = x - quadSide().x + quadUp().x;
   *(gpuIterator++) = y - quadSide().y + quadUp().y;
   *(gpuIterator++) = z - quadSide().z + quadUp().z;
   gpuIterator += 4;

   // bottom left
   *(gpuIterator++) = x - quadSide().x - quadUp().x;
   *(gpuIterator++) = y - quadSide().y - quadUp().y;
   *(gpuIterator++) = z - quadSide().z - quadUp().z;

   *(gpuIterator++) = particle.getR();
   *(gpuIterator++) = particle.getG();
   *(gpuIterator++) = particle.getB();
   *(gpuIterator++) = particle.getParamCurrentValue(PARAM_ALPHA);

   // bottom left
   *(gpuIterator++) = x - quadSide().x - quadUp().x;
   *(gpuIterator++) = y - quadSide().y - quadUp().y;
   *(gpuIterator++) = z - quadSide().z - quadUp().z;
   gpuIterator += 4;

   // bottom right
   *(gpuIterator++) = x + quadSide().x - quadUp().x;
   *(gpuIterator++) = y + quadSide().y - quadUp().y;
   *(gpuIterator++) = z + quadSide().z - quadUp().z;
   gpuIterator += 4;

   // top right vertex
   *(gpuIterator++) = x + quadSide().x + quadUp().x;
   *(gpuIterator++) = y + quadSide().y + quadUp().y;
   *(gpuIterator++) = z + quadSide().z + quadUp().z;      

   *(gpuIterator++) = particle.getR();
   *(gpuIterator++) = particle.getG();
   *(gpuIterator++) = particle.getB();
   *(gpuIterator++) = particle.getParamCurrentValue(PARAM_ALPHA);
}

SPK_GLQuadRenderer.cpp
Change textcoord
Code:

float* GLQuadRenderer::createTextureBuffer(const Group& group) const
{
   FloatBuffer* fbuffer = NULL;

   switch(texturingMode)
   {
   case TEXTURE_2D :
      fbuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(TEXTURE_BUFFER_NAME,FloatBufferCreator(12),TEXTURE_2D,false));
      if (!group.getModel()->isEnabled(PARAM_TEXTURE_INDEX))
      {
         float t[12] = {1.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f,1.0f,1.0f,1.0f,1.0f,0.0f};
         for (size_t i = 0; i < group.getParticles().getNbReserved() * 12; ++i)
            fbuffer->getData()[i] = t[i % 12];
      }
      break;
      
      ......................

Change glDrawArray with GL_QUADS to GL_TRIANGLES
Code:

void GLQuadRenderer::render(const Group& group)
{
   ...........................

   // interleaves vertex and color data
   glVertexPointer(3,GL_FLOAT,7 * sizeof(float),gpuBuffer);
   glColorPointer(4,GL_FLOAT,7 * sizeof(float),gpuBuffer + 3);

   glDrawArrays(GL_TRIANGLES,0,group.getNbParticles() * 6);

   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_COLOR_ARRAY);

   if (texturingMode != TEXTURE_NONE)
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Problem with GL_QUADS   Sat Mar 03, 2012 12:38 pm

Hi, maybe the buffer used to sotre the positions/colors of particles is not big enough.
Have you modified the capacity of this buffer accordingly ?

The buffer is set to hold 28 floats per particles. As you need 6 vertices per particles, you need (3 float per positions + 4 floats per colors) * 6 = 42 floats per particles.

So in SPK_GLQuadRenderer.cpp line 74, you must pass 42 :

Code:
FloatBuffer* fBuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(GPU_BUFFER_NAME,FloatBufferCreator(42),0,false));

But the best way to do to use triangles is to use index buffer and therefore still have only 4 vertices per particles but with 6 indices.
The advantages will be the following :

  • Less work to GPU due to vertex caching
  • Less data to transfer to GPU : 28 * 4 + 6 * 2 (by using short indices) = 124 bytes per particles instead of 42 * 4 = 168 bytes
  • Less processing to fill the buffer (4 vertices instead of 6) as the index data can be preprocessed (it ll never change) a bit like the textureBuffer.


If you want to use an index buffer, you ll have to create a new buffer of short and fill it once in the creates buffer.
The optimal thing would also be to store the index buffer on the VRAM side and therefore upload it to the GPU only once but it would be more work as SPARK 1 does not support VBO only VA.

Hope this helps


Last edited by Juff on Sat Mar 03, 2012 3:35 pm; edited 1 time in total
Back to top Go down
View user profile http://spark.developpez.com
emtenteo



Messages : 2
Date d'inscription : 2012-03-03

PostSubject: Re: Problem with GL_QUADS   Sat Mar 03, 2012 1:07 pm

This problem is resolved when i change 28 to 42. Thanks you so much, you are so great ^^
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Problem with GL_QUADS   Today at 9:27 am

Back to top Go down
 
Problem with GL_QUADS
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Problem with Selenium RC, can't find objects in Junit.
» Problem with Selenium Webdriver
» Profile Customization Problem
» [ANSWERED] Winreducer Install problem
» Selenium RC & Dojo controls.

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Questions (en)-
Jump to: