OpenGL offline rendering and buffer objects

Source: Internet
Author: User
Document directory
  • 1. FBO is not supported
  • 2. PC supports FBO
  • 3. Offline rendering on mobile
Theory

Opengll offline rendering is to use OpenGL to render the rendering result to an image in the video memory. The GL interface function can be used to read from the video memory to the memory. The OpenGL-based offline rendering mechanism allows you to quickly implement a Renderer:

Input: image, point, line...

Output: Image

From general to Special: 1. FBO is not supported, If the mobile device does not support FBO and needs to implement offline rendering, that's exactly the same.. Gldrawbuffer (gl_back); glreadbuffer (gl_back); sets the buffer zone after read/write. Generally, PCs support dual-buffering, No more than gl_back..Gldrawpixels updates the color buffer. Call OpenGL to draw in gl_back. After completion, glreadpixels calls the color buffer from the memory. This function causes GPU blocking and is inefficient.2. PC supports FBO OpenGL supports multiple buffer objects: The buffer object is a buffer area in the memory. OpenGL is an industry rendering standard. The specific interface functions are implemented by the graphics card driver. The OpenGL client is an application using opegl. the OpenGL server can be understood as a GPU. If no GPU is available, it is a module in the OS kernel, the buffer object is defined on the server side to reduce the data transmission overhead during each rendering on the client. Each buffer object has a unique ID. Similar to the handle concept, the client uses bufferid to manage the buffer object. 1) Texture objects, most commonly supported since gl1.0. Basic operation commands: glgentextures, glbindtextures, and gldeletetextures. New commands will be added to multiple textures in the future. Server-side texture data, client only Write Permission: The gltexsubimage2d function updates the Texture buffer content locally or all. 2) VBO (vertex buffer object) and PbO (Pixel Buffer object) use the same GL commands: glgenbuffers, glbindbuffers, and gldeletebuffers... However, the data content stored in the buffer is inconsistent. The former stores vertices and the latter stores pixels. The vertex list of VBO gradually fades out of people's field of view. The VBO, PbO, and client Read and Write Permissions: Glmapbuffer maps the server-side memory address to the client address. After the operation is completed, glunmapbuffer is called, or data is updated directly through glbuffersubdata. 3) After VBO, VAO (vertex Array Buffer) appeared again. VAO came out of gl3.0, which is a little too cold. Considering the Android Market for mobile devices, we have research. If you are interested, please slam here: http://www.zwqxin.com/archives/opengl/vao-and-vbo-stuff.html4) RBO (render buffer object), RBO can not be used independently, must be combined with FBO, corresponds to the OpenGL buffer, RBO can store color, depth, template data. Command set: glgenrenderbuffers, glbindrenderbuffer, and gldeleterenderbuffers. 5) FBO (frame buffer object) has a set of special commands: glgenframebuffers, glbindframebuffer, and gldeleteframebuffers .. After FBO is created, the buffer must be bound: The color and depth are required. The template buffer depends on the requirement. The buffer object is not limited to RBO, and the texture object can also act as a buffer object: The last parameter for creating a texture is null in glteximage2d. In the memory, you only need to create a texture object, texture data is not required. Example of using a texture object as a buffer object: callback, The offline rendering process using FBO is as follows: Main rendering process, using the system default buffer object Save OpenGL onsite ---------> Bind FBO A) glclear clears the buffer content corresponding to FBO. B) add content to the color buffer before offline rendering, such as the background image. C) Set projectionmatrix D) Set modelviewmatrix E) all draw CILS // draw some stuff F) glreadpixels // if needed,The rendering result image is transferred from the video memory to the memory and used to create a texture object in the subsequent main rendering process.. Glcopyteximage2d uses the data in the frame buffer to define the Texture unit. pixels are directly read from the color buffer. The function is similar to glcopypixels.
If the color buffer uses a texture object, you can use this texture to draw it in the main rendering process. <--------- Unbind FBO Back to main rendering process3. offline rendering of mobile devices on mobile is obviously restricted. gles is the reduced version of OpenGL. gles does not have the gldrawbuffer and glreadbuffer interfaces and cannot directly manipulate the front and back buffers. Therefore, solution 1 can only be switched to FBO if it fails. Gles1.1 began to support FBO, GL variables and instructions plus the oes suffix. The offline FBO rendering process on the mobile phone is basically similar to that on the PC. There are two main differences: 1) about Step B of offline RenderingGldrawpixels, the most common practice on PC, directly copies data to the color buffer, but gles does not support gldrawpixels. The first alternative: directly drawtexturequad in orthogonal projection mode, which follows the OpenGL standard assembly line: texture object creation, data transmission, vertex transmission, and geometric transformation, raster and texture coordinate addressing take texture units, and finally write the results to the color buffer through various tests in the buffer zone. Optimized Solution: The texture object is used as the FBO color buffer. You can use the gltexsubimage2d function to directly update the image data to the color buffer. The functions are the same as those of gldrawpixels to avoid OpenGL pipelines. 2) efficiency is preferred on mobile phones. We recommend that you do not use the glreadpixels function directly. For details, refer to the ogl_fbo_pbo_readback example.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.