Changeset 300 for trunk/src/gl/gl_program.cc
- Timestamp:
- 08/07/14 10:29:34 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gl/gl_program.cc
r299 r300 88 88 : vertex_shader( GL_VERTEX_SHADER ), fragment_shader( GL_FRAGMENT_SHADER ) 89 89 { 90 glid = glCreateProgram(); 90 91 compile( vertex_program, fragment_program ); 91 92 } … … 93 94 gl_program::~gl_program() 94 95 { 95 if ( is_valid())96 if ( glid != 0 ) 96 97 { 97 98 // Detach the shaders from the program 98 glDetachShader( m_name.get_value(), vertex_shader.get_id() ); 99 glDetachShader( m_name.get_value(), fragment_shader.get_id() ); 99 glDetachShader( glid, vertex_shader.get_id() ); 100 glDetachShader( glid, fragment_shader.get_id() ); 101 glDeleteProgram( glid ); 100 102 } 101 103 } … … 106 108 if (!fragment_shader.compile( fragment_program )) { return false; } 107 109 108 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::POSITION ), "nv_position" );109 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TEXCOORD ), "nv_texcoord" );110 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::NORMAL ), "nv_normal" );111 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::COLOR ), "nv_color" );112 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TANGENT ), "nv_tangent" );113 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::BONEINDEX ), "nv_boneindex" );114 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::BONEWEIGHT ), "nv_boneweight");115 116 glAttachShader( m_name.get_value(), fragment_shader.get_id() );117 glAttachShader( m_name.get_value(), vertex_shader.get_id() );118 glLinkProgram( m_name.get_value());110 glBindAttribLocation( glid, static_cast<GLuint>( slot::POSITION ), "nv_position" ); 111 glBindAttribLocation( glid, static_cast<GLuint>( slot::TEXCOORD ), "nv_texcoord" ); 112 glBindAttribLocation( glid, static_cast<GLuint>( slot::NORMAL ), "nv_normal" ); 113 glBindAttribLocation( glid, static_cast<GLuint>( slot::COLOR ), "nv_color" ); 114 glBindAttribLocation( glid, static_cast<GLuint>( slot::TANGENT ), "nv_tangent" ); 115 glBindAttribLocation( glid, static_cast<GLuint>( slot::BONEINDEX ), "nv_boneindex" ); 116 glBindAttribLocation( glid, static_cast<GLuint>( slot::BONEWEIGHT ), "nv_boneweight"); 117 118 glAttachShader( glid, fragment_shader.get_id() ); 119 glAttachShader( glid, vertex_shader.get_id() ); 120 glLinkProgram( glid ); 119 121 120 122 if (!validate()) … … 129 131 bool gl_program::is_valid() const 130 132 { 131 return m_name.is_valid();133 return glid != 0; 132 134 } 133 135 … … 135 137 { 136 138 int params; 137 glGetProgramiv( m_name.get_value(), GL_ACTIVE_ATTRIBUTES, ¶ms );139 glGetProgramiv( glid, GL_ACTIVE_ATTRIBUTES, ¶ms ); 138 140 139 141 for ( unsigned i = 0; i < (unsigned)params; ++i ) … … 144 146 char name_buffer[128]; 145 147 146 glGetActiveAttrib( m_name.get_value(), i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer );148 glGetActiveAttrib( glid, i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer ); 147 149 148 150 string name( name_buffer, size_t(attr_nlen) ); … … 151 153 if ( name.substr(0,3) == "gl_" ) continue; 152 154 153 int attr_loc = glGetAttribLocation( m_name.get_value(), name.c_str() );155 int attr_loc = glGetAttribLocation( glid, name.c_str() ); 154 156 155 157 m_attribute_map[ name ] = new attribute( name, attr_loc, gl_enum_to_datatype( attr_type ), attr_len ); … … 160 162 { 161 163 int params; 162 glGetProgramiv( m_name.get_value(), GL_ACTIVE_UNIFORMS, ¶ms );164 glGetProgramiv( glid, GL_ACTIVE_UNIFORMS, ¶ms ); 163 165 164 166 for ( unsigned i = 0; i < size_t(params); ++i ) … … 169 171 char name_buffer[128]; 170 172 171 glGetActiveUniform( m_name.get_value(), i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer );173 glGetActiveUniform( glid, i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer ); 172 174 173 175 string name( name_buffer, size_t(uni_nlen) ); … … 176 178 if ( name.substr(0,3) == "gl_" ) continue; 177 179 178 int uni_loc = glGetUniformLocation( m_name.get_value(), name.c_str() );180 int uni_loc = glGetUniformLocation( glid, name.c_str() ); 179 181 datatype utype = gl_enum_to_datatype( uni_type ); 180 182 … … 232 234 int status; 233 235 234 glGetProgramiv( m_name.get_value(), GL_LINK_STATUS, &status );235 glGetProgramInfoLog( m_name.get_value(), buffer_size, &length, buffer );236 237 NV_LOG( LOG_INFO, "Program #" << m_name.get_value()<< (status == GL_FALSE ? " failed to compile!" : " compiled successfully.") );236 glGetProgramiv( glid, GL_LINK_STATUS, &status ); 237 glGetProgramInfoLog( glid, buffer_size, &length, buffer ); 238 239 NV_LOG( LOG_INFO, "Program #" << glid << (status == GL_FALSE ? " failed to compile!" : " compiled successfully.") ); 238 240 239 241 if ( length > 0 ) 240 242 { 241 NV_LOG( LOG_INFO, "Program #" << m_name.get_value()<< " log: " << buffer );243 NV_LOG( LOG_INFO, "Program #" << glid << " log: " << buffer ); 242 244 } 243 245 … … 247 249 } 248 250 249 glValidateProgram( m_name.get_value());250 glGetProgramiv( m_name.get_value(), GL_VALIDATE_STATUS, &status );251 glValidateProgram( glid ); 252 glGetProgramiv( glid, GL_VALIDATE_STATUS, &status ); 251 253 252 254 if ( status == GL_FALSE ) 253 255 { 254 glGetProgramInfoLog( m_name.get_value(), buffer_size, &length, buffer );255 NV_LOG( LOG_ERROR, "Program #" << m_name.get_value()<< " validation error : " << buffer );256 glGetProgramInfoLog( glid, buffer_size, &length, buffer ); 257 NV_LOG( LOG_ERROR, "Program #" << glid << " validation error : " << buffer ); 256 258 return false; 257 259 }
Note: See TracChangeset
for help on using the changeset viewer.