Real-Time Rendering Buffers in OpenGL 3.3

Slides:



Advertisements
Similar presentations
Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects.
Advertisements

EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 2: Shader Fundamentals (continued)
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
Open Graphics Library (OpenGL)
4.7. I NSTANCING Introduction to geometry instancing.
Geometric Objects and Transformations. Coordinate systems rial.html.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
OpenGL Buffer Transfers Patrick Cozzi University of Pennsylvania CIS Spring 2012.
OPENGL INTRODUCTION 林宏祥 2014/10/06. 此投影片已被稍微簡化過,跟今日課堂上的內容不太一樣。 如果想要看更詳細說明的人,請參考每頁投影片下面的『備忘稿』
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
OpenGL Shading Language
Mouse Input. For Further Reading Learning WebGL, Lesson 11: 2.
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
A study of efficiency INDEX BUFFERS JEFF CHASTINE 1.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Computer Graphics Index Buffers
Real-Time Rendering Geometry and Buffers
Chapter 6 GPU, Shaders, and Shading Languages
Objectives Simple Shaders Programming shaders with GLSL
OpenGL Texture Mapping
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Programming with OpenGL Part 2: Complete Programs
7 Arrays.
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Introduction to geometry instancing
Building Models Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Vertex Array Objects & Buffer Objects
Chapter XVIII Surface Tessellation
OpenGL Texture Mapping
Programming with OpenGL Part 3: Shaders
Programming with OpenGL Part 5: More GLSL
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to Computer Graphics with WebGL
03 | Creating, Texturing and Moving Objects
Programming with OpenGL Part 5: More GLSL
Introduction to OpenGL
Language Definitions Chap. 3 of Orange Book.
CS 480/680 (Fall 2018) Part 2: Texture Loading
Computer Graphics Transformations
Textures in WebGL.
Mickaël Sereno Graphics Memory Mickaël Sereno 11/07/2019 Mickaël Sereno -
Introduction to Computer Graphics with WebGL
Opengl implementation
Computer Graphics Vertex Array Object
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Real-Time Rendering Buffers in OpenGL 3.3 CSE 781 Prof. Roger Crawfis

Data Buffers For most of your geometry you will use one or more GL_ARRAY_BUFFER’s. These are just arrays or void* pointers. Create the pointer using glGenBuffers(). Bind this pointer to have subsequent operations apply to it using glBindBuffer. You bind to the GL_ARRAY_BUFFER proxy.

Setting Data You can set the memory of the buffer using glBufferData and optionally glBufferSubData. Pass in a null pointer (0) to glBufferData to have it initialized to zero. glBufferSubData can be used to fill a subset of the data.

What is your data for? When you set the buffer data with glBufferData you also give OpenGL a hint as to what it will be used for. GL_STATIC_DRAW indicates that it will be set once and used to draw each frame, so perhaps move this data to the GPU. GL_DYNAMIC_DRAW indicates that it may be changed every frame, so why take up GPU space. GL_STREAM_DRAW indicates that is similar to GL_STATIC_DRAW but may not be used very often, so don’t waste GPU memory.

Using Buffers You set the buffer with a chunk of memory. OpenGL has no knowledge of what it is or what to do with it. For this we associate buffers with semantic streams. The glVertexAttribPointer can be used to indicate the type (e.g., GL_FLOAT) and dimension of the data (e.g., vec2). More importantly, it indicates which slot or stream the data should be bound to. The last argument in this routine indicates an offset (not a pointer). The pointer is actually to the currently bound buffer.

Serialized Buffers You can use the offset to place one attribute immediately after the other. This would be one big buffer with say the vertices, followed by the normals, followed by the texture coordinates. Not terribly useful. Why not just use three separate buffers!

Interleaved Data A more useful strategy is to interleave the data such that the first vertex position is followed by the first normal and the first texture coordinate. This can be used to stream an array of structs.

Multiple Buffers A clean way is to allocated a separate buffer for each attribute. How do we associate each of these buffers (or offsets; or offsets and strides)?

Multiple Streams A Shader Program can have many streams of data coming into it. These are indicated by two mappings A mapping from buffers to slots. A mapping from slots to vertex shader variables The end result is we have a mapping from buffers to vertex shader variables. Each slot or stream also needs to be enabled using glEnableVertexAttribArray.

Vertex Variables You connect streams to the “in” variables in your vertex shader. Remember, uniforms are constants. “in” variables in the other shaders come from the previous stage. Each “in” variable will need a different stream or slot. Two approaches to wire these slots: In the source code (C, C++, etc.) In the shader (OpenGL 3.3 or greater and not in OpenGL ES).

Slot Assignments Slot 0 Slot 4 Slot 2 Vertex Shader vec3 position; vec4 vertexColor; vec2 texCoords;

glBindAttribLocation You configure the association between slots and variable names with the glBindAttribLocation, which takes in a shader program, a slot number and a string for the variable name. The association between vertex variables and slots needs to be done before the shader is linked (or you need to link again). The streams or buffers do not need to be defined or even known at this time. A common name system works well for this: inVertex : slot 0 inNormal : slot 1 TexCoord0 : slot 2 …

glGetAttribLocation You can also have OpenGL assign the slots automatically during linking. Calling glGetAttribLocation can then be called after linking to determine the slot assigned.

Using layout in GLSL A third approach allows you to explicitly specify the location in the shader. Example: layout (location = 0) in vec4 Position; You can use this with the glGetAttribLocation to keep things consistent or just assume positions are at slot 0.

Vertex Array Objects A Vertex Array Object (VAO) organizes all of the state required to draw an object. Saves the many BindBuffer / VertexAttribPointer calls needed to draw. In other words is stores the association between buffers and slots, including which and how many slots are enabled.