c++ - GLSL: no active uniforms/attributes after link -


after linking program both vertex , fragment shaders attached , feeding values, noticed nothing happens @ all, i.e. nothing rendered. after logging, found out program cannot find of uniforms. after more logging, found out there no active uniforms or attributes in program. double checked shader sources well, , variables used fo'sho (thus eliminating "optimalisations"). checked source parsing , it's fine too. i, therefore, have no idea may causing this.

this parsing/compiling function:

int _loadprogramfromsource(gluint shader,const char* filename) {     std::ifstream file;     file.open(filename, std::ios::in);      //check if file valid     if (!file)     {         g_log.printerror("creating shader %s - file not found",filename);         return -1;     }      const glint len = _getfilelenght(file);     if(len == 0) return 0;      std::vector<std::string> lines;      lines.push_back("#version 140"); // glsl version control     while(!file.eof()) {         std::string in = "";         std::getline(file, in);         if(strcmp(in.substr(0,8).c_str(),"#version")) lines.push_back(in.c_str());     }      std::string fm = "";     for(int = 0; < lines.size(); ++i) {         std::cout << lines[i] << std::endl;         fm += lines[i];         if(fm[fm.size()-1]) fm += "\0";     }      const glchar* filememory = fm.c_str();      glshadersource(shader, 1, &filememory, null); check_gl_error;     glcompileshader(shader); check_gl_error;      int status;     glgetshaderiv(shader, gl_compile_status, &status); check_gl_error;     if(status == gl_true) {         g_log.printinfo("shader %s compiled successfully.", filename);         printlog(shader);         return 0;     }     else {         g_log.printerror("shader %s not compile.", filename);         printlog(shader);         return -1;     }  } 

and linking one:

int settechnique(unsigned int htechnique) {     glint asdf; // temp     m_activetechnique = htechnique;       gllinkprogram(m_techniques[m_activetechnique].m_program); check_gl_error;      glgetprogramiv(m_techniques[m_activetechnique].m_program,gl_link_status,&asdf);     if(asdf == gl_true) {         g_log.printinfo("program %d linked. (%s | %s)",m_techniques[m_activetechnique].m_program,m_techniques[m_activetechnique].buffervshader,m_techniques[m_activetechnique].bufferpshader);         glgetprogramiv(m_techniques[m_activetechnique].m_program,gl_active_uniforms,&asdf); check_gl_error;         g_log.printinfo("active uniforms: %d",asdf);         glgetprogramiv(m_techniques[m_activetechnique].m_program,gl_active_attributes,&asdf); check_gl_error;         g_log.printinfo("active attributes: %d",asdf);     } else {         g_log.printerror("program not linked.");         glint tmp0;         glgetprogramiv(m_techniques[m_activetechnique].m_program, gl_info_log_length, &tmp0);         if(tmp0) {             glchar* tmp1 = new glchar[tmp0];             glsizei tmp2;             glgetprograminfolog(m_techniques[m_activetechnique].m_program, tmp0, &tmp2, tmp1);             g_log.printerror("%s",tmp1);             g_log.printerror("%s",m_techniques[m_activetechnique].buffervshader);             g_log.printerror("%s",m_techniques[m_activetechnique].bufferpshader);             delete[] tmp1;         }     }      if(m_techniques[m_activetechnique].m_cull_off)         gldisable(gl_cull_face);     else         glenable(gl_cull_face);      if(m_techniques[m_activetechnique].m_ccwcull)         glcullface(gl_front);     else         glcullface(gl_back);      return 0; } 

this little substract log:

program 120 linked. (media/shaders/ship/lowreflect_vertexshader.vert | media/shaders/ship/lowreflect_pixelshader.frag) active uniforms: 0 active attributes: 0 glsl: warning! lightdiffuse no such uniform. glsl: warning! lightspecular no such uniform. glsl: warning! lightambient no such uniform. glsl: warning! fogcolor no such uniform. glsl: warning! fogdensity no such uniform. glsl: warning! worldviewprojmatrix no such uniform. glsl: warning! worldmatrix no such uniform. 

...and on.

glxinfo | grep opengl opengl vendor string: nvidia corporation opengl renderer string: geforce 9600 gt/pcie/sse2 opengl core profile version string: 3.3.0 nvidia 325.15 opengl core profile shading language version string: 3.30 nvidia via cg compiler opengl core profile context flags: (none) opengl core profile profile mask: core profile 

vertex shader:

// glslv output cg compiler // cgc version 3.0.0016, build date feb 10 2011 // command line args: -profile glslv -po version=140 // source file: lowreflect_vertexshader.cg //vendor nvidia corporation //version 3.0.0.16 //profile glslv //program main //semantic matspecular //semantic matdiffuse //semantic matspecularpower //semantic lightdirection //semantic cameraposition //semantic worldviewprojmatrix //semantic worldmatrix //var float4 matspecular :  : matspecular : -1 : 1 //var float4 matdiffuse :  : matdiffuse : -1 : 1 //var float matspecularpower :  : matspecularpower : -1 : 1 //var float4 lightdirection :  : lightdirection : -1 : 1 //var float4 cameraposition :  : cameraposition : -1 : 1 //var float4x4 worldviewprojmatrix :  : worldviewprojmatrix[0], 4 : -1 : 1 //var float4x4 worldmatrix :  : worldmatrix[0], 4 : -1 : 1 //var float4 in.position : $vin.position : $position : 0 : 1 //var float3 in.normal : $vin.normal : $normal : 0 : 1 //var float3 in.tangent : $vin.texcoord4 :  : 0 : 0 //var float3 in.binormal : $vin.texcoord8 :  : 0 : 0 //var float2 in.coord : $vin.texcoord0 : $texcoord0 : 0 : 1 //var float2 in.coord2 : $vin.texcoord1 : $texcoord1 : 0 : 1 //var float4 main.sposition : $vout.position : position : -1 : 1 //var float4 main.diffuse : $vout.texcoord0 : $tex0 : -1 : 1 //var float4 main.specular : $vout.texcoord1 : $tex1 : -1 : 1 //var float2 main.coord : $vout.texcoord2 : $tex2 : -1 : 1 //var float2 main.coord2 : $vout.texcoord3 : $tex3 : -1 : 1 //var float main.depth : $vout.texcoord4 : $tex4 : -1 : 1 //var float main.oclip0 : $vout.texcoord5 : $tex5 : -1 : 1  #version 140  struct vertex {     vec4 position;     vec3 normal1;     vec3 tangent;     vec3 binormal;     vec2 coord1;     vec2 coord21; };  struct low_fragment {     vec4 sposition;     vec4 diffuse;     vec4 specular;     vec2 coord;     vec2 coord2;     float depth;     float oclip0; };  low_fragment ret_0; float tmp3; float tmp2; float tmp1; float tmp0; vec4 r0013; vec4 r0023; float tmp50; vec3 a0057; float tmp58; float y0065; in vec4 position; in vec4 normal; in vec4 texcoord0; in vec4 texcoord1; out vec4 tex0; out vec4 tex1; out vec4 tex2; out vec4 tex3; out vec4 tex4; out vec4 tex5; uniform vec4 matspecular; uniform vec4 matdiffuse; uniform float matspecularpower; uniform vec4 lightdirection; uniform vec4 cameraposition; uniform mat4 worldviewprojmatrix; uniform mat4 worldmatrix;   // main procedure, original name main void main() {      low_fragment out;     vec3 view;     vec3 normal;     vec3 reflect;     float diff;     float spec;      r0013.x = dot(worldviewprojmatrix[0], position);     r0013.y = dot(worldviewprojmatrix[1], position);     r0013.z = dot(worldviewprojmatrix[2], position);     r0013.w = dot(worldviewprojmatrix[3], position);     r0023.y = dot(worldmatrix[1], position);     view = (cameraposition - position).xyz;     tmp0 = dot(view, view);     tmp1 = inversesqrt(tmp0);     view = tmp1*view;     tmp0 = dot(normal.xyz, normal.xyz);     tmp1 = inversesqrt(tmp0);     normal = tmp1*normal.xyz;     tmp2 = dot(normal, view);     reflect = view - (2.00000000e+00*normal)*tmp2;     diff = dot(lightdirection.xyz, normal);     tmp3 = min(1.00000000e+00, diff);     tmp50 = max(0.00000000e+00, tmp3);     out.diffuse = tmp50*matdiffuse;     a0057 = (-lightdirection).xyz;     spec = dot(a0057, reflect);     tmp3 = min(1.00000000e+00, spec);     tmp58 = max(0.00000000e+00, tmp3);     y0065 = float(int(matspecularpower));     spec = pow(tmp58, y0065);     out.specular = spec*matspecular;     ret_0.sposition = r0013;     ret_0.diffuse = out.diffuse;     ret_0.specular = out.specular;     ret_0.coord = texcoord0.xy;     ret_0.coord2 = texcoord1.xy;     ret_0.depth = r0013.z;     ret_0.oclip0 = r0023.y;     gl_position = r0013;     tex0 = out.diffuse;     tex1 = out.specular;     tex2.xy = texcoord0.xy;     tex3.xy = texcoord1.xy;     tex4.x = r0013.z;     tex5.x = r0023.y;     return; } 

fragment shader:

// glslf output cg compiler // cgc version 3.0.0016, build date feb 10 2011 // command line args: -profile glslf -po version=140 // source file: lowreflect_pixelshader.cg //vendor nvidia corporation //version 3.0.0.16 //profile glslf //program main //semantic matambient //semantic lightdiffuse //semantic lightspecular //semantic lightambient //semantic fogcolor //semantic fogdensity //semantic sampdiffuse : texunit0 //semantic sampspecular : texunit1 //semantic samplight : texunit3 //var float4 matambient :  : matambient : -1 : 1 //var float4 lightdiffuse :  : lightdiffuse : -1 : 1 //var float4 lightspecular :  : lightspecular : -1 : 1 //var float4 lightambient :  : lightambient : -1 : 1 //var float4 fogcolor :  : fogcolor : -1 : 1 //var float fogdensity :  : fogdensity : -1 : 1 //var sampler2d sampdiffuse : texunit0 : sampdiffuse 0 : -1 : 1 //var sampler2d sampspecular : texunit1 : sampspecular 1 : -1 : 1 //var sampler2d samplight : texunit3 : samplight 3 : -1 : 1 //var float4 in.diffuse : $vin.texcoord0 : $tex0 : 0 : 1 //var float4 in.specular : $vin.texcoord1 : $tex1 : 0 : 1 //var float2 in.coord : $vin.texcoord2 : $tex2 : 0 : 1 //var float2 in.coord2 : $vin.texcoord3 : $tex3 : 0 : 1 //var float in.depth : $vin.texcoord4 : $tex4 : 0 : 1 //var float in.oclip0 : $vin.texcoord5 : $tex5 : 0 : 1 //var float4 main.color : $vout.color : $col0 : -1 : 1  #version 140  struct low_fragment {     vec4 diffuse;     vec4 specular;     vec2 coord;     vec2 coord2;     float depth;     float oclip0; };  struct low_pixel {     vec4 color; };  low_pixel ret_0; float tmp1; vec4 tmp0; float c0016; float tmp21; float t0026; in vec4 tex0; in vec4 tex1; in vec4 tex2; in vec4 tex3; in vec4 tex4; in vec4 tex5; out vec4 col0; uniform vec4 matambient; uniform vec4 lightdiffuse; uniform vec4 lightspecular; uniform vec4 lightambient; uniform vec4 fogcolor; uniform float fogdensity; uniform sampler2d sampdiffuse; uniform sampler2d sampspecular; uniform sampler2d samplight;   // main procedure, original name main void main() {      low_pixel out;     vec4 diffusetex;     vec4 speculartex;     vec4 diffuse;     vec4 specular;     vec4 ambient;     float fogfactor;      if (tex5.x < 0.00000000e+00) { // if begin         discard;     } // end if     diffusetex = texture(sampdiffuse, tex2.xy);     c0016 = diffusetex.w - 8.00000012e-01;     if (c0016 < 0.00000000e+00) { // if begin         discard;     } // end if     speculartex = texture(sampspecular, tex2.xy);     tmp0 = texture(samplight, tex3.xy);     diffusetex.xyz = diffusetex.xyz*tmp0.xxx;     speculartex.xyz = speculartex.xyz*tmp0.xxx;     diffuse = tex0*diffusetex*lightdiffuse;     specular = tex1*speculartex*lightspecular;     ambient = matambient*diffusetex*lightambient;     out.color = diffuse + specular + ambient;     out.color.w = diffusetex.w;     tmp1 = tex4.x*fogdensity*tex4.x*fogdensity;     tmp21 = pow(2.71828198e+00, tmp1);     fogfactor = 1.00000000e+00/tmp21;     t0026 = 1.00000000e+00 - fogfactor;     out.color.xyz = out.color.xyz + t0026*(fogcolor.xyz - out.color.xyz);     ret_0.color = out.color;     col0 = out.color;     return; } // main end 

i provide additional information on fly, if need any. in advance.

rather explain in detail why loading code awful, i'll provide correct code code trying , failing do.

std::string shader; {   std::ifstream file(filename, std::ios::in);   if(file)     shader.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()); } 

this doesn't prefix shader #version, that's in shader files. istreambuf_iterator class in <iterator> header.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -