Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Why is my Q3 Level Renderer slow!

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Hellerup, DENMARK
    Posts
    4

    Why is my Q3 Level Renderer slow!

    Hi!
    I have managed to create a simple Quake3 Level Renderer. Textures and Lightmaps are succesfully applied and I think the PVS and Frustumculling works great, but itīs still very slow (sometimes aprox. 15 fps.)
    The below code is my BSP Render() function:

    void BSP: raw(float PosX, float PosY, float PosZ)
    {
    Frustum->CalculateFrustum();

    CameraPoint[1] = PosX;
    CameraPoint[2] = PosY;
    CameraPoint[0] = PosZ;

    int CameraLeaf=0;

    CameraLeaf = FindLeaf();

    if (CameraLeaf < 0)
    return;

    if (&Leaves[CameraLeaf].cluster < 0)
    return;

    glPushMatrix();
    glTranslatef(PositionX, PositionY, PositionZ);

    int i=0;
    int x=0;
    int j=0;
    int k=0;
    int CurrFace=0;
    int n_leaffaces=0;

    for (x=0; x<NumLeaves; x++) // For every leaf in the level
    {
    if (TESTVIS(Leaves[CameraLeaf].cluster, Leaves[x].cluster)) // Test to see if leaf MAY be visible
    {
    if (InFrustum(Leaves[x].mins, Leaves[x].maxs)) // Test to see if leaf IS visible
    {
    n_leaffaces = Leaves[x].n_leaffaces; // Get number of faces in the current leaf

    for (j = 0; j < n_leaffaces; j++) // For every face in that leaf
    {
    CurrFace = LeafFaces[Leaves[x].leafface+j].face;

    if (Faces[CurrFace].type == 1 && Faces[CurrFace].lm_index > -1)
    {
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
    TexData[Faces[CurrFace].texture].Use();

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, LightMapTextures[Faces[CurrFace].lm_index].ID);

    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );

    glBegin( GL_TRIANGLE_FAN);

    for(k = Faces[CurrFace].vertex; k < Faces[CurrFace].vertex + Faces[CurrFace].n_vertexes; k++)
    {
    glColor4f(Vertices[k].color[0], Vertices[k].color[1], Vertices[k].color[2], Vertices[k].color[3]);

    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, Vertices[k].texcoord[0][0], Vertices[k].texcoord[0][1]);
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, Vertices[k].texcoord[1][0], Vertices[k].texcoord[1][1]);

    glNormal3f(Vertices[k].normal[0], Vertices[k].normal[1], Vertices[k].normal[2]);
    glVertex3f(Vertices[k].position[1], Vertices[k].position[2], Vertices[k].position[0]);
    }

    glEnd();
    }
    }
    }
    }
    }

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_2D);

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glDisable(GL_TEXTURE_2D);

    glEnable(GL_TEXTURE_2D);

    glPopMatrix();

    }

    The TESTVIS Macro is from the Aftershock engine:

    #define TESTVIS(from,to) \
    (*(VisData->vecs + (from)*VisData->sz_vecs + \
    ((to)>>3)) & (1 << ((to) & 7)))

    Please help me! It really bugs me!

    Best regards
    Humle

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Why is my Q3 Level Renderer slow!

    Just a couple of suggestions,

    1. Use glVertex3fv, glColor3fv (actually glColor3bv may be best). And do you really even need to use glNormal? Nothing in that code suggests you need normals.

    OR

    2. Stop using immediate mode. Batch your polygons together into a vertex array (and associated arrays) then feed the arrays to OpenGL all at once.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Lubbock, TX, USA
    Posts
    197

    Re: Why is my Q3 Level Renderer slow!

    Dfrey's #2 is it. Think about it, you're making 5 calls to OpenGL for every vertex in your scene, plus, vertices that are shared will be transformed and lit twice in immediate mode.
    Use indexed vertex arrays for your triangle lists or, even better, stripify your geometry on level load time and use non-indexed triangle strips (that's the fastest choice in most cases).

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    17

    Re: Why is my Q3 Level Renderer slow!

    Hi ,
    what is WAY more important than the points mentioned before is that you do not batch up your faces by texture/lightmap .. but instead do all the setup code for each and every face you render .
    that`s what`s slowing you down .
    So , if you found out a face is visible put it to a kind of hash , with one slot for every texture/lightmap combination .
    After you`re done visiting the tree you step through this hash , do the setup code for each slot (yes , you should use vertex arrays) and then render the whole slot . this way you have less texture changes .. this is really going to speed you up ...

  5. #5
    Member Newbie
    Join Date
    May 2001
    Location
    Warsaw Poland
    Posts
    39

    Re: Why is my Q3 Level Renderer slow!

    with vertex-arrays and today's hardware you can
    draw entire Q3 level per frame (ignoring BSP and VIS data) at 50 fps

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Hellerup, DENMARK
    Posts
    4

    Re: Why is my Q3 Level Renderer slow!

    Thank you for your response, but Martin, please write some pseudo-code...Im lost!

    Best regards
    Humle

    Originally posted by Martin Kraus:
    Hi ,
    what is WAY more important than the points mentioned before is that you do not batch up your faces by texture/lightmap .. but instead do all the setup code for each and every face you render .
    that`s what`s slowing you down .
    So , if you found out a face is visible put it to a kind of hash , with one slot for every texture/lightmap combination .
    After you`re done visiting the tree you step through this hash , do the setup code for each slot (yes , you should use vertex arrays) and then render the whole slot . this way you have less texture changes .. this is really going to speed you up ...

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    4

    Re: Why is my Q3 Level Renderer slow!

    Why don't you use the BSP nodes as well as the leaves for frustum culling? They are much more efficient, as you can cull a maximum of half the map away if it isn't in the view frustum.

  8. #8
    Junior Member Newbie
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    17

    Re: Why is my Q3 Level Renderer slow!

    Hi ,
    uhmm , the code for this is rather complicated .. let`s see : (simplified )

    for each leaf
    if (leaf_visible )
    {
    for each face in leaf
    {
    if not already in facelist , push to facelist
    ]
    }

    when done visiting :
    for each facelist slot
    {
    if (!slot_empty)
    {
    set texture
    set lightmap
    for each face in slot
    {
    push to vertex array ;
    }
    render current vertex array ;
    }
    }

    that`s about it .. for real code : www.planequake.com/aftershock

  9. #9
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Hellerup, DENMARK
    Posts
    4

    Re: Why is my Q3 Level Renderer slow!

    Martin, what is a slot and should there be one slot for each face?
    Btw. DeathWishes reply isent true, right?

  10. #10
    Junior Member Newbie
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    17

    Re: Why is my Q3 Level Renderer slow!

    Hi ,
    you need one slot for every texture ( or shader ) / lightmap combination .. all faces with the same texture and lightmap go into one slot .. that is the whole point of them , to batch the faces with the same state up ..
    i can`t explain every detail here ,also because it`s not fully on topic in this forum .. check the source , it`s all there .
    What DeathWishes ?!

Page 1 of 2 12 LastLast

Similar Threads

  1. How do you use your renderer targets?
    By imported_Groovounet in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 10-14-2009, 11:43 AM
  2. toggle between hw/sw renderer?
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-10-2003, 05:48 PM
  3. Renderer design
    By kaysoft in forum OpenGL: Advanced Coding
    Replies: 18
    Last Post: 11-26-2002, 08:46 PM
  4. indexed vertexarrays slow, very slow ?
    By imported_T2k in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 02-28-2002, 05:06 PM
  5. Replies: 10
    Last Post: 04-30-2000, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean