source: trunk/nv/gl/gl_context.hh @ 520

Last change on this file since 520 was 520, checked in by epyon, 9 years ago
  • ecs updates
  • animation updates
  • ragdoll manager
  • lua has own random engine
  • several minor fixes
  • particle engine/particle group
  • shitload of other stuff
  • bullet world
File size: 5.0 KB
Line 
1// Copyright (C) 2012-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
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
18namespace nv
19{
20        struct gl_framebuffer_info : public framebuffer_info
21        {
22                unsigned glid;
23                unsigned depth_rb_glid;
24        };
25
26        struct gl_vertex_array_info : public vertex_array_info
27        {
28                unsigned glid;
29        };
30
31
32        class gl_context : public context
33        {
34        public:
35                gl_context( device* a_device, void* a_handle );
36                virtual ~gl_context();
37
38                virtual vertex_array create_vertex_array( const vertex_array_desc& desc );
39                virtual framebuffer create_framebuffer( uint32 temp_samples = 1 );
40                using context::release;
41                virtual void release( vertex_array va );
42                virtual void release( framebuffer f );
43                virtual image_data* dump_image( image_format f, image_data* reuse );
44                virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const;
45
46                using context::create_texture;
47                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr );
48                virtual texture create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data = nullptr );
49
50                virtual buffer create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source = nullptr );
51                virtual void create_buffer( buffer, size_t, const void* = nullptr );
52
53                virtual void set_draw_buffers( uint32 count, const output_slot* slots );
54                virtual void set_draw_buffer( output_slot slot );
55                virtual void set_read_buffer( output_slot slot );
56                virtual void blit( framebuffer f, buffer_mask mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 );
57                virtual void blit( framebuffer from, framebuffer to, buffer_mask mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 );
58
59                virtual void attach( framebuffer f, output_slot slot, texture t, int layer = -1 );
60                virtual void attach( framebuffer f, texture depth, int layer = -1 );
61                virtual void attach( framebuffer f, ivec2 size );
62                virtual bool check( framebuffer_slot ft );
63                virtual void bind( framebuffer f, framebuffer_slot ft = FRAMEBUFFER );
64                virtual void bind( texture t, texture_slot slot );
65                virtual void bind( buffer b, uint32 index, size_t offset = 0, size_t size = 0 );
66                virtual void bind( buffer b, texture t );
67
68
69                virtual void update( texture t, const void* data );
70                virtual void update( buffer b, const void* data, size_t offset, size_t size );
71                virtual void* map_buffer( buffer, buffer_access, size_t /*offset*/, size_t /*length*/ );
72                virtual void unmap_buffer( buffer );
73
74                //              virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size );
75
76                virtual void clear( const clear_state& cs );
77                // temporary
78                virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count, size_t first = 0 );
79                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 );
80
81                virtual const ivec4& get_viewport();
82                virtual void set_viewport( const ivec4& viewport );
83                virtual void apply_render_state( const render_state& state );
84                virtual void apply_engine_uniforms( program p, const scene_state& s );
85                // TODO: remove
86                void* get_native_handle() { return m_handle; }
87
88        protected:
89                void bind( program p );
90                void bind( vertex_array va );
91                void unbind( program p );
92//              void unbind( buffer b );
93                void unbind( vertex_array va );
94                void unbind( framebuffer va );
95
96                void force_apply_render_state( const render_state& state );
97                void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
98        private:
99                void apply_stencil_test( const stencil_test& stencil );
100                void apply_stencil_face( unsigned face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
101                void apply_scissor_test( const scissor_test& scissor );
102                void apply_depth_test( const depth_test& depth );
103                void apply_depth_mask( bool mask );
104                void apply_multisample( bool multisample );
105                void apply_depth_range( const depth_range& range );
106                void apply_color_mask( const color_mask& mask );
107                void apply_blending( const blending& blend );
108                void apply_culling( const culling& cull );
109                void apply_polygon_mode( const polygon_mode& mode );
110                void enable( unsigned int what, bool value );
111                void set_active_texture( texture_slot slot );
112
113                bool validate_program( program p );
114        private:
115                texture_slot m_active_slot;
116                texture      m_bound_textures[ texture_slot::MAX_TEXTURES ];
117                program      m_bound_program;
118
119                vec4  m_clear_color;
120                float m_clear_depth;
121                int   m_clear_stencil;
122                void* m_handle;
123
124                handle_store< gl_vertex_array_info, vertex_array > m_vertex_arrays;
125                handle_store< gl_framebuffer_info, framebuffer >   m_framebuffers;
126        };
127
128
129} // namespace nv
130
131#endif // NV_CONTEXT_HH
Note: See TracBrowser for help on using the repository browser.