Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

Similar documents
Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013

COMP371 COMPUTER GRAPHICS

CS475/CS675 - Computer Graphics. OpenGL Drawing

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE

GLSL Overview: Creating a Program

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

CS 432 Interactive Computer Graphics

CSE 167. Discussion 03 ft. Glynn 10/16/2017

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

CPSC 436D Video Game Programming

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

Shaders. Slide credit to Prof. Zwicker

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Rendering Objects. Need to transform all geometry then

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Geometry Shaders. And how to use them

CS 432 Interactive Computer Graphics

3d Programming I. Dr Anton Gerdelan

Tutorial 1: Your First Triangle!

CS452/552; EE465/505. Image Processing Frame Buffer Objects

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Tutorial 04. Harshavardhan Kode. September 14, 2015

Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader

CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE

CS452/552; EE465/505. Review & Examples

Vertex Buffer Objects

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea

Tutorial 12: Real-Time Lighting B

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Mali Developer Resources. Kevin Ho ARM Taiwan FAE

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

OpenGL Status - November 2013 G-Truc Creation

Mobile HW and Bandwidth

OpenGL with Qt 5. Qt Developer Days, Berlin Presented by Sean Harmer. Produced by Klarälvdalens Datakonsult AB

Coding OpenGL ES 3.0 for Better Graphics Quality

Copyright Khronos Group Page 1

Introduction to OpenGL ES 3.0

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

Lecture 13: OpenGL Shading Language (GLSL)

Computer Graphics Seminar

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

OpenGL BOF Siggraph 2011

6.S096 Lecture 9 Visualization

A Review of OpenGL Compute Shaders

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

EECS 487: Interactive Computer Graphics

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

Drawing with OpenGL. Chapter 3. Chapter Objectives

Mobile Application Programing: Android. OpenGL Operation

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

From system point of view, a graphics application handles the user input, changes the internal state, called the virtual world by modeling or

We assume that you are familiar with the following:

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

Supplement to Lecture 22

Programming shaders & GPUs Christian Miller CS Fall 2011

Profiling and Debugging Games on Mobile Platforms

The Graphics Pipeline

CS452/552; EE465/505. Image Formation

OpenGL Performances and Flexibility

Introductory Seminar

Introduction to Computer Graphics with WebGL

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Get the most out of the new OpenGL ES 3.1 API. Hans-Kristian Arntzen Software Engineer

Lighting and Texturing

Programming with OpenGL Complete Programs Objectives Build a complete first program

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics (CS 4731) & 2D Graphics Systems

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

Compute Shaders. Christian Hafner. Institute of Computer Graphics and Algorithms Vienna University of Technology

Mobile Application Programing: Android. OpenGL Operation

OpenGL ES 3.0 and Beyond How To Deliver Desktop Graphics on Mobile Platforms. Chris Kirkpatrick, Jon Kennedy

Introduction to OpenGL/GLSL and WebGL GLSL

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Dave Shreiner, ARM March 2009

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

More frames per second. Alex Kan and Jean-François Roy GPU Software

Glamor Status Report. Keith Packard Open Source Technology Center Intel

Transcription:

Starting out with OpenGL ES 3.0 Jon Kirkham, Senior Software Engineer, ARM

Agenda Some foundational work Instanced geometry rendering Uniform Buffers Transform feedback ETC2 Texture formats Occlusion Queries Vertex Array Objects

What s New Updated shading language GLSL ES 3.00 Updated vertex shading using transform feedback mode Lots of new object types shader uniform buffers vertex array objects sampler objects sync objects pixel buffer objects (PBOs) Occlusion queries that work efficiently with tiled renderers Instanced rendering New texture formats and features texture swizzles (sized) integer formats ETC2 texture compression Primitive restart... and a whole lot more

A Quick Review OpenGL ES 3.0 is a shader-based API The pipeline has two shading stages: Geometric Data Vertex Shader Rasterizer Stage Vertex Shader Operation Transformation of 3D world data to 2D screen coordinates. Fragment Shader Fragment Shader Shading (coloring) of potential pixels on the screen

GPU Memory Host Memory Preparing Geometric Data All data sent to OpenGL ES must be passed through a buffer Buffer Type client-side arrays vertex-buffer objects (VBOs) Description CPU-based memory like you get from malloc() GPU-based memory that the graphics driver allocates on your behalf Usage Characteristics Evil and bandwidth unfriendly Fast and GPU friendly OpenGL ES 3.0 supports both varieties, but only use VBOs We ll see more uses for buffers in a bit (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) (x, y, z) glbufferdata()

Rendering in OpenGL ES 3.0 In OpenGL ES 2.0, you could render in two ways: Rendering Command gldrawarrays gldrawelements Description Pass vertex data to vertex shader sequentially Pass vertex data to vertex shader indexed by element list Rendering the same model multiple times was inconvenient In OpenGL ES 3.0, we can do instance rendering Rendering Command gldrawarraysinstanced gldrawelementsinstanced Description Repeatedly pass vertex data to vertex shader sequentially Repeatedly pass vertex data to vertex shader indexed by element list

