OGLplus  (0.59.0) a C++ wrapper for rendering APIs

resources.hpp
1 
9 #ifndef OGLPLUS_EXAMPLE_RESOURCES_HPP // NOLINT(llvm-header-guard)
10 #define OGLPLUS_EXAMPLE_RESOURCES_HPP
11 
12 #include <oglplus/gl.hpp>
13 #include <oglplus/gl_api.hpp>
14 
16 #include <eagine/double_buffer.hpp>
17 #include <eagine/quantities.hpp>
19 
20 namespace eagine::application {
21 //------------------------------------------------------------------------------
22 // program
23 //------------------------------------------------------------------------------
24 class cube_program {
25 public:
26  void init(execution_context&, video_context&);
27  void clean_up(video_context&);
28  void set_texture(video_context&, oglp::gl_types::int_type);
29  void set_projection(video_context&, const oglp::tmat<float, 4, 4, true>&);
30  void update(execution_context&, video_context&);
31 
32  void bind_position_location(video_context&, oglp::vertex_attrib_location);
33  void bind_normal_location(video_context&, oglp::vertex_attrib_location);
34  void bind_tex_coord_location(video_context&, oglp::vertex_attrib_location);
35 
36 private:
38  oglp::uniform_location projection_loc;
39  oglp::uniform_location modelview_loc;
40  oglp::uniform_location light_pos_loc;
41  oglp::uniform_location cube_tex_loc;
42 
43  radians_t<float> rad{0.F};
44 };
45 //------------------------------------------------------------------------------
46 // geometry
47 //------------------------------------------------------------------------------
48 class cube_geometry {
49 public:
50  void init(execution_context&, video_context&);
51  void clean_up(video_context&);
52  void draw(video_context&);
53 
54  static auto position_loc() noexcept {
56  }
57 
58  static auto normal_loc() noexcept {
60  }
61 
62  static auto tex_coord_loc() noexcept {
64  }
65 
66 private:
68 
69  oglp::owned_buffer_name positions;
70  oglp::owned_buffer_name normals;
71  oglp::owned_buffer_name tex_coords;
72  oglp::owned_buffer_name indices;
73 
74  std::vector<oglp::shape_draw_operation> ops;
75 };
76 //------------------------------------------------------------------------------
77 // draw buffers
78 //------------------------------------------------------------------------------
79 class cube_draw_buffers {
80 public:
81  void init(execution_context&, video_context&);
82  void clean_up(video_context&);
83 
84  auto back_fbo() const noexcept {
85  return oglp::framebuffer_name{objs.back().fbo};
86  }
87 
88  auto front_tex_unit() const noexcept {
89  return objs.front().tex_unit;
90  }
91 
92  auto side() const noexcept {
93  return tex_side;
94  }
95 
96  void swap() {
97  objs.swap();
98  }
99 
100 private:
101  const oglp::gl_types::sizei_type tex_side{512};
102 
103  struct _buffer_objects {
104  oglp::gl_types::int_type tex_unit{};
108  };
109 
110  double_buffer<_buffer_objects> objs{};
111 };
112 //------------------------------------------------------------------------------
113 } // namespace eagine::application
114 
115 #endif
Application harness / wrapper code is placed in this namespace.
Definition: eagine.hpp:72
GLsizei sizei_type
Signed integer size type.
Definition: config.hpp:88
prog_var_location< EAGINE_ID_V(Uniform)> uniform_location
Alias for shader program uniform location wrapper.
Definition: prog_var_loc.hpp:115
GLint int_type
Signed integer type.
Definition: config.hpp:70
gl_owned_object_name< renderbuffer_tag > owned_renderbuffer_name
Alias for owned GL renderbuffer object handle.
Definition: object_name.hpp:198
gl_owned_object_name< texture_tag > owned_texture_name
Alias for owned GL texture object handle.
Definition: object_name.hpp:213
gl_object_name< framebuffer_tag > framebuffer_name
Alias for GL framebuffer object handle.
Definition: object_name.hpp:118
gl_owned_object_name< vertex_array_tag > owned_vertex_array_name
Alias for owned GL vertex array object handle.
Definition: object_name.hpp:224
prog_var_location< EAGINE_ID_V(VertexAttr)> vertex_attrib_location
Alias for program vertex attribute location wrapper.
Definition: prog_var_loc.hpp:104
gl_owned_object_name< program_tag > owned_program_name
Alias for owned GL program object handle.
Definition: object_name.hpp:188
gl_owned_object_name< framebuffer_tag > owned_framebuffer_name
Alias for owned GL framebuffer object handle.
Definition: object_name.hpp:178

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).