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 NW
Idth = 8;
int nheight = 3;
int nSize = Nwidth*nheight;
Create input data float *pfinput = new Float[4*nsize];
float *pfoutput = new Float[4*nsize];
for (int i = 0; i < nsize*4; i + +) {Pfinput[i] = i + 1.5;
}//Create drawing window Glutinit (&ARGC,ARGV);
Glutcreatewindow ("GPGPU");
Glewinit ();
Create FBO and bind Gluint FB;
Glgenframebuffersext (1,&FB);
Glbindframebufferext (GL_FRAMEBUFFER_EXT,FB);
Create texture objects and bind gluint Tex;
Glgentextures (1,&tex);
Glbindtexture (Gl_texture_rectangle_arb,tex);
Set 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); Associate Textures to FBO Glframebuffertexture2dext (Gl_framebuffer_ext,gl_color_attachment0_ext,gl_texture_rectangle_arb,tex,0);
Defines the texture data cell type glteximage2d (gl_texture_rectangle_arb,0,gl_rgba32f_arb,nwidth,nheight,0,gl_rgba,gl_float,0);
Transfer data to 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,&FB);
Gldeletetextures (1,&tex);
return 0; }
The above example, did nothing, just transfer data to the GPU, and then passed back intact, mainly to verify the role. In fact, this example is referring to the GPGPU programming technique-from GLSL to Cuda to the book of OpenCL.