Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


OpenGL VBO Problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 DrEvil   Members   -  Reputation: 1105

Like
0Likes
Like

Posted 02 March 2013 - 02:27 AM

I'm having trouble rendering a pretty large VBO of quads. This code appears to work fine on small meshes, yet when I try to render pretty large ones(58997 quads) from a single VBO it crashes specifically in 

 

glDrawArrays( it->second.mType, 0, it->second.mNumPrimitives * it->second.mNumVertsPerPrimitive );

 

 

No call stack, just a single random address in the callstack window and the output windows shows

 

 

First-chance exception at 0x003ff829 in ET.exe: 0xC0000005: Access violation reading location 0x01e27000.
Unhandled exception at 0x003ff829 in ET.exe: 0xC0000005: Access violation reading location 0x01e27000.

 

If I remove for example the * it->second.mNumVertsPerPrimitive from the glDrawArrays I don't see the whole mesh. 

 

Here's my construction and rendering code. Since I always get confused about whether various parameters means number of geometric primtives(quad, triangle, etc), or number of floats, I'm trying to wrap the VBO creation and rendering in some helper functions to hide it.

 


bool RenderBuffer::StaticBufferCreate( obuint32 & bufferId, const QuadList & primitives )
{
    static int nextBufferId = 0;
 
    StaticBufferDelete( bufferId );
 
    if ( bufferId == 0 )
        bufferId = ++nextBufferId;
 
    glPushClientAttrib( GL_CLIENT_ALL_ATTRIB_BITS );
 
    VBO v;
    v.mType = GL_QUADS;
    v.mNumPrimitives = primitives.size();
    v.mNumVertsPerPrimitive = 4;
 
    glGenBuffersARB( 1, &v.mBufferVertId );
    glGenBuffersARB( 1, &v.mBufferColorId );
 
    std::vector<float> coords( v.mNumPrimitives * v.mNumVertsPerPrimitive * 3 /* floats per vert */ );
    std::vector<float> colors( v.mNumPrimitives * v.mNumVertsPerPrimitive * 4 /* floats per color */ );
 
    coords.resize( 0 );
    colors.resize( 0 );
 
    for ( size_t i = 0; i < primitives.size(); ++i )
    {
        const Quad & q = primitives[ i ];
        for ( size_t v = 0; v < 4; ++v )
        {
            coords.push_back( q.v[v].x );
            coords.push_back( q.v[v].y );
            coords.push_back( q.v[v].z );
 
            colors.push_back( q.c.rF() );
            colors.push_back( q.c.gF() );
            colors.push_back( q.c.bF() );
            colors.push_back( q.c.aF() );
        }
    }
 
    GLsizeiptr vertexBytes = sizeof(float) * coords.size();
    GLsizeiptr colorBytes = sizeof(float) * colors.size();
 
    glBindBufferARB( GL_ARRAY_BUFFER_ARB, v.mBufferVertId );
    glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertexBytes, &coords[ 0 ], GL_STATIC_DRAW_ARB );
 
    glBindBufferARB( GL_ARRAY_BUFFER_ARB, v.mBufferColorId );
    glBufferDataARB( GL_ARRAY_BUFFER_ARB, colorBytes, &colors[ 0 ], GL_STATIC_DRAW_ARB );
    
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 
    vbos.insert( std::make_pair( bufferId, v ) );
 
    glPopClientAttrib();
    return true;
}

 

 And the drawing code


for ( size_t i = 0; i < mVBOList.size(); ++i )
{
    VBOMap::const_iterator it = vbos.find( mVBOList[ i ] );
    if ( it != vbos.end() )
    {
        glBindBufferARB( GL_ARRAY_BUFFER_ARB, it->second.mBufferVertId );
        glEnableClientState( GL_VERTEX_ARRAY );
        glVertexPointer( 3, GL_FLOAT, 0, NULL /*start of buffer, no offset*/ );
 
        glBindBufferARB( GL_ARRAY_BUFFER_ARB, it->second.mBufferColorId );                
        glEnableClientState( GL_COLOR_ARRAY );
        glColorPointer( 4, GL_FLOAT, 0, NULL /*start of buffer, no offset*/ );
                
        glDrawArrays( it->second.mType, 0, it->second.mNumPrimitives * it->second.mNumVertsPerPrimitive );
 
        glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
 
        glDisableClientState( GL_VERTEX_ARRAY );                
        glDisableClientState( GL_COLOR_ARRAY );
    }
}

 

 



Sponsor:

#2 rouncer   Members   -  Reputation: 291

Like
0Likes
Like

Posted 02 March 2013 - 06:24 PM

is there some 32 bit indices you have to set for large meshes?   i dunno, doesnt even look like your using an index buffer by looking at the code, just saying tho...



#3 DrEvil   Members   -  Reputation: 1105

Like
0Likes
Like

Posted 03 March 2013 - 03:39 PM

Yea no index buffer.

 

Is there in general any mechanisms to debug crashes that occur in the graphics driver ?



#4 Promit   Moderators   -  Reputation: 7343

Like
0Likes
Like

Posted 04 March 2013 - 07:24 PM

The basic issue is of course obvious: you're stepping beyond buffer bounds. But I'm not seeing anything obviously wrong in the code snips posted. Is it possible you've left a client state enabled by accident elsewhere? You might want to try dropping your code into a tool like GDebugger (free from ATI's dev tools site, works on all hardware).



#5 tool_2046   Members   -  Reputation: 1097

Like
0Likes
Like

Posted 04 March 2013 - 09:13 PM

Does glGetError return anything suspicious during buffer creation?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS