大阵列中的几何着色器错误 [英] Error in Geometry Shader from large array

查看:167
本文介绍了大阵列中的几何着色器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试链接我的Geometry Shader时,它会引发以下错误:

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?

推荐答案

三角形数据不包含常量(或统一形式).

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

是的,数据很大以适合数组.使用OpenGL时,统一数据和其他类型的数据存在硬件矛盾.

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.

这篇关于大阵列中的几何着色器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