Changeset 44
- Timestamp:
- 05/28/13 16:48:29 (12 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gl/gl_context.hh
r37 r44 20 20 { 21 21 public: 22 void clear( const clear_state& cs ); 23 const ivec4& get_viewport(); 24 void set_viewport( const ivec4& viewport ); 25 22 gl_context(); 23 virtual void clear( const clear_state& cs ); 24 virtual const ivec4& get_viewport(); 25 virtual void set_viewport( const ivec4& viewport ); 26 virtual void apply_render_state( const render_state& state ); 26 27 private: 27 28 void force_apply_render_state( const render_state& state ); 28 29 void force_apply_stencil_face( int face, const stencil_test_face& stencil ); 29 void apply_render_state( const render_state& state );30 30 void apply_stencil_test( const stencil_test& stencil ); 31 31 void apply_stencil_face( int face, stencil_test_face& stencil, const stencil_test_face& new_stencil ); -
trunk/nv/gl/gl_device.hh
r42 r44 24 24 virtual program* create_program( const string& vs_source, const string& fs_source ); 25 25 virtual vertex_buffer* create_vertex_buffer( buffer_hint hint, int size, void* source = nullptr ); 26 virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ); 27 virtual vertex_array* create_vertex_array(); 26 28 virtual ~gl_device(); 27 29 private: -
trunk/nv/gl/gl_vertex_buffer.hh
r42 r44 31 31 }; 32 32 33 class gl_index_buffer : public index_buffer 34 { 35 public: 36 gl_index_buffer( buffer_hint hint, int size, void* data = nullptr ); 37 virtual void assign( void* data ); 38 virtual void bind(); 39 virtual void unbind(); 40 virtual bool is_valid() const; 41 private: 42 gl_buffer_name m_name; 43 }; 44 45 class gl_vertex_array : public vertex_array 46 { 47 public: 48 gl_vertex_array(); 49 virtual void bind(); 50 virtual void unbind(); 51 }; 52 33 53 } // namespace nv 34 54 -
trunk/nv/gl/gl_window.hh
r38 r44 14 14 15 15 #include <nv/interface/window.hh> 16 #include <nv/gl/gl_context.hh> 16 17 17 18 namespace nv … … 26 27 string get_title() const; 27 28 void set_title( const string& title ); 29 virtual context* get_context() { return m_context; } 30 ~gl_window(); 28 31 private: 29 uint16 m_width; 30 uint16 m_height; 31 string m_title; 32 void* m_screen; 32 uint16 m_width; 33 uint16 m_height; 34 string m_title; 35 void* m_screen; 36 gl_context* m_context; 33 37 }; 34 38 -
trunk/nv/interface/context.hh
r32 r44 23 23 public: 24 24 virtual void clear( const clear_state& cs ) = 0; 25 virtual void apply_render_state( const render_state& state ) = 0; 26 virtual const ivec4& get_viewport() = 0; 27 virtual void set_viewport( const ivec4& viewport ) = 0; 25 28 protected: 26 29 clear_state m_clear_state; -
trunk/nv/interface/device.hh
r42 r44 28 28 virtual program* create_program( const string& vs_source, const string& fs_source ) = 0; 29 29 virtual vertex_buffer* create_vertex_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0; 30 virtual index_buffer* create_index_buffer( buffer_hint hint, int size, void* source = nullptr ) = 0; 31 virtual vertex_array* create_vertex_array() = 0; 30 32 }; 31 33 -
trunk/nv/interface/vertex_buffer.hh
r42 r44 14 14 15 15 #include <nv/common.hh> 16 #include <nv/types.hh> 17 #include <unordered_map> 18 #include <string> 16 19 17 20 namespace nv … … 25 28 }; 26 29 27 class vertex_buffer30 class buffer 28 31 { 29 32 public: 30 vertex_buffer( buffer_hint hint, int size ) { m_size = size; m_hint = hint; }33 buffer( buffer_hint hint, int size ) { m_size = size; m_hint = hint; } 31 34 virtual void assign( void* data ) = 0; 32 35 virtual void bind() = 0; … … 40 43 }; 41 44 45 class vertex_buffer : public buffer 46 { 47 public: 48 vertex_buffer( buffer_hint hint, int size ) : buffer( hint, size ) {} 49 }; 50 51 class index_buffer : public buffer 52 { 53 public: 54 index_buffer( buffer_hint hint, int size ) : buffer( hint, size ) {} 55 }; 56 57 class vertex_buffer_attribute 58 { 59 public: 60 vertex_buffer_attribute( vertex_buffer* buffer, type datatype, int components, int offset = 0, int stride = 0, bool owner = true ) 61 : m_buffer( buffer ), m_datatype( datatype ), m_components( components ), m_offset( offset ), m_stride( stride ), m_owner( owner ) {} 62 63 vertex_buffer* get_buffer() const { return m_buffer; } 64 type get_datatype() const { return m_datatype; } 65 int get_components() const { return m_components; } 66 int get_offset() const { return m_offset; } 67 int get_stride() const { return m_stride; } 68 69 ~vertex_buffer_attribute() 70 { 71 if (m_owner) 72 { 73 delete m_buffer; 74 } 75 } 76 protected: 77 vertex_buffer* m_buffer; 78 type m_datatype; 79 int m_components; 80 int m_offset; 81 int m_stride; 82 bool m_owner; 83 }; 84 85 typedef std::unordered_map< int, vertex_buffer_attribute* > vertex_buffer_attribute_map; 86 87 class vertex_array 88 { 89 public: 90 vertex_array() : m_map(), m_index( nullptr ) {} 91 void add_vertex_buffer( int location, vertex_buffer* buffer, type datatype, int components, int offset = 0, int stride = 0, bool owner = true ) 92 { 93 m_map[ location ] = new vertex_buffer_attribute( buffer, datatype, components, offset, stride, owner ); 94 }; 95 void set_index_buffer( index_buffer* buffer ) { m_index = buffer; } 96 virtual void bind() = 0; 97 virtual void unbind() = 0; 98 ~vertex_array() { 99 for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); i != m_map.end(); ++i ) 100 { 101 delete i->second; 102 } 103 if (m_index) delete m_index; 104 } 105 protected: 106 vertex_buffer_attribute_map m_map; 107 index_buffer* m_index; 108 }; 109 110 42 111 } // namespace nv 43 112 -
trunk/nv/interface/window.hh
r32 r44 18 18 namespace nv 19 19 { 20 20 class context; 21 21 class window 22 22 { … … 26 26 virtual string get_title() const = 0; 27 27 virtual void set_title( const string& title ) = 0; 28 virtual context* get_context() = 0; 28 29 }; 29 30 -
trunk/nv/types.hh
r37 r44 16 16 enum type 17 17 { 18 INT, 19 BYTE, 20 SHORT, 21 UINT, 22 UBYTE, 23 USHORT, 18 24 FLOAT, 19 25 FLOAT_VECTOR_2, … … 23 29 FLOAT_MATRIX_3, 24 30 FLOAT_MATRIX_4, 25 INT,26 31 INT_VECTOR_2, 27 32 INT_VECTOR_3, … … 43 48 template < type EnumType > struct enum_to_type {}; 44 49 50 template <> struct enum_to_type< INT > { typedef int type; }; 51 template <> struct enum_to_type< UINT > { typedef unsigned int type; }; 52 template <> struct enum_to_type< SHORT > { typedef short type; }; 53 template <> struct enum_to_type< USHORT >{ typedef unsigned short type; }; 54 template <> struct enum_to_type< BYTE > { typedef char type; }; 55 template <> struct enum_to_type< UBYTE > { typedef unsigned char type; }; 45 56 template <> struct enum_to_type< FLOAT > { typedef f32 type; }; 46 template <> struct enum_to_type< INT > { typedef int type; };47 57 48 58 template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; }; … … 60 70 template < typename Type > struct type_to_enum {}; 61 71 72 template <> struct type_to_enum< int > { static const type type = INT; }; 73 template <> struct type_to_enum< unsigned int > { static const type type = UINT; }; 74 template <> struct type_to_enum< short > { static const type type = SHORT; }; 75 template <> struct type_to_enum< unsigned short >{ static const type type = USHORT; }; 76 template <> struct type_to_enum< char > { static const type type = BYTE; }; 77 template <> struct type_to_enum< unsigned char > { static const type type = UBYTE; }; 62 78 template <> struct type_to_enum< f32 > { static const type type = FLOAT; }; 63 template <> struct type_to_enum< int > { static const type type = INT; };64 79 65 80 template <> struct type_to_enum< vec2 > { static const type type = FLOAT_VECTOR_2; }; -
trunk/src/gl/gl_context.cc
r37 r44 13 13 { 14 14 // apply_framebuffer 15 15 16 apply_scissor_test( cs.scissor_test ); 16 17 apply_color_mask( cs.color_mask ); … … 35 36 m_clear_stencil = cs.stencil; 36 37 } 37 38 glClear( c s.buffers);38 39 glClear( clear_state_buffers_to_mask( cs.buffers ) ); 39 40 } 40 41 … … 347 348 } 348 349 350 351 gl_context::gl_context() 352 { 353 force_apply_render_state( m_render_state ); 354 } -
trunk/src/gl/gl_device.cc
r42 r44 56 56 } 57 57 58 index_buffer* gl_device::create_index_buffer( buffer_hint hint, int size, void* source /*= nullptr */ ) 59 { 60 return new gl_index_buffer( hint, size, source ); 61 } 62 63 vertex_array* gl_device::create_vertex_array() 64 { 65 return new gl_vertex_array(); 66 } 67 58 68 gl_device::~gl_device() 59 69 { -
trunk/src/gl/gl_enum.cc
r43 r44 186 186 switch( type ) 187 187 { 188 case BYTE : return GL_BYTE; 189 case UBYTE : return GL_UNSIGNED_BYTE; 190 case SHORT : return GL_SHORT; 191 case USHORT : return GL_UNSIGNED_SHORT; 192 case INT : return GL_INT; 193 case UINT : return GL_UNSIGNED_INT; 188 194 case FLOAT : return GL_FLOAT; 189 195 case FLOAT_VECTOR_2 : return GL_FLOAT_VEC2; … … 193 199 case FLOAT_MATRIX_3 : return GL_FLOAT_MAT3; 194 200 case FLOAT_MATRIX_4 : return GL_FLOAT_MAT4; 195 case INT : return GL_INT;196 201 case INT_VECTOR_2 : return GL_INT_VEC2; 197 202 case INT_VECTOR_3 : return GL_INT_VEC3; … … 205 210 switch( gl_enum ) 206 211 { 207 case GL_FLOAT : return FLOAT; 208 case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2; 209 case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3; 210 case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4; 211 case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2; 212 case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3; 213 case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4; 214 case GL_INT : return INT; 215 case GL_INT_VEC2 : return INT_VECTOR_2; 216 case GL_INT_VEC3 : return INT_VECTOR_3; 217 case GL_INT_VEC4 : return INT_VECTOR_4; 212 case GL_BYTE : return BYTE; 213 case GL_UNSIGNED_BYTE : return UBYTE; 214 case GL_SHORT : return SHORT; 215 case GL_UNSIGNED_SHORT : return USHORT; 216 case GL_INT : return INT; 217 case GL_UNSIGNED_INT : return UINT; 218 case GL_FLOAT : return FLOAT; 219 case GL_FLOAT_VEC2 : return FLOAT_VECTOR_2; 220 case GL_FLOAT_VEC3 : return FLOAT_VECTOR_3; 221 case GL_FLOAT_VEC4 : return FLOAT_VECTOR_4; 222 case GL_FLOAT_MAT2 : return FLOAT_MATRIX_2; 223 case GL_FLOAT_MAT3 : return FLOAT_MATRIX_3; 224 case GL_FLOAT_MAT4 : return FLOAT_MATRIX_4; 225 case GL_INT_VEC2 : return INT_VECTOR_2; 226 case GL_INT_VEC3 : return INT_VECTOR_3; 227 case GL_INT_VEC4 : return INT_VECTOR_4; 218 228 default : return type(0); // TODO: throw! 219 229 } -
trunk/src/gl/gl_vertex_buffer.cc
r42 r44 40 40 return m_name.is_valid(); 41 41 } 42 43 gl_index_buffer::gl_index_buffer( buffer_hint hint, int size, void* data ) 44 : index_buffer( hint, size ), m_name() 45 { 46 if (data) 47 { 48 assign( data ); 49 } 50 } 51 52 void gl_index_buffer::assign( void* data ) 53 { 54 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() ); 55 glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_size, data, buffer_hint_to_enum( m_hint ) ); 56 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0); 57 } 58 59 void gl_index_buffer::bind() 60 { 61 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() ); 62 } 63 64 void gl_index_buffer::unbind() 65 { 66 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); 67 } 68 69 bool gl_index_buffer::is_valid() const 70 { 71 return m_name.is_valid(); 72 } 73 74 gl_vertex_array::gl_vertex_array() 75 { 76 77 } 78 79 void gl_vertex_array::bind() 80 { 81 for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); i != m_map.end(); ++i ) 82 { 83 int location = i->first; 84 vertex_buffer_attribute* va = i->second; 85 vertex_buffer* vb = va->get_buffer(); 86 glEnableVertexAttribArray( location ); 87 vb->bind(); 88 glVertexAttribPointer( 89 location, 90 va->get_components(), 91 nv::type_to_gl_enum( va->get_datatype() ), 92 GL_FALSE, 93 va->get_stride(), 94 (void*)va->get_offset() 95 ); 96 vb->unbind(); 97 } 98 99 } 100 101 void gl_vertex_array::unbind() 102 { 103 for ( vertex_buffer_attribute_map::iterator i = m_map.begin(); i != m_map.end(); ++i ) 104 { 105 glDisableVertexAttribArray( i->first ); 106 } 107 } -
trunk/src/gl/gl_window.cc
r38 r44 29 29 NV_LOG( LOG_INFO, "OpenGL Version : " << glGetString(GL_VERSION) ); 30 30 NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) ); 31 32 m_context = new gl_context(); 33 m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) ); 31 34 } 32 35 … … 51 54 m_title = title; 52 55 } 56 57 gl_window::~gl_window() 58 { 59 delete m_context; 60 }
Note: See TracChangeset
for help on using the changeset viewer.