Using OpenGL shaders for math calculation (C++)

只愿长相守 提交于 2021-02-08 06:35:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!