Coding OpenGL ES 3.0 for Better Graphics Quality Part 2 Hugo Osornio Rick Tewell A P R 1 1 t h 2 0 1 4 TM External Use
Agenda Exercise 1: Array Structure vs Vertex Buffer Objects vs Vertex Array Objects (30 minutes elapsed) Exercise 2: Copying Buffer Objects (40 Minutes Elapsed) Exercise 3: Instanced Rendering (50 Minutes Elapsed) Exercise 4: Primitive Restart (60 Minutes Elapsed) Exercise 5: Texture Compression (70 Minutes elapsed) Exercise 6: Multiple Render Targets (90 Minutes) Exercise 7: Transform Feedback (110 Minutes) External Use 1
Exercise 1 Array Structure vs Vertex Buffer Objects vs Vertex Buffer Objects +Vertex Array Objects Vertex Array Structure Approach Simple and inefficient Vertex Buffer Object Efficient yet tricky cumbersome if you have to switch configurations Vertex Array Objects Efficient way to switch between configurations! External Use 2
Introduction In order to fully grasp the advantages of Vertex Array Objects. Let s first understand how did OpenGL ES 2.0 handled Vertex Attributes using: Array of Structures. Vertex Buffer Objects. External Use 3
Array of Structures How does it work? Vertex shaders require a set of attributes that are supplied per vertex in order to be able to define position, color, texture coordinates and normals. Vertex Arrays are stored in a single buffer structure. These structures are located in client memory space (In your application s memory). And EVERY TIME a draw function is called, the vertex attributes are copied to the GPU. External Use 4
Array of Structures - Coding PENDING TO INCLUDE HANDS ON STEPS. Coding Exercise will be 10 minutes long. External Use 5
Vertex Buffer Object How does it work? Vertex Buffer Objects allow us to allocate vertex data in memory directly accessible for the GPU (remember that using Vertex Arrays, the Vertex Attribute Data needed to be copied from Client Space to GPU space) thus saving us the copy process on each primitive draw call. There are 2 type of buffers that can be created for a vertex shader to use. Array Buffer Object: Store Vertex Data, vertex position, color, normal, texture coordinates. Element Array Buffer Object: Store Indices to be used by the gldrawelements* functions. External Use 6
Vertex Buffer Object - Coding PENDING TO INCLUDE HANDS ON STEPS estimated exercise time 10 minutes. External Use 7
Vertex Array Object How does it work? As you noticed with the previous example, you require a lot of API calls to set, enable and bind a vertex buffer object. And so, switching between 2 different vertex array configurations will involve CPU time spent on those calls. In OpenGL ES 3.0, the concept of Vertex Array Objects was introduced. This object includes all states required to switch between vertex array/vertex buffer object configurations, therefore we avoid plenty of API calls to set attributes, EVERYTIME the configurations are done. External Use 8
Vertex Array Object - Coding PENDING TO INCLUDE HANDS ON STEPS estimated time 10 minutes External Use 9
Exercise 2 Copying Buffer Objects Advantages How to do it External Use 10
Copying Buffer Objects How does it work? On previous examples we used the glbufferdata and glbuffersubdata to copy information from Client Space to Device Space. OpenGL ES 3.0 provides a way to copy data to one buffer object to another buffer object without using Client Memory space, that is, entirely on GPU memory. Its usage is quite simple, glbindbuffer(gl_copy_read_buffer, source_buffer); glbindbuffer(gl_copy_write_buffer, dest_buffer); glcopybuffersubdata(gl_copy_read_buffer, GL_COPY_WRITE_BUFFER, source_offset, write_offset, data_size); External Use 11
Copying Buffer Objects- Coding PENDING TO INCLUDE HANDS ON STEPS (5 minutes) External Use 12
Exercise 3 Instanced Rendering What is it? How to do it External Use 13
Instanced Rendering How does it work? Instanced Rendering: Useful to render meshes/objects that have similar geometry with different attributes (transformation matrix, color, size) using only ONE draw call. EXTREMELY USEFUL on crowd drawing, where you need to draw the same object multiple times. Imagine that you have 100 objects. In order to draw them all, you might use 100 gldraw* functions, however, for each call, your CPU will lose valuable time. With gldraw*instanced you will only lose that time once instead of 100 times. External Use 14
Copying Buffer Objects- Coding PENDING TO INCLUDE HANDS ON STEPS (10 minutes) External Use 15
Exercise 4 Primitive Restart What is it? How to do it External Use 16
Primitive Restart What is it? In OpenGL ES 2.0, if you wanted to draw triangle strips from disconnected primitives, you had to add a degenerate triangle (A triangle with collinear vertices) to the Array Attribute. Primitive Restart lets you store a special value within the Array, so you can set the OpenGL State Machine, to restart an OpenGL Rendering instruction, with the next data Item. External Use 17
Primitive Restart - Coding PENDING TO INCLUDE HANDS ON STEPS (10 minutes) External Use 18
Exercise 5 Texture Compression What is it? How to do it External Use 19
Texture Compression What is it? OpenGL ES 2.0 did not define formats for Compressed Images. It defined a mechanism to load compressed image data. This unleashed every big time GPU vendor to create HW specific compression extensions, and the one to pay was the OpenGL developer, having to support different compression formats on different platforms. OpenGL ES 3.0 defined ETC2 and EAC as standard compressed textures format. External Use 20
Texture Compression - Coding PENDING TO INCLUDE HANDS ON STEPS (10 minutes) External Use 21
Exercise 6 Multiple Render Targets What is it? How to do it External Use 22
Multiple Render Targets What is it? It is a feature that allows the pipeline to Render images to multiple color buffers at once. The fragment shader outputs several colors, normals, depths or texture coordinates. A key thing to understand is that you are not writing the same data to all the render targets. Great for deferred shading, where in order to create a scene, you have to render over it more than once to get the expected result. External Use 23
Multiple Render Targets - Coding PENDING TO INCLUDE HANDS ON STEPS (20 minutes) External Use 24
External Use 25
Exercise 7 Transform Feedback What is it? How to do it External Use 26
Transform Feedback - What is it? OpenGL ES 3.0 introduces a new feature that allows the vertex shader outputs to selectively be written to an output buffer (in addition to, or instead of being passed to the fragment shader). Simply put, we can retrieve the vertices after they've passed through the vertex or geometry shaders. This enables you to execute GPU based animation. External Use 27
Transform Feedback - Coding PENDING TO INCLUDE HANDS ON STEPS (20 minutes) External Use 28
www.freescale.com 2014 Freescale Semiconductor, Inc. External Use