Converting to Instanced Rendering Less code, more performance GLfloat xform[numinstances][3] = { { x0, y0, z0 }, { x1, y1, z1 }, }; for ( int i = 0; i < NumInstances; ++i ) { gluniform3fv( xform, 1, xform[i] ); gldrawarrays( GL_TRIANGLES, 0, NumTris ); } (application code) gluniform3fv( xform, NumInstances, xform ); gldrawarraysinstanced(gl_triangles, 0, NumTris, NumInstances);

Converting to Instanced Rendering in vec4 position; uniform vec4 xform; (shader code) void main() { gl_position = position + xform; } in vec4 position; uniform vec4 xform[]; void main() { gl_position = position + xform[gl_instanceid]; }

Instanced Rendering Simplifies rendering the same object multiple times Can Reduce the number of draw calls needed Reduce memory bandwidth used

Instance Rendering Demo

Uniform Buffers Uniforms are like constant global variables for a shader their value stays the same for all primitives in a draw call Loading large numbers of uniform variables is tedious there is a struct packaging mechanism, but it s not widely used Uniform Buffer Objects let you load many uniforms easily

Uniform Buffers uniform vec4 position[numobjects]; uniform vec4 velocity[numobjects]; uniform float drag[numobjects]; (shader code) void main() { } uniform ObjectData { vec4 position[numobjects]; vec4 velocity[numobjects]; float drag[numobjects]; }; void main() { }

Initializing Uniforms: a comparison struct { GLfloat position[numobjects][4]; GLfloat velocity[numobjects][4]; GLfloat drag[numobjects]; } data; (application code) GLuint positionloc = glgetuniformlocation( program, position ); GLuint velocityloc = glgetuniformlocation( program, velocity ); GLuint dragloc = glgetuniformlocation( program, drag ); if ( positionloc < 0 velocityloc < 0 dragloc < 0 ) { throw UniformLocationError(); } gluniform4fv( positionloc, NumObjects, data.position ); gluniform4fv( velocityloc, NumObjects, data.velocity ); gluniform4fv( dragloc, NumObjects, data.drag );

Initializing Uniforms: a comparison struct { GLfloat position[numobjects][4]; GLfloat velocity[numobjects][4]; GLfloat drag[numobjects]; } data; (application code) glgenbuffer( 1, &uniformbuffer ); glbufferdata( GL_UNIFORM_BUFFER, sizeof(data), data, GL_STATIC_DRAW ); GLuint uniformindex = glgetuniformblockindex( program, ObjectData ); gluniformblockbinding( program, uniformindex, n ); glbindbufferbase( GL_UNIFORM_BUFFER, 0, uniformbuffer );

Uniform Buffers Useful when you want to share uniforms between different programs Uses Typically faster to switch uniform buffer bindings than switching dozens of uniforms in a program Store more data

Instance Tessellation Demo

Transform Feedback Recall that every vertex is processed by a vertex shader For complex vertex shaders executing the shader could take a long time could result in this being a performance bottleneck Transform feedback allows the results of vertex shading to be captured in a buffer, and rendered later very useful if the object doesn t change between frames Geometric Data Vertex Shader Rasterizer Fragment Shader Transform feedback buffer

Data Flow in Shaders Uniform Vertices in Vertex Shader out Magic in Fragment Shader out Fragments During transform feedback, the outputs of the vertex shader are written to a buffer, which can then become a new data buffer for vertex shading

Configuring Transform Feedback 1. Compile and link transform feedback shader program 2. Determine the outputs of your transform feedback buffer const GLchar* varyings = { location, velocity }; gltransformfeedbackvaryings( program, 2, varyings, GL_SEPARATE_ATTRIBS ); the order of varying names specify their output index 3. Associate transform feedback buffer with output streams GLuint index = 0; // for location GLintptr offset = 0; // location starts at the beginning of the buffer GLsizeptr size = 4 * NumVertices * sizeof(glfloat); glbindbufferrange( GL_TRANSFORM_FEEDBACK_BUFFER, index, xfbid, offset, size); index = 1; // for veclocity offset = size; // data starts immediately after previous entries glbindbufferrange( GL_TRANSFORM_FEEDBACK_BUFFER, index, xfbid, offset, size);

Generating Data with Transform Feedback glenable( GL_RASTERIZER_DISCARD ); gluseprogram( xfbprogram ); glbegintransformfeedback( GL_POINTS ); gldrawarrays( GL_POINTS, 0, NumVertices ); glendtransformfeedback(); gldisable( GL_RASTERIZER_DISCARD ); Specify that we re not going to engage the rasterizer to generate any fragments.

Generating Data with Transform Feedback glenable( GL_RASTERIZER_DISCARD ); gluseprogram( xfbprogram ); glbegintransformfeedback( GL_POINTS ); gldrawarrays( GL_POINTS, 0, NumVertices ); glendtransformfeedback(); gldisable( GL_RASTERIZER_DISCARD ); Switch to our transform feedback shader program (this is the one with our xfb varyings in it).

Generating Data with Transform Feedback glenable( GL_RASTERIZER_DISCARD ); gluseprogram( xfbprogram ); glbegintransformfeedback( GL_POINTS ); gldrawarrays( GL_POINTS, 0, NumVertices ); glendtransformfeedback(); gldisable( GL_RASTERIZER_DISCARD ); Switch into transform feedback mode, requesting that points are generated.

Generating Data with Transform Feedback glenable( GL_RASTERIZER_DISCARD ); gluseprogram( xfbprogram ); glbegintransformfeedback( GL_POINTS ); gldrawarrays( GL_POINTS, 0, NumVertices ); glendtransformfeedback(); gldisable( GL_RASTERIZER_DISCARD ); Send our input data through our transform feedback shader, which will output into our vertex buffer.

Generating Data with Transform Feedback glenable( GL_RASTERIZER_DISCARD ); gluseprogram( xfbprogram ); glbegintransformfeedback( GL_POINTS ); gldrawarrays( GL_POINTS, 0, NumVertices ); glendtransformfeedback(); gldisable( GL_RASTERIZER_DISCARD ); Return to normal rendering (i.e., vertex shader output isn t sent to an xfb buffer).

Generating Data with Transform Feedback glenable( GL_RASTERIZER_DISCARD ); gluseprogram( xfbprogram ); glbegintransformfeedback( GL_POINTS ); gldrawarrays( GL_POINTS, 0, NumVertices ); glendtransformfeedback(); gldisable( GL_RASTERIZER_DISCARD ); Disable the rasterizer sending fragments to the bit-bucket.

Transform Feedback Demo

Texture Compression Options OpenGL ES 1.1, 2.0 ETC1 (as an extension) Other proprietary formats OpenGL ES 3.0 ETC2 (as a part of the core specification) ASTC (as an extension) Other proprietary formats

ETC1 Texture Compression No alpha support Only RGB888 to RGB444 compression No supported on all platforms

ETC2 Texture Compression Available on all OpenGL ES 3.0 platforms Backwards compatible with ETC1 Support for alpha (8 bit or 1 bit) srgb support More formats: R11 (signed/unsigned) RG11 (signed/unsigned)

ETC2 Examples 1 Channel Heightmap 2 Channel Bumpmap 8 bit Alpha Texture 3 Channel Texture 1 bit Alpha Texture

ASTC Extension to OpenGL ES and OpenGL Flexible 2D and 3D textures LDR and HDR pixel formats

Occlusion Queries OpenGL shades before determining visibility the fragment shader is executed before depth testing For complex fragment shading, this can be wasteful lots of work for naught Occlusion Queries help determine if the fragments from a rendered object will pass the depth test Fundamental Idea: render a simply shaded, lowresolution version of your object to determine if any of it is visible constant color, object-aligned bounding-boxes are a nice choice

Using Occlusion Queries Queries need to be allocated GLuint queries[numqueries]; glgenqueries( NumQueries, queries ); Render in query mode glbeginquery( GL_ANY_SAMPLES_PASSED_CONSERVATIVE, queries[i] ); gldrawarrays( ); glendquery( GL_ANY_SAMPLES_PASSED_CONSERVATIVE );

Using Occlusion Queries Check if query computation is completed GLboolean ready; GLboolean visible; do { glgetqueryobjectiv(queries[i], GL_QUERY_RESULT_AVAILABLE, &ready ); } while (!ready ); glgetqueryobjective(queries[i], GL_QUERY_RESULT, visible ); if ( visible ) { // render };

Occlusion Query Demo

Vertex Array Objects Encapsulates vertex data state Stores all the state of glvertexattribpointer with currently bound GL_ARRAY_BUFFER glenablevertexattribarray / gldisablevertexattribarray GL_ELEMENT_ARRAY_BUFFER Reduces the function overhead of switching buffers

Vertex Array Objects GLuint SetupVAO(GLuint vbo, GLuint ibo) { GLuint vao; glgenvertexarrays(1, &vao); glbindvertexarray(vao); } // Create vertex array object and setup its state glbindbuffer(gl_array_buffer, vbo); glvertexattribpointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, NULL); glvertexattribpointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, sizeof(float) * 3); glbindbuffer(gl_element_array_buffer, ibo); glbindvertexarray(0); return vao; void RenderFunc(GLuint vao, GLsizei NumIndices) { glbindvertexarray(vao); gldrawelements(gl_triangles, NumIndices, GL_UNSIGNED_SHORT, NULL); }

Examples and Help For more information (including the code for the examples you ve seen today) visit: http://malideveloper.arm.com