[395] | 1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
[37] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
| 6 |
|
---|
[37] | 7 | /**
|
---|
| 8 | * @file gl_context.hh
|
---|
| 9 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
| 10 | * @brief Context class
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef NV_GL_CONTEXT_HH
|
---|
| 14 | #define NV_GL_CONTEXT_HH
|
---|
| 15 |
|
---|
| 16 | #include <nv/interface/context.hh>
|
---|
| 17 |
|
---|
| 18 | namespace nv
|
---|
| 19 | {
|
---|
[313] | 20 | struct gl_framebuffer_info : public framebuffer_info
|
---|
| 21 | {
|
---|
| 22 | unsigned glid;
|
---|
[331] | 23 | unsigned depth_rb_glid;
|
---|
[313] | 24 | };
|
---|
| 25 |
|
---|
[491] | 26 | struct gl_vertex_array_info : public vertex_array_info
|
---|
| 27 | {
|
---|
| 28 | unsigned glid;
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 |
|
---|
[37] | 32 | class gl_context : public context
|
---|
| 33 | {
|
---|
| 34 | public:
|
---|
[326] | 35 | gl_context( device* a_device, void* a_handle );
|
---|
| 36 | virtual ~gl_context();
|
---|
[313] | 37 |
|
---|
[491] | 38 | virtual vertex_array create_vertex_array( const vertex_array_desc& desc );
|
---|
[492] | 39 | virtual framebuffer create_framebuffer( uint32 temp_samples = 1 );
|
---|
[501] | 40 | using context::release;
|
---|
[313] | 41 | virtual void release( vertex_array va );
|
---|
| 42 | virtual void release( framebuffer f );
|
---|
| 43 | virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const;
|
---|
| 44 |
|
---|
[501] | 45 | using context::create_texture;
|
---|
| 46 | virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr );
|
---|
| 47 | virtual texture create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data = nullptr );
|
---|
| 48 |
|
---|
| 49 | virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr );
|
---|
| 50 | virtual void create_buffer( buffer, size_t, const void* = nullptr );
|
---|
| 51 |
|
---|
[342] | 52 | virtual void set_draw_buffers( uint32 count, const output_slot* slots );
|
---|
[331] | 53 | virtual void set_draw_buffer( output_slot slot );
|
---|
| 54 | virtual void set_read_buffer( output_slot slot );
|
---|
| 55 | virtual void blit( framebuffer f, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 );
|
---|
[492] | 56 | virtual void blit( framebuffer from, framebuffer to, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 );
|
---|
[331] | 57 |
|
---|
[500] | 58 | virtual void attach( framebuffer f, output_slot slot, texture t, int layer = -1 );
|
---|
[463] | 59 | virtual void attach( framebuffer f, texture depth, int layer = -1 );
|
---|
[331] | 60 | virtual void attach( framebuffer f, ivec2 size );
|
---|
| 61 | virtual bool check( framebuffer_slot ft );
|
---|
| 62 | virtual void bind( framebuffer f, framebuffer_slot ft = FRAMEBUFFER );
|
---|
[301] | 63 | virtual void bind( texture t, texture_slot slot );
|
---|
[473] | 64 | virtual void bind( buffer b, uint32 index, size_t offset = 0, size_t size = 0 );
|
---|
[491] | 65 | virtual void bind( buffer b, texture t );
|
---|
[299] | 66 |
|
---|
[491] | 67 |
|
---|
[406] | 68 | virtual void update( texture t, const void* data );
|
---|
[302] | 69 | virtual void update( buffer b, const void* data, size_t offset, size_t size );
|
---|
[499] | 70 | virtual void* map_buffer( buffer, buffer_access, size_t /*offset*/, size_t /*length*/ );
|
---|
| 71 | virtual void unmap_buffer( buffer );
|
---|
| 72 |
|
---|
[491] | 73 | // virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size );
|
---|
[299] | 74 |
|
---|
[44] | 75 | virtual void clear( const clear_state& cs );
|
---|
[45] | 76 | // temporary
|
---|
[473] | 77 | virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count, size_t first = 0 );
|
---|
[502] | 78 | virtual void draw_instanced( primitive prim, const render_state& rs, program p, size_t instances, vertex_array va, size_t count, size_t first = 0 );
|
---|
| 79 |
|
---|
[44] | 80 | virtual const ivec4& get_viewport();
|
---|
| 81 | virtual void set_viewport( const ivec4& viewport );
|
---|
| 82 | virtual void apply_render_state( const render_state& state );
|
---|
[303] | 83 | virtual void apply_engine_uniforms( program p, const scene_state& s );
|
---|
[326] | 84 | // TODO: remove
|
---|
| 85 | void* get_native_handle() { return m_handle; }
|
---|
[303] | 86 |
|
---|
[245] | 87 | protected:
|
---|
[313] | 88 | void bind( program p );
|
---|
| 89 | void bind( vertex_array va );
|
---|
| 90 | void unbind( program p );
|
---|
| 91 | // void unbind( buffer b );
|
---|
| 92 | void unbind( vertex_array va );
|
---|
| 93 | void unbind( framebuffer va );
|
---|
| 94 |
|
---|
[37] | 95 | void force_apply_render_state( const render_state& state );
|
---|
[121] | 96 | void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
|
---|
[245] | 97 | private:
|
---|
[37] | 98 | void apply_stencil_test( const stencil_test& stencil );
|
---|
[121] | 99 | void apply_stencil_face( unsigned face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
|
---|
[37] | 100 | void apply_scissor_test( const scissor_test& scissor );
|
---|
| 101 | void apply_depth_test( const depth_test& depth );
|
---|
| 102 | void apply_depth_mask( bool mask );
|
---|
[492] | 103 | void apply_multisample( bool multisample );
|
---|
[37] | 104 | void apply_depth_range( const depth_range& range );
|
---|
| 105 | void apply_color_mask( const color_mask& mask );
|
---|
| 106 | void apply_blending( const blending& blend );
|
---|
| 107 | void apply_culling( const culling& cull );
|
---|
[233] | 108 | void apply_polygon_mode( const polygon_mode& mode );
|
---|
[37] | 109 | void enable( unsigned int what, bool value );
|
---|
[492] | 110 | void set_active_texture( texture_slot slot );
|
---|
[493] | 111 |
|
---|
| 112 | bool validate_program( program p );
|
---|
[37] | 113 | private:
|
---|
[492] | 114 | texture_slot m_active_slot;
|
---|
| 115 | texture m_bound_textures[ texture_slot::MAX_TEXTURES ];
|
---|
[501] | 116 | program m_bound_program;
|
---|
| 117 |
|
---|
[37] | 118 | vec4 m_clear_color;
|
---|
| 119 | float m_clear_depth;
|
---|
| 120 | int m_clear_stencil;
|
---|
[326] | 121 | void* m_handle;
|
---|
[313] | 122 |
|
---|
[491] | 123 | handle_store< gl_vertex_array_info, vertex_array > m_vertex_arrays;
|
---|
| 124 | handle_store< gl_framebuffer_info, framebuffer > m_framebuffers;
|
---|
[245] | 125 | };
|
---|
| 126 |
|
---|
[37] | 127 |
|
---|
| 128 | } // namespace nv
|
---|
| 129 |
|
---|
| 130 | #endif // NV_CONTEXT_HH
|
---|