18 Mar 2013, 10:18
Generic-user-small

Kelsey Roden (6 posts)

I’m reading the book for the second time, this time I’m experimenting with the results of each chapter. My question is in regards to the first air hockey project where there are two triangles for the table, one line for the player’s region boundary, and two points for the mallets.

I modified the project to have another set of vertexData for a border around the table. What I did was removed this code from onSurfaceCreated() ( all of the changes I did to the Renderer class )

glVertexAttribPointer(A_POSITION_LOCATION, POSITION_COMPONENT_COUNT, GL_FLOAT, false, 0, vertexData); glEnableVertexAttribArray(A_POSITION_LOCATION);

I moved this code to the onDrawFrame() method and duplicated it to draw a border before the table is being drawn. This seems to work fine in the running project but does my application now take a huge performance hit, or is it fine to do things like this even in larger applications?

18 Mar 2013, 10:30
Generic-user-small

Kelsey Roden (6 posts)

My onDrawFrame() method looks something like this:

glClear(GL_COLOR_BUFFER_BIT);

glVertexAttribPointer(A_POSITION_LOCATION, POSITION_COMPONENT_COUNT, GL_FLOAT, false, 0, vertexData_Table_Border); glEnableVertexAttribArray(A_POSITION_LOCATION);

glUniform4f(uColorLocation, 0.9f, 0.9f, 0.9f, 1.0f); glDrawArrays(GL_TRIANGLES, 0, 6);

glVertexAttribPointer(A_POSITION_LOCATION, POSITION_COMPONENT_COUNT, GL_FLOAT, false, 0, vertexData); glEnableVertexAttribArray(A_POSITION_LOCATION);

glUniform4f(uColorLocation, 1.0f, 1.0f, 1.0f, 1.0f); glDrawArrays(GL_TRIANGLES, 0, 6);

( This draws the table border using the first float buffer, then it gets the second float buffer and uses it to draw the table. )

18 Mar 2013, 15:13
Generic-user-small

Kevin Brothaler (36 posts)

You probably won’t notice an impact for a simple application, though in general you’ll want to minimize state changes, and later on this could have an impact once you start dealing with complex scenes.

This resource has some good technical information that goes into more detail (it’s for iOS, but since it’s based on OpenGL ES much of the information applies to Android as well; just ignore the part about VAOs since that’s nonstandard): http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html

18 Mar 2013, 16:06
Generic-user-small

Kelsey Roden (6 posts)

Thank you for that link.

Now its time to contemplate merging tree, building, and enemy coordinates/textures into one vertex array. :) It might prove easier than I first expected.

19 Mar 2013, 02:21
Generic-user-small

Kevin Brothaler (36 posts)

The next update will have a quick section on using the Tracer for OpenGL ES. This is a neat tool that can help you dive into more detail and see how much time each draw call is taking, and where you might be having performance issues.

In the meantime, this is also a good read: http://www.teamblubee.com/2012/09/22/android-openggl-and-slow-rendering/

Cheers,

Kevin

  You must be logged in to comment