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

Last change on this file since 319 was 319, checked in by epyon, 11 years ago
  • created core module and moved all free source files there
  • took the opportunity to update all copyright lines and minor cleanup
  • minor fixes
  • not all examples are up to date
File size: 3.3 KB
Line 
1// Copyright (C) 2012-2014 ChaosForge Ltd
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
17namespace nv
18{
19        struct gl_framebuffer_info : public framebuffer_info
20        {
21                unsigned glid;
22        };
23
24        class gl_context : public context
25        {
26        protected:
27                gl_context( device* a_device );
28        public:
29                ~gl_context();
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
38                virtual void bind( texture t, texture_slot slot );
39
40                virtual void update( texture t, void* data );
41                virtual void update( buffer b, const void* data, size_t offset, size_t size );
42
43                virtual void clear( const clear_state& cs );
44                // temporary
45                virtual void draw( primitive prim, const render_state& rs, program p, vertex_array va, size_t count );
46                virtual const ivec4& get_viewport();
47                virtual void set_viewport( const ivec4& viewport );
48                virtual void apply_render_state( const render_state& state );
49                virtual void apply_engine_uniforms( program p, const scene_state& s );
50
51        protected:
52                void bind( program p );
53//              void bind( buffer b );
54                void bind( vertex_array va );
55                void bind( framebuffer va );
56                void unbind( program p );
57//              void unbind( buffer b );
58                void unbind( vertex_array va );
59                void unbind( framebuffer va );
60
61                void force_apply_render_state( const render_state& state );
62                void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
63                // TODO: remove
64                virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array );
65        private:
66                void apply_stencil_test( const stencil_test& stencil );
67                void apply_stencil_face( unsigned face, stencil_test_face& stencil, const stencil_test_face& new_stencil );
68                void apply_scissor_test( const scissor_test& scissor );
69                void apply_depth_test( const depth_test& depth );
70                void apply_depth_mask( bool mask );
71                void apply_depth_range( const depth_range& range );
72                void apply_color_mask( const color_mask& mask );
73                void apply_blending( const blending& blend );
74                void apply_culling( const culling& cull );
75                void apply_polygon_mode( const polygon_mode& mode );
76                void enable( unsigned int what, bool value );
77        private:
78                vec4  m_clear_color;
79                float m_clear_depth;
80                int   m_clear_stencil;
81
82                entity_store< vertex_array_info, vertex_array >  m_vertex_arrays;
83                entity_store< gl_framebuffer_info, framebuffer > m_framebuffers;
84        };
85
86        class sdl_gl_context : public gl_context
87        {
88        public:
89                sdl_gl_context( device* a_device, void* a_sdl_win_handle );
90                ~sdl_gl_context();
91        private:
92                void* m_handle;
93        };
94
95        class native_gl_context : public gl_context
96        {
97        public:
98                native_gl_context( device* a_device, void* a_native_win_handle );
99                void* get_native_handle() { return m_handle; }
100                ~native_gl_context();
101        private:
102                void* m_handle;
103        };
104
105
106} // namespace nv
107
108#endif // NV_CONTEXT_HH
Note: See TracBrowser for help on using the repository browser.