Changeset 300
- Timestamp:
- 08/07/14 10:29:34 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gl/gl_program.hh
r299 r300 16 16 #include <nv/interface/program.hh> 17 17 #include <nv/string.hh> 18 #include <nv/gl/gl_names.hh>19 18 20 19 namespace nv … … 37 36 unsigned int get_id() const { return object_id; } 38 37 private: 39 uint32 shader_type;40 u int32object_id;38 uint32 shader_type; 39 unsigned object_id; 41 40 }; 42 41 … … 58 57 void load_uniforms(); 59 58 60 gl_shader_name m_name;59 unsigned glid; 61 60 gl_shader vertex_shader; 62 61 gl_shader fragment_shader; -
trunk/nv/gl/gl_texture2d.hh
r299 r300 14 14 15 15 #include <nv/interface/texture2d.hh> 16 #include <nv/gl/gl_names.hh>17 16 18 17 namespace nv … … 25 24 26 25 gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ); 26 ~gl_texture2d(); 27 27 protected: 28 gl_texture_name m_name;28 unsigned glid; 29 29 }; 30 30 -
trunk/nv/gl/gl_vertex_buffer.hh
r299 r300 14 14 15 15 #include <nv/interface/vertex_buffer.hh> 16 #include <nv/gl/gl_names.hh>17 16 18 17 namespace nv … … 25 24 26 25 gl_vertex_buffer( buffer_hint hint, size_t size, const void* data = nullptr ); 26 ~gl_vertex_buffer(); 27 27 private: 28 gl_buffer_name m_name;28 unsigned glid; 29 29 }; 30 30 … … 35 35 36 36 gl_index_buffer( buffer_hint hint, size_t size, const void* data = nullptr ); 37 ~gl_index_buffer(); 37 38 private: 38 gl_buffer_name m_name;39 unsigned glid; 39 40 }; 40 41 -
trunk/src/gl/gl_context.cc
r299 r300 16 16 void gl_context::bind( texture2d* texture, texture_slot slot ) 17 17 { 18 GLuint id = static_cast< gl_texture2d* >( texture )-> m_name.get_value();18 GLuint id = static_cast< gl_texture2d* >( texture )->glid; 19 19 glActiveTexture( GL_TEXTURE0 + static_cast< GLenum >( slot ) ); 20 20 glBindTexture( GL_TEXTURE_2D, id ); … … 24 24 { 25 25 gl_program* glp = static_cast< gl_program* >( p ); 26 glUseProgram( glp-> m_name.get_value());26 glUseProgram( glp->glid ); 27 27 glp->update_uniforms(); 28 28 } … … 30 30 void nv::gl_context::bind( vertex_buffer* b ) 31 31 { 32 GLuint id = static_cast< gl_vertex_buffer* >( b )-> m_name.get_value();32 GLuint id = static_cast< gl_vertex_buffer* >( b )->glid; 33 33 glBindBuffer( GL_ARRAY_BUFFER, id ); 34 34 } … … 36 36 void nv::gl_context::bind( index_buffer* b ) 37 37 { 38 GLuint id = static_cast< gl_index_buffer* >( b )-> m_name.get_value();38 GLuint id = static_cast< gl_index_buffer* >( b )->glid; 39 39 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, id ); 40 40 } … … 96 96 void gl_context::update( texture2d* texture, void* data ) 97 97 { 98 GLuint id = static_cast< gl_texture2d* >( texture )-> m_name.get_value();98 GLuint id = static_cast< gl_texture2d* >( texture )->glid; 99 99 image_format format = texture->get_format(); 100 100 ivec2 size = texture->get_size(); -
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 } -
trunk/src/gl/gl_texture2d.cc
r299 r300 11 11 12 12 nv::gl_texture2d::gl_texture2d( ivec2 size, pixel_format aformat, datatype adatatype, sampler asampler, void* data /*= nullptr */ ) 13 : texture2d( size, aformat, adatatype, asampler ) , m_name()13 : texture2d( size, aformat, adatatype, asampler ) 14 14 { 15 glBindTexture( GL_TEXTURE_2D, m_name.get_value() ); 15 glGenTextures( 1, &glid ); 16 17 glBindTexture( GL_TEXTURE_2D, glid ); 16 18 17 19 // Detect if mipmapping was requested … … 27 29 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)nv::sampler_wrap_to_enum( m_sampler.wrap_t) ); 28 30 29 glBindTexture( GL_TEXTURE_2D, 0 );30 31 31 if (data) 32 32 { 33 glBindTexture( GL_TEXTURE_2D, m_name.get_value() );34 33 glTexImage2D( GL_TEXTURE_2D, 0, (GLint)nv::image_format_to_enum(m_format.format), m_size.x, m_size.y, 0, nv::image_format_to_enum(m_format.format), nv::datatype_to_gl_enum(m_format.type), data ); 35 glBindTexture( GL_TEXTURE_2D, 0 ); 34 } 35 36 glBindTexture( GL_TEXTURE_2D, 0 ); 37 } 38 39 nv::gl_texture2d::~gl_texture2d() 40 { 41 if ( glid != 0 ) 42 { 43 glDeleteTextures( 1, &glid ); 36 44 } 37 45 } -
trunk/src/gl/gl_vertex_buffer.cc
r299 r300 11 11 12 12 gl_vertex_buffer::gl_vertex_buffer( buffer_hint hint, size_t size, const void* data ) 13 : vertex_buffer( hint, size ) , m_name()13 : vertex_buffer( hint, size ) 14 14 { 15 glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() ); 15 glGenBuffers( 1, &glid ); 16 glBindBuffer( GL_ARRAY_BUFFER, glid ); 16 17 glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) ); 17 18 glBindBuffer( GL_ARRAY_BUFFER, 0 ); 18 19 } 19 20 21 nv::gl_vertex_buffer::~gl_vertex_buffer() 22 { 23 if ( glid != 0 ) 24 { 25 glDeleteBuffers( 1, &glid ); 26 } 27 } 28 20 29 gl_index_buffer::gl_index_buffer( buffer_hint hint, size_t size, const void* data ) 21 : index_buffer( hint, size ) , m_name()30 : index_buffer( hint, size ) 22 31 { 23 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() ); 32 glGenBuffers( 1, &glid ); 33 34 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, glid ); 24 35 glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) ); 25 36 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); 26 37 } 27 38 39 nv::gl_index_buffer::~gl_index_buffer() 40 { 41 if ( glid != 0 ) 42 { 43 glDeleteBuffers( 1, &glid ); 44 } 45 }
Note: See TracChangeset
for help on using the changeset viewer.