Overview of OpenGL for universal GPU computing

Source: Internet
Author: User

It might be a bit earlier. GPU computing developers will do a common GPU computing OpenGL, with the rise of GPU computing technology, more and more technologies, such as OpenCL, CUDA, OPENACC, etc., are specifically used to do parallel computing standard or interface.

OpenGL is used to do general-purpose GPU computing, mainly using texture memory to compute in the GPU and retrieving the results of memory, which is probably the best choice for OpenGL to do general-purpose GPU computing.

The approximate process is to create the OpenGL environment first, then create the FBO (frame cache object), texture, set texture parameters, then bind the texture to the frame cache object, finally transfer the data to the texture, then use the fragment shader to process the data, and finally retrieve the data. A simple example is as follows:

#include <stdio.h> #include <gl/glew.h> #include <gl/glut.h>int main (int argc,char** argv) {int nwidth = 8;int Nheight = 3;int nSize = nwidth*nheight;//Create input data float *pfinput = new Float[4*nsize];float *pfoutput = new Float[4*n size];for (int i = 0; i < nsize*4; i + +) {Pfinput[i] = i + 1.5;} Create a drawing window Glutinit (&AMP;ARGC,ARGV); Glutcreatewindow ("GPGPU"); Glewinit ();//Create FBO and bind Gluint Fb;glgenframebuffersext ( 1,&AMP;FB); Glbindframebufferext (GL_FRAMEBUFFER_EXT,FB);//Create texture object and bind Gluint tex;glgentextures (1,&tex); Glbindtexture (Gl_texture_rectangle_arb,tex);//Set the texture parameter Gltexparameteri (gl_texture_rectangle_arb,gl_texture_min_ Filter,gl_nearest); Gltexparameteri (gl_texture_rectangle_arb,gl_texture_mag_filter,gl_nearest); GlTexParameteri ( Gl_texture_rectangle_arb,gl_texture_wrap_s,gl_clamp); Gltexparameteri (GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_ T,gl_clamp);//associating Textures to Fboglframebuffertexture2dext (gl_framebuffer_ext,gl_color_attachment0_ext,gl_texture_ rectangle_arb,tex,0);//define Texture Data unit type GLTEXIMAGE2D (GL_texture_rectangle_arb,0,gl_rgba32f_arb,nwidth,nheight,0,gl_rgba,gl_float,0);//Transfer data to the texture cache gltexsubimage2d (GL_ Texture_rectangle_arb,0,0,0,nwidth,nheight,gl_rgba,gl_float,pfinput);//Read Data Glreadbuffer (GL_COLOR_ATTACHMENT0_ EXT); Glreadpixels (0,0,nwidth,nheight,gl_rgba,gl_float,pfoutput);//print results for (int i = 0; i < nsize*4; i + +) {printf ("%f\ T%f\n ", Pfinput[i],pfoutput[i]);} Clear resource Delete []pfinput;delete []pfoutput;gldeleteframebuffersext (1,&AMP;FB); Gldeletetextures (1,&tex); return 0 ;}


In the above example, nothing is done, just transfer the data to the GPU, and then pass it back intact, primarily as a validation function. In fact, this example is referring to the GPGPU programming technique-from GLSL to Cuda to the book of OpenCL.

Overview of OpenGL for universal GPU computing

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.