[319] | 1 | // Copyright (C) 2012-2014 ChaosForge Ltd
|
---|
[37] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
| 4 | // This file is part of NV Libraries.
|
---|
| 5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
| 6 | /**
|
---|
| 7 | * @file gl_context.hh
|
---|
| 8 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
| 9 | * @brief Context class
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | #ifndef NV_GL_CONTEXT_HH
|
---|
| 13 | #define NV_GL_CONTEXT_HH
|
---|
| 14 |
|
---|
| 15 | #include <nv/interface/context.hh>
|
---|
| 16 |
|
---|
| 17 | namespace nv
|
---|
| 18 | {
|
---|
[313] | 19 | struct gl_framebuffer_info : public framebuffer_info
|
---|
| 20 | {
|
---|
| 21 | unsigned glid;
|
---|
[331] | 22 | unsigned depth_rb_glid;
|
---|
[313] | 23 | };
|
---|
| 24 |
|
---|
[37] | 25 | class gl_context : public context
|
---|
| 26 | {
|
---|
| 27 | public:
|
---|
[326] | 28 | gl_context( device* a_device, void* a_handle );
|
---|
| 29 | virtual ~gl_context();
|
---|
[313] | 30 |
|
---|
| 31 | virtual vertex_array create_vertex_array();
|
---|
| 32 | virtual framebuffer create_framebuffer();
|
---|
| 33 | virtual void release( vertex_array va );
|
---|
| 34 | virtual void release( framebuffer f );
|
---|
| 35 | virtual const vertex_array_info* get_vertex_array_info( vertex_array va ) const;
|
---|
| 36 | virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const;
|
---|
| 37 |
|
---|
[342] | 38 | virtual void set_draw_buffers( uint32 count, const output_slot* slots );
|
---|
[331] | 39 | virtual void set_draw_buffer( output_slot slot );
|
---|
| 40 | virtual void set_read_buffer( output_slot slot );
|
---|
| 41 | virtual void blit( framebuffer f, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 );
|
---|
| 42 |
|
---|
| 43 | virtual void attach( framebuffer f, output_slot slot, texture t );
|
---|
| 44 | virtual void attach( framebuffer f, texture depth );
|
---|
| 45 | virtual void attach( framebuffer f, ivec2 size );
|
---|
| 46 | virtual bool check( framebuffer_slot ft );
|
---|
| 47 | virtual void bind( framebuffer f, framebuffer_slot ft = FRAMEBUFFER );
|
---|
[301] | 48 | virtual void bind( texture t, texture_slot slot );
|
---|
[299] | 49 |
|
---|
[301] | 50 | virtual void update( texture t, void* data );
|
---|
[302] | 51 | virtual void update( buffer b, const void* data, size_t offset, size_t size );
|
---|
[299] | 52 |
|
---|
[44] | 53 | virtual void clear( const clear_state& cs );
|
---|
[45] | 54 | // temporary
|
---|
[303] | 55 | virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count );
|
---|
[44] | 56 | virtual const ivec4& get_viewport();
|
---|
| 57 | virtual void set_viewport( const ivec4& viewport );
|
---|
| 58 | virtual void apply_render_state( const render_state& state );
|
---|
[303] | 59 | virtual void apply_engine_uniforms( program p, const scene_state& s );
|
---|
[326] | 60 | // TODO: remove
|
---|
| 61 | void* get_native_handle() { return m_handle; }
|
---|
[303] | 62 |
|
---|
[245] | 63 | protected:
|
---|
[313] | 64 | void bind( program p );
|
---|
| 65 | // void bind( buffer b );
|
---|
| 66 | void bind( vertex_array va );
|
---|
| 67 | void unbind( program p );
|
---|
| 68 | // void unbind( buffer b );
|
---|
| 69 | void unbind( vertex_array va );
|
---|
| 70 | void unbind( framebuffer va );
|
---|
| 71 |
|
---|
[37] | 72 | void force_apply_render_state( const render_state& state );
|
---|
[121] | 73 | void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
|
---|
[313] | 74 | // TODO: remove
|
---|
| 75 | virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array );
|
---|
[245] | 76 | private:
|
---|
[37] | 77 | void apply_stencil_test( const stencil_test& stencil );
|
---|
[121] | 78 | void apply_stencil_face( unsigned face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
|
---|
[37] | 79 | void apply_scissor_test( const scissor_test& scissor );
|
---|
| 80 | void apply_depth_test( const depth_test& depth );
|
---|
| 81 | void apply_depth_mask( bool mask );
|
---|
| 82 | void apply_depth_range( const depth_range& range );
|
---|
| 83 | void apply_color_mask( const color_mask& mask );
|
---|
| 84 | void apply_blending( const blending& blend );
|
---|
| 85 | void apply_culling( const culling& cull );
|
---|
[233] | 86 | void apply_polygon_mode( const polygon_mode& mode );
|
---|
[37] | 87 | void enable( unsigned int what, bool value );
|
---|
| 88 | private:
|
---|
| 89 | vec4 m_clear_color;
|
---|
| 90 | float m_clear_depth;
|
---|
| 91 | int m_clear_stencil;
|
---|
[326] | 92 | void* m_handle;
|
---|
[313] | 93 |
|
---|
[347] | 94 | handle_store< vertex_array_info, vertex_array > m_vertex_arrays;
|
---|
| 95 | handle_store< gl_framebuffer_info, framebuffer > m_framebuffers;
|
---|
[245] | 96 | };
|
---|
| 97 |
|
---|
[37] | 98 |
|
---|
| 99 | } // namespace nv
|
---|
| 100 |
|
---|
| 101 | #endif // NV_CONTEXT_HH
|
---|