• 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
Ed Welch

is glEnableVertexAttribArray redundant?

10 posts in this topic

I can't seem to understand the purpose glEnableVertexAttribArray. I know it enables glVertexAttribPointer, but I can't see any case where you would want to call glVertexAttribPointer with the attribute disabled. If you don't want to send the attribute, then you would just not call glVertexAttribPointer at all.

0

Share this post


Link to post
Share on other sites

Hi mhagain, thanks for the answer!

Right, so you're saying it's useful if you are re-using a VBO from the same shader?

Unfortunately, I'm using OpenGL ES so I can't use GL_ARB_vertex_attrib_binding.

0

Share this post


Link to post
Share on other sites

but if you are drawing a shadow you are using a different shader. I thought once you switched shaders everything is reset.

0

Share this post


Link to post
Share on other sites

but if you are drawing a shadow you are using a different shader. I thought once you switched shaders everything is reset.

 

Nope, you can switch shaders and most states will stay the same.

0

Share this post


Link to post
Share on other sites

 


Nope, you can switch shaders and most states will stay the same.

 

Right, I didn't know that. I presume switching the frame buffer doesn't effect it either?

0

Share this post


Link to post
Share on other sites

 

 


Nope, you can switch shaders and most states will stay the same.

 

Right, I didn't know that. I presume switching the frame buffer doesn't effect it either?

 

 

States pretty much live in isolation unless it's documented otherwise.

0

Share this post


Link to post
Share on other sites

Well, that means I had a potential bug in my program :-o. Thanks for your help anyways ;)

0

Share this post


Link to post
Share on other sites

 

 

glDisableVertexAttribArray (2);

glDisableVertexAttribArray (1);

 

Then you set up the rest of your state and issue a draw call.

 

Now, think about what you need to do when drawing the next mesh?

 

 

The point here is that if the glEnable/DisableVertexAttribArray did not exist, one would not need to disable or enable in the first place. If the shadow shader doesn't use normals or texcoords, it could just ignore those attribute channels, and when the next shader is used with those channels, it would just pick them up in a no-op configure manner.

 

I've also pondered on the question "what if I'd just go and enable all attribute arrays always at engine startup, or in VAO case, right after creating a new VAO?" effectively making the default attribute state to be enabled, since unused attributes are always ignored anyways. There is that feature where you can disable an attribute array, and replace it with a single constant value for the whole attribute, but most consider that as a non-feature, so I would just ignore it. And the train of though always comes to this: what if there are some bad GL drivers out there that take a performance impact on setting up the unused vertex attribute data? So just to play safe, I've thought it to be better to just do the clean thing.

 

VAOs fortunately take this question away, since it moves the enables/disables to VAO creation time anyways, so it becomes an uninteresting question.

0

Share this post


Link to post
Share on other sites

If you just enable all attrib arrays, each one for which you don't make a glVertexAttribPointer call will take the default attrib pointer state.

 

The most important thing here is that the initial value for the pointer param is 0.

 

The second most important thing is that when you make a glVertexAttribPointer call, the driver takes a bunch of state and params, including the params to your glvertexAttribPointer call and the currently bound GL_ARRAY_BUFFER, and, saves them out as state for that attrib array.  So in other words, this and not anywhere else is the point at which your currently bound buffer takes effect.

 

If you've no GL_ARRAY_BUFFER bound your draw call will end up dereferencing a NULL pointer.

 

But the GL_ARRAY_BUFFER binding isn't established until you call glVertexAttribPointer so if you never call glVertexAttribPointer then you'll never have a GL_ARRAY_BUFFER binding for that attrib array.

 

So you'll always dereference a NULL pointer.

 

And you'll crash.

 

Go ahead, check out the OpenGL.org forums and you'll see a healthy enough supply of cries for help from people who get a crash inside a draw call and it turns out they've an array enabled but no glVertexAttribPointer set for it.

 

At this point one is just getting cutesy and trying to fight against the API rather than work with it and use it the way it was designed to be used.  That's not a clever thing to do.

 

(IIRC it's also illegal to have a GL_ARRAY_BUFFER of 0 when using VAOs too, so even if you have a really really robust driver - which you can't rely on your customers also having - best case is you'll get a bunch of GL errors).

 

Seriously - it's insane, don't do it.

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