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