June 5, 2009
Pretty simple thing in CPU.
But If its doing with OpenGL shader you may find a difficulty of losing parallelism of GPU.
Few days later we had a requirement of finding sum of pixels in texture of dimension 100 * 100.
If we are calculating sum in Fragment shader, a single pixel will be rendered and iterate through each pixels in the texture, and sum will be returned from the shader.
Now here is another option to get the sum without iterating through each elements in texture.
We can use blending feature of OpenGL frame buffer.
Enable Additive blending for Frame Buffer. use glBlendEquation(GL_FUNC_ADD)
http://www.opengl.org/sdk/docs/man/xhtml/glBlendEquation.xml
Create a RenderTarget of size 1*1. Then clear it, and render all pixel to it.
Now U will get sum of the texture in your render target.
Leave a Comment » |
Observations | Tagged: blending, GPU, opengl, parallelism, Shader, sum, texture |
Permalink
Posted by glstarter
November 3, 2008
One problem I found when OpenGL buffer object used with CUDA in multiple rendering contexts.
When I have more than one rendering context, the opengl will return same buffer object ids for different buffer objects. The reason for returning same buffer object is nothing these are two rendering contexts.
See code below.
// Creating first buffer object with first rendering Context.
wglMakeCurrent( myRC1 );
glGenBuffers( 1, &myBuffer1 );// This id will be 1 in normal case.
// creating second buffer object with next rendering context.
wglMakeCurrent( myRC2 );
glGenBuffers( 1, &myBuffer2 );// This id also will be 1 in normal case.
// Then registering these buffers to CUDA.
cudaGLRegisterBufferObject( myBuffer1 ); // This will be success.
// Registering next buffer object.
cudaGLRegisterBufferObject( myBuffer2 ); // Here I’ll get Error .
The reason for this error is, cuda device depends on current thread. But openGL creates buffer objects based on rendering contexts. First register to cuda will succeeded, becouse its( 1) not registered yet. Then next register call will fail, becouse this buffer object id ( 1) is already registered for CUDA device. I created two rendering contexts for this thread and hence two buffer objects will return same id.
Thats all friends.
glStarter.
3 Comments |
Observations | Tagged: buffer object, context, CUDA, cudaGLRegisterBufferObject, glGenBuffers, map, opengl, rendering, wglMakeCurrent |
Permalink
Posted by glstarter