OpenGL“优化”统一变量

时间:2014-05-13 22:56:34

标签: opengl optimization 3d glsl unroll

我有一个名为 control_count 的统一变量(贝塞尔曲线中控制点的计数)。在我的代码中的标记部分,如果我用此变量替换常量 4 ,它就会停止工作,如果它 4 它正常工作。变量必须包含值4,我在循环之前和之后测试它,我也在代码中标记了它。这应该是一个展开问题?如何强制编译器不要这样做?

#version 150


layout(lines_adjacency) in;

layout(line_strip, max_vertices = 101) out;

out vec4 gs_out_col; 

uniform mat4 MVP;
uniform int control_count;
uniform int tess_count;

int degree;

int binom( int n, int k );

void main() 
{

degree = control_count - 1;

vec3 b[10];
float B[10];

////////////MARK//////////////////
//control_count must be 4, other ways it'd draw less points
for(int i = 0; i < control_count; ++i){
    b[i] = gl_in[i].gl_Position.xyz;
}
////////////END MARK//////////////////

for(int i = 0; i <= tess_count; ++i){
    float t = i / float(tess_count);

    gl_Position = vec4(0);

    ////////////MARK//////////////////
    //here, if I write control_count instead of 4, I don't get what I expect
    for(int j = 0; j < 4; ++j){         
    ////////////END MARK//////////////////
        B[j] = binom(3, j) * pow(1 - t, 3 - j) * pow(t, j);
        gl_Position += vec4(b[j] * B[j], B[j]);
    }

    gl_Position = MVP * gl_Position;

    ////////////MARK//////////////////
    //control_count - 4 --> I get red color,
    //control_count - 3 --> I get purple, 
    //so the variable must have the value 4
    gs_out_col = vec4(1, 0, control_count - 4, 1);//gl_Position;
    ////////////END MARK//////////////////

    EmitVertex();
}

}

使用常量 4 的“好”结果: enter image description here

使用变量 control_count 的“错误”结果: enter image description here

0 个答案:

没有答案