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

Last change on this file since 491 was 491, checked in by epyon, 9 years ago
  • mass update (will try to do atomic from now)
File size: 3.8 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();
40                virtual void release( vertex_array va );
41                virtual void release( framebuffer f );
42                virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const;
43
44                virtual void set_draw_buffers( uint32 count, const output_slot* slots );
45                virtual void set_draw_buffer( output_slot slot );
46                virtual void set_read_buffer( output_slot slot );
47                virtual void blit( framebuffer f, clear_state::buffers_type mask, ivec2 src1, ivec2 src2, ivec2 dst1, ivec2 dst2 );
48
49                virtual void attach( framebuffer f, output_slot slot, texture t );
50                virtual void attach( framebuffer f, texture depth, int layer = -1 );
51                virtual void attach( framebuffer f, ivec2 size );
52                virtual bool check( framebuffer_slot ft );
53                virtual void bind( framebuffer f, framebuffer_slot ft = FRAMEBUFFER );
54                virtual void bind( texture t, texture_slot slot );
55                virtual void bind( buffer b, uint32 index, size_t offset = 0, size_t size = 0 );
56                virtual void bind( buffer b, texture t );
57
58
59                virtual void update( texture t, const void* data );
60                virtual void update( buffer b, const void* data, size_t offset, size_t size );
61                //              virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size );
62
63                virtual void clear( const clear_state& cs );
64                // temporary
65                virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count, size_t first = 0 );
66                virtual const ivec4& get_viewport();
67                virtual void set_viewport( const ivec4& viewport );
68                virtual void apply_render_state( const render_state& state );
69                virtual void apply_engine_uniforms( program p, const scene_state& s );
70                // TODO: remove
71                void* get_native_handle() { return m_handle; }
72
73        protected:
74                void bind( program p );
75//              void bind( buffer b );
76                void bind( vertex_array va );
77                void unbind( program p );
78//              void unbind( buffer b );
79                void unbind( vertex_array va );
80                void unbind( framebuffer va );
81
82                void force_apply_render_state( const render_state& state );
83                void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
84        private:
85                void apply_stencil_test( const stencil_test& stencil );
86                void apply_stencil_face( unsigned face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
87                void apply_scissor_test( const scissor_test& scissor );
88                void apply_depth_test( const depth_test& depth );
89                void apply_depth_mask( bool mask );
90                void apply_depth_range( const depth_range& range );
91                void apply_color_mask( const color_mask& mask );
92                void apply_blending( const blending& blend );
93                void apply_culling( const culling& cull );
94                void apply_polygon_mode( const polygon_mode& mode );
95                void enable( unsigned int what, bool value );
96        private:
97                vec4  m_clear_color;
98                float m_clear_depth;
99                int   m_clear_stencil;
100                void* m_handle;
101
102                handle_store< gl_vertex_array_info, vertex_array > m_vertex_arrays;
103                handle_store< gl_framebuffer_info, framebuffer >   m_framebuffers;
104        };
105
106
107} // namespace nv
108
109#endif // NV_CONTEXT_HH
Note: See TracBrowser for help on using the repository browser.