Error in Geometry Shader from large array

点点圈 提交于 2020-01-05 03:37:10

问题


When I try to link my Geometry Shader it throws the following error:

0(76) : error C5041: cannot locate suitable resource to bind variable "triTable". Possibly large array.

In reference to this array declared in the shader:

    const int triTable[256][16] =
    { { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
    { 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
    { 0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
    ...
    ...
    ...
    { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } };

The array is quite large. Does this have to do with the array being just too big to declare within the shader, or is there some other problem?


回答1:


Triangle data is not meant to be in constants (or uniforms).

Yes, the data is to big to fit in the array. There are hardware contraints on uniform data, and other types of data when using OpenGL.

Preferably you should put your triangle data into a vertex array object and render using it, but if for some reason you want to have the triangle data available for every invocation of the shader you can get this functionality by encoding your vertices into an texture instead of an uniform array, and then just fetch from the texture inside your shader.

In general, textures solve the problem of needing a large amount of constant data between shader invocations.

Note that you can get float texture formats which is probably what you would use for vertex data.




回答2:


You have several options:

  1. Store your data in vertex buffer object and specify the vertex attribute format in vertex array.
  2. Store your data in an 1D texture. But this way is subject to the texture size limit depending on your graphics card. Check it using glGetInteger(GL_MAX_TEXTURE_SIZE, &size); My GT750M returns 16384 (in texels)
  3. If you want to store more triangle data beyond the above limit, you could resort to texture buffer object. It scales the number of texels up to hundreds of millions. Check its limitation on your graphics card using glGetInteger(GL_MAX_TEXTURE_BUFFER_SIZE, &size);


来源:https://stackoverflow.com/questions/29262469/error-in-geometry-shader-from-large-array

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