Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects.

Slides:



Advertisements
Similar presentations
Chapter 11. Faster Geometry Throughput Presented by Garrett Yeh.
Advertisements

Week 4 Lecture 1: OpenGL 3.x & 4.x. 2 Objectives Changes in OpenGL 3.x 4.x Changes in GLSL 1.3/4/5 4.x.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 2: Shader Fundamentals (continued)
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
 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.
Meshes Dr. Scott Schaefer. 3D Surfaces Vertex Table.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
Buffer Objects Kurt Akeley, NVIDIA Corporation. Outline Background Buffer Objects Vertex Arrays Examples.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
OpenGL 3.0 Texture Arrays Presentation: Olivia Terrell, Dec. 4, 2008.
 Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.  Applications:
GAM531 DPS931 – Week 10 Meshes and Buffers. Breaking Down An Image Actors Actors = Mesh + Material Mesh = Shape of the object.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
Speeding Up Rendering After Deciding What to Draw.
2002 by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data:
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
The programmable pipeline Lecture 3.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
OpenGL Buffer Transfers Patrick Cozzi University of Pennsylvania CIS Spring 2012.
Review of OpenGL Basics
Async Workgroup Update Barthold Lichtenbelt. OpenGL Siggraph BOF page 2 Goals Provide synchronization framework for OpenGL - Provide base functionality.
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.
1 OGRE Programming Intermediate Tutorial: Volume Selection.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
Geometry processing on GPUs Jens Krüger Technische Universität München.
Ray Tracing using Programmable Graphics Hardware
Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Dynamic Geometry Displacement Jens Krüger Technische Universität München.
VAR/Fence: Using NV_vertex_array_range and NV_fence Cass Everitt.
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.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 GPU.
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.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Best Practices for Multi-threading Eric Young Developer Technology.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Buffers Ed Angel Professor Emeritus of Computer Science
Real-Time Rendering Buffers in OpenGL 3.3
Computer Graphics Index Buffers
Graphics on GPU © David Kirk/NVIDIA and Wen-mei W. Hwu,
Real-Time Rendering Geometry and Buffers
Introduction to OpenGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Chapter VI OpenGL ES and Shader
Computer Graphics Buffers
Building Models Ed Angel Professor Emeritus of Computer Science
Isaac Gang University of Mary Hardin-Baylor
Computer Graphics Practical Lesson 8
Programming with OpenGL Part 2: Complete Programs
Buffers Ed Angel Professor Emeritus of Computer Science
Programming with OpenGL Part 2: Complete Programs
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to OpenGL
Mickaël Sereno Graphics Memory Mickaël Sereno 11/07/2019 Mickaël Sereno -
Opengl implementation
Presentation transcript:

Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects

2 Vertex Buffer Objects Store vertex data (vertex, normal vector, color etc.) Stored on graphics hardware for non- immediate rendering. Substantial performance gains over immediate mode rendering.

3 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Creating Vertex Buffer Objects Creating a VBO requires 3 steps: 1. Generate a new buffer object with glGenBuffersARB(). 2. Bind the buffer object with glBindBufferARB(). 3. Copy vertex data to the buffer object with glBufferDataARB().

4 C Example /* Initialise VBO - do only once, at start of program */ /* Create a variable to hold the VBO identifier */ unsigned int triangleVBO; /* Vertices of a triangle (counter-clockwise winding) */ float data[] = {1.0, 0.0, 1.0, 0.0, 0.0, -1.0, -1.0, 0.0, 1.0}; /* Create a new VBO and use the variable id to store the VBO id */ glGenBuffers(1, &triangleVBO); /* Make the new VBO active */ glBindBuffer(GL_ARRAY_BUFFER, triangleVBO); /* Upload vertex data to the video device */ glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);

5 /* Draw Triangle from VBO - do each time window, view point or data changes */ /* Establish its 3 coordinates per vertex with zero stride in this array; necessary here */ glVertexPointer(3, GL_FLOAT, 0, NULL); /* Make the new VBO active. Repeat here incase changed since initialisation */ glBindBuffer(GL_ARRAY_BUFFER, triangleVBO); /* Establish array contains vertices (not normals, colours, texture coords etc) */ glEnableClientState(GL_VERTEX_ARRAY); /* Actually draw the triangle, giving the number of vertices provided */ glDrawArrays(GL_TRIANGLES, 0, sizeof(data) / sizeof(float) / 3); /* Force display to be drawn now */ glFlush();

6 Updating Vertex Buffer Objects Use glBufferDataARB() or glBufferSubDataARB() to overwrite data. glMapBufferARB() in order to map the buffer object into client's memory. Use glUnmapBufferARB() to unmap. // bind then map the VBO glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId); float* ptr = (float*)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); // if the pointer is valid(mapped), update VBO if(ptr) { updateMyVBO(ptr,...); // modify buffer data glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); // unmap it }

7 Vertex Array Object Despite the name, they do not store vertices. Used to store openGL state attributes. Contain a reference pointer to a vertex buffer object, but this is not required for all cases (e.g. glDrawArrays).

8 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Pixel Buffer Objects Similar concept, allows pixel data to be transferred to gfx card without cpu (through direct memory access). Can perform asynchronous DMA transfer between a PBO and a texture object. Can modify a portion of the buffer object or the entire buffer by using glMapBufferARB() and glUnmapBufferARB().

9 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 // "index" is used to copy pixels from a PBO to a texture object // "nextIndex" is used to update pixels in the other PBO index = (index + 1) % 2; if(pboMode == 1) nextIndex = index; // with 1 PBO else if(pboMode == 2) nextIndex = (index + 1) % 2; // with 2 PBOs // bind the texture and PBO glBindTexture(GL_TEXTURE_2D, textureId); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[index]); // copy pixels from PBO to texture object. Use offset instead of pointer. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0); // bind PBO to update texture source glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[nextIndex]); Manipulating Textures

10 // Note: See Bellow glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB); // map the buffer object into client's memory GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB); if(ptr) { // update data directly on the mapped buffer updatePixels(ptr, DATA_SIZE); glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release the mapped buffer } glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); Manipulating Textures // Note that glMapBufferARB() causes sync issue. // If GPU is working with this buffer, glMapBufferARB() will wait(stall) // until GPU to finish its job. To avoid waiting (idle), you can call // first glBufferDataARB() with NULL pointer before glMapBufferARB(). // If you do that, the previous data in PBO will be discarded and // glMapBufferARB() returns a new allocated pointer immediately // even if GPU is still working with the previous data.

11 // "index" is used to read pixels from framebuffer to a PBO // "nextIndex" is used to update pixels in the other PBO index = (index + 1) % 2; nextIndex = (index + 1) % 2; // set the target framebuffer to read glReadBuffer(GL_FRONT); // read pixels from framebuffer to PBO glReadPixels() returns immediately. glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]); glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0); // map the PBO to process its data by CPU glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]); GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); if(ptr) { processPixels(ptr,...); glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); } // back to conventional pixel operation glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); Modifying the Front Buffer