1

我正在尝试从几何着色器中的 3D 纹理中读取:

#version 150

layout(points) in; // origo of cell
layout(points, max_vertices = 1) out;

uniform sampler3D text;

void main (void) 
{   
    for(int i = 0; i < gl_in.length(); ++i)
    {
        // texture coordinates:
        float u, v, w;

        // set u, v, and w somehow
        ...

        float value = texture(text, vec3(u, v, w)).r;

        bool show;

        // set show based on value somehow:
        ...

        if(show) {      
            gl_Position = gl_in[i].gl_Position;
            EmitVertex();
            EndPrimitive();  
        }  
    }
}

这就是我在初始化 GL 代码中设置纹理的方式:

int nx = 101;
int ny = 101;
int nz = 101;
float *data = new float[nx*ny*nz];
// set data[] somehow:
...
glEnable(GL_TEXTURE_3D);
glBindTexture(GL_TEXTURE_3D , texture); 
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage3D( GL_TEXTURE_3D, 
                  0,      // level-of-detail number. 0 is the base image level.
             GL_RED, // internal format
         nx, ny, nz,
                  0,      // border
             GL_RED, // pixel format 
           GL_FLOAT,  // data type of the pixel data 
               data);

但是如何将几何着色器中的采样器“文本”与我的纹理相关联?

到目前为止,我还没有告诉 OpenGL 有一个名为“text”的采样器,它应该对纹理进行采样。

编辑:我尝试了以下方法:

GLint textLoc = glGetUniformLocation(program, "text");
glUniform1i(textLoc, 0); // sends 0 to "text" in shader
// why do I not just hardcode 0 inside the geometry shader instead ? 
glBindTexture(GL_TEXTURE_3D , texture); 
glActiveTexture(GL_TEXTURE0); // same as 0 ?
GLuint sampler_state = 0;
glGenSamplers(1, &sampler_state);
glBindSampler(0, sampler_state); // what does this do?

这里有什么问题?

4

0 回答 0