Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging 在OpenGL 4.5中迭代自定义结构unifrom数组_Debugging_Opengl_Glsl_Shader - Fatal编程技术网

Debugging 在OpenGL 4.5中迭代自定义结构unifrom数组

Debugging 在OpenGL 4.5中迭代自定义结构unifrom数组,debugging,opengl,glsl,shader,Debugging,Opengl,Glsl,Shader,我试图遍历OpenGL 4.5中自定义结构的统一数组,但我的应用程序因操作枚举器无效而崩溃 我的片段着色器如下所示: #version 450 struct Light { vec4 position;//intensity here as well vec4 color; }; in vec3 normal;//Normal to the vertex in vec3 vertexPos;//True position of the vertex (i.e it's locatio

我试图遍历OpenGL 4.5中自定义结构的统一数组,但我的应用程序因操作枚举器无效而崩溃

我的片段着色器如下所示:

#version 450

struct Light
{
  vec4 position;//intensity here as well
  vec4 color;
};

in vec3 normal;//Normal to the vertex
in vec3 vertexPos;//True position of the vertex (i.e it's location in space)
in vec2 texture_coord;

out vec4 outColor;//Final color of the pixel

uniform sampler2D text;
uniform samplerCubeArray depth_maps;
uniform Light lights[];

uniform vec4 color = vec4(1);//Default color
//TODO: make this an array
//uniform vec3 lum = vec3(100,90,15); vec3(80,70,10);//A unique light position

uniform vec3 lums[2] = {vec3(80,70,10), vec3(100,90,15)};
uniform vec3 cameraPos = vec3(0);//The position of the camera in the world
uniform vec3 cameraDir = vec3(0);

void main()
{
    outColor = vec4(0);
    for(uint i=0 ; i<2; i++)
    {
        vec4 color = vec4(0);
        vec3 lum = lights[i].position.xyz;
        vec3 l = vec3(lum-vertexPos);
        if(length(l)>0)
            l = normalize(l);
        vec3 c = vec3(texture(text,abs(texture_coord)));
        vec3 n = normalize(normal);
        vec3 e = cameraPos-vertexPos;
        e = normalize(e);
        vec3 h = normalize(e+l);

        color = vec4(c*(vec3(0.5)+0.5*max(0,dot(n,l))) + 
            vec3(0.1)*max(0,pow(dot(h,n), 100)), 1);

        vec3 temp = vertexPos-lum; 

        float test = texture(depth_maps, vec4(temp, 1)).r;
        double d = length(temp);

        if(d>test*256 + 0.5)
            color = vec4(test/2);

        outColor += color;
    }

    outColor = outColor/2.f;
}
事情按预期进行

为什么我不能遍历我的灯光数组?是因为它是自定义结构吗

编辑:

添加设置阴影贴图的cpp代码,因为它是根据请求设置的

画一张阴影图

void Renderer::draw_shadow_maps(vector<Light> &lights)
{
    current_program = shading_programs[SHADER_DEPTH].programID;
    glUseProgram(current_program);

    //shadow_maps.resize(lights.size());

    glViewport(0, 0, 2048, 2048);
    glBindFramebuffer(GL_FRAMEBUFFER, FBOs[FBO_SHADOW_MAP]);

    for(uint i=0; i<lights.size(); i++)
    {
        glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadow_maps[0].textureID, 0);

        load_uniform((int)i, "map_index");

        glDrawBuffer(GL_NONE); 
        glReadBuffer(GL_NONE);

        if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        {
            if(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
                cerr << "shadow map was not initialized properly" << endl;
            exit(0);
        }

        glClear(GL_DEPTH_BUFFER_BIT);

        setup_light_perspectives(current_program, lights[i]);
        draw();
    }
}
将信息传递到GPU:

void Shadow_Map::load_to_GPU(GLuint program)
{   
    glUseProgram(program);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textureID);

    string name = "depth_maps";

    GLint loc = glGetUniformLocation(program, name.c_str());
    if(loc == GL_INVALID_VALUE || loc==GL_INVALID_OPERATION)
    {
        cerr << "Error returned when trying to find depth_map uniform."
            << "\nuniform: " << name 
            << "\nError num: " << loc
            << endl;
        return;
    }

    glUniform1i(loc,1);
}
void Shadow\u Map::加载到GPU(GLuint程序)
{   
glUseProgram(程序);
玻璃结构(GL_纹理1);
glBindTexture(GL_纹理_立方体_贴图_数组,textureID);
string name=“深度映射”;
GLint loc=glGetUniformLocation(程序,名称.c_str());
如果(loc==GL_无效_值| | loc==GL_无效_操作)
{
瑟尔
几乎总是必须具有静态定义的大小。以下是例外情况:

  • 您可以向前声明一个不带大小的数组,但前提是您稍后使用大小重新声明它
  • 这个变量是
  • 变量(或接口块)是着色器阶段输入/输出限定变量/块,该阶段的输入/输出是阵列的

  • 设置制服的代码是什么样子的?”
    loc==GL_INVALID_VALUE | | loc==GL_INVALID_OPERATION
    “是的,根本不是这样。另外,代码的其余部分在哪里?你从哪里得到“崩溃”程序的OpenGL错误?
    Shadow_Map::Shadow_Map()
    {
        glGenTextures(1, &textureID);
    
        glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textureID);
        glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY,1, GL_DEPTH_COMPONENT32F, 2048, 2048, 6*10);
    
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);  
    
        glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
        openGLerror();
    }
    
    void Shadow_Map::load_to_GPU(GLuint program)
    {   
        glUseProgram(program);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textureID);
    
        string name = "depth_maps";
    
        GLint loc = glGetUniformLocation(program, name.c_str());
        if(loc == GL_INVALID_VALUE || loc==GL_INVALID_OPERATION)
        {
            cerr << "Error returned when trying to find depth_map uniform."
                << "\nuniform: " << name 
                << "\nError num: " << loc
                << endl;
            return;
        }
    
        glUniform1i(loc,1);
    }
    
    uniform Light lights[];