问题
I have a matrix (for example 100x100 dimantion):
I need to do calculation with each element (matrix[i,j]*tt/8+5
for example)
I have huge matrix and I want to implement the algorithm using OpenGL shaders. I want to use shader like:
uniform float val;
uniform float tt;
void main()
{
gl_Position.x = val*tt/8+5
}
How I can implement the program? How I can get matrix after calculation(I do not want to show any windows\pictures?
回答1:
It is possible if you create a fake window frame buffer.
See my sample program where I abused the fragment Shader as a compute Shader because compute shaders are quite new. This program does some Gaussian Filtering calculations of the matrix and returns it to the CPU. (It actually does not matter what it does).
Here are few things to note:
- the transporting of files between CPU/GPU is slow
- other people already pointed out that your matrix is NOT huge. I consider it as very very small (it even fits in the RAM).
来源:https://stackoverflow.com/questions/39045419/using-opengl-shaders-for-math-calculation-c