• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Grumple

GL 3.3 glDrawElements VAO issue...AMD bug or my mistake?

3 posts in this topic

Hello,

 

I'm running out of ideas trying to debug an issue with a basic line render in the form of a 'world axis' model.

 

The idea is simple:  

 

I create a VAO with float line vertices (3 per vertex), int indices (1 per vertex), and unsigned byte color (3 per vertex)

I allow room and pack the array such that the first 12 vertices/indices/colors are for uniquely colored lines representing my +- world axis, and then a bunch of lines forming a 2D grid across the XZ plane.  

Once data is loaded, I render by binding my VAO, activating a basic shader then drawing the model in two stages.  One glDrawElements call is made for the axis lines after glLineWidth is set to 2, and the grid lines drawn through a separate glDrawElements with thinner lines.  

Whenever I Draw this way, the last 6 lines of my grid (i.e. the end of the VAO array) show up as random colors.  However, the lines themselves are correctly positioned, etc.   If I just do one glDrawElements call for all lines (ie world axis and grid lines at once), then the entire model appears as expected with correct colors everywhere.  

 

This is only an issue on some ATI cards (ie radeon mobility 5650), but works on NVidia no problem.

 

I can't see what I would have done wrong if the lines are appearing fine (ie my VAO index counts/offsets must be ok for glDrawElements), and I don't see how it could be that I'm somehow packing the data into the VAO wrong if they appear correctly via a single glDrawElements call instead of two calls separated by changes to glLineWidth()?

 

Any suggestions?  glGetError, etc return no problems at all...

 

Here is some example render code, although I know it is just a small piece of the overall picture.  This causes the problem:

    TFloGLSL_IndexArray *tmpIndexArray = m_VAOAttribs->GetIndexArray();

    //The first AXIS_MODEL_BASE_INDEX_COUNT elements are for the base axis..draw these thicker
    glLineWidth(2.0f);
    glDrawElements(GL_LINES, AXIS_MODEL_BASE_INDEX_COUNT, 
                   GL_UNSIGNED_INT,  (GLvoid*)tmpIndexArray->m_VidBuffRef.m_GLBufferStartByte);

    //The first remaining elements are for the base grid..draw these thin
    int gridLinesElementCount = m_VAOAttribs->GetIndexCount() - AXIS_MODEL_BASE_INDEX_COUNT;
    if(gridLinesElementCount > 0)
    {
        glLineWidth(1.0f);

        glDrawElements(GL_LINES, gridLinesElementCount, GL_UNSIGNED_INT, 
                       (GLvoid*)(tmpIndexArray->m_VidBuffRef.m_GLBufferStartByte + (AXIS_MODEL_BASE_INDEX_COUNT * sizeof(int))));
    }

This works just fine:

    glDrawElements(GL_LINES, m_VAOAttribs->GetIndexCount(), GL_UNSIGNED_INT, 
                    (GLvoid*)tmpIndexArray->m_VidBuffRef.m_GLBufferStartByte);
Edited by Grumple
0

Share this post


Link to post
Share on other sites
Update:
 
I still haven't figured out the root of the issue, but as a test I have switched to using floats for my color attribute instead of gl_unsigned_byte.  My unsigned byte colors were being passed in the range 0..255 with normalized set to GL_TRUE, and floats are passed 0..1.0 with normalized param of GL_FALSE.  Without really changing anything else , the problem goes away completely, so I am really suspicious of the ATI driver...
 
Anyone else seeing issues using multiple glDrawElement calls from a single bound VAO containing unsigned-byte color vertex attributes?

 

0

Share this post


Link to post
Share on other sites

Update #2:  Problem solved!

 

For anyone encountering similar issues, it turns out some older ATI cards (maybe newer) do NOT like vertex array attributes that are not aligned to 4-byte boundaries.   I changed my color array to pass 4 unsigned bytes instead of 3, and updated my shader to accept vec4 instead of vec3 for that attribute and everything now works as intended.

 

Kind of a silly issue....but that is what i get for trying to cut corners on memory bandwidth, etc.  =P

0

Share this post


Link to post
Share on other sites

 

Kind of a silly issue....but that is what i get for trying to cut corners on memory bandwidth, etc.  =P

 

No need to cut corners there unless you have actual bandwidth issues. I think even then it's suspect, especially since 3-bytes must be aligned to 4 even on modern, because there they just turn into extra instructions.

On modern cards misaligned accesses have minor impact, so packing the data more makes more sense there, I guess.

Very strange that it would just crash though, did you pack the struct so it didn't naturally align to a 4byte boundary? You can only align 1, 2, 4, 8 etc, btw.

 

While we're talking about performance: The only thing that really matters is that you don't split up your data into several structures. Like position + normals. The GPU will drop in speed exponentially.

See effects of strided access here: http://www.ncsa.illinois.edu/People/kindr/projects/hpca/files/singapore_p3.pdf

 

As long as the structs are packed, and the data can be read sequentially in memory, you are good.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0