OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scene.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef SCENE_HPP__
22 #define SCENE_HPP__
23 
24 #include "mesh.hpp"
25 #include "culling.hpp"
26 #include <vector>
27 #include <stdint.h>
28 
29 class Scene
30 {
31  public:
32  Scene();
33  ~Scene();
34 
35  void update(float delta_time, unsigned width, unsigned height);
36  void render(unsigned width, unsigned height);
37  void move_camera(float delta_x, float delta_y);
38 
40  CullHiZ = 0,
42  CullNone = -1
43  };
44  void set_culling_method(CullingMethod method);
45 
46  void set_physics_speed(float speed) { physics_speed = speed; }
47  float get_physics_speed() const { return physics_speed; }
49  bool get_show_redundant() const { return show_redundant; }
50 
51  private:
54  std::vector<CullingInterface*> culling_implementations;
55 
57 
60 
61  void render_spheres(vec3 color_mod);
62 
63  void bake_occluder_geometry(std::vector<vec4> &occluder_positions,
64  std::vector<uint32_t> &occluder_indices,
65  const Mesh &box_mesh, const vec4 *instances, unsigned num_instances);
66 
69 
72 
73  // Allow for readbacks of atomic counter without stalling GPU pipeline.
74 #define INDIRECT_BUFFERS 4
75  struct
76  {
78  unsigned buffer_index;
80  } indirect;
81 
82  void init_instances();
89 
90  void apply_physics(float delta_time);
92 
93  void render_depth_map();
94 
97 
100  void update_camera(float rotation_y, float rotation_x, unsigned viewport_width, unsigned viewport_height);
101 };
102 
103 #endif
104 
unsigned num_occluder_instances
Definition: scene.hpp:86
void render(unsigned width, unsigned height)
Definition: scene.cpp:373
mat4 view
Definition: scene.hpp:96
void set_physics_speed(float speed)
Definition: scene.hpp:46
Definition: matrix.h:51
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
void bake_occluder_geometry(std::vector< vec4 > &occluder_positions, std::vector< uint32_t > &occluder_indices, const Mesh &box_mesh, const vec4 *instances, unsigned num_instances)
Definition: scene.cpp:94
~Scene()
Definition: scene.cpp:451
void update(float delta_time, unsigned width, unsigned height)
Definition: scene.cpp:282
void render_spheres(vec3 color_mod)
Definition: scene.cpp:335
void apply_physics(float delta_time)
Definition: scene.cpp:265
bool show_redundant
Definition: scene.hpp:58
GLuint sphere_program
Definition: scene.hpp:68
void move_camera(float delta_x, float delta_y)
Definition: scene.cpp:83
Definition: matrix.h:75
unsigned culling_implementation_index
Definition: scene.hpp:56
Scene()
Definition: scene.cpp:56
GLDrawable * box
Definition: scene.hpp:52
bool enable_culling
Definition: scene.hpp:59
unsigned num_render_sphere_instances
Definition: scene.hpp:88
GLuint sphere_instances_buffer
Definition: scene.hpp:85
void set_culling_method(CullingMethod method)
Definition: scene.cpp:251
std::vector< CullingInterface * > culling_implementations
Definition: scene.hpp:54
Definition: scene.hpp:29
bool get_show_redundant() const
Definition: scene.hpp:49
GLboolean enable
Definition: gl2ext.h:780
unsigned num_sphere_render_lods
Definition: scene.hpp:87
static float delta_x
Definition: app.cpp:85
float camera_rotation_y
Definition: scene.hpp:98
void set_show_redundant(bool enable)
Definition: scene.hpp:48
mat4 projection
Definition: scene.hpp:95
GLDrawable quad
Definition: scene.hpp:70
#define INDIRECT_BUFFERS
Definition: scene.hpp:74
GLuint occluder_program
Definition: scene.hpp:67
#define SPHERE_LODS
Definition: culling.hpp:29
GLuint quad_program
Definition: scene.hpp:71
static float delta_y
Definition: app.cpp:86
Definition: matrix.h:104
GLenum GLuint buffer
Definition: gl2ext.h:628
float camera_rotation_x
Definition: scene.hpp:99
GLDrawable * sphere[SPHERE_LODS]
Definition: scene.hpp:53
struct Scene::@26 indirect
float physics_speed
Definition: scene.hpp:91
CullingMethod
Definition: scene.hpp:39
GLint GLsizei width
Definition: gl2ext.h:179
void render_depth_map()
Definition: scene.cpp:429
float get_physics_speed() const
Definition: scene.hpp:47
GLuint occluder_instances_buffer
Definition: scene.hpp:84
void init_instances()
Definition: scene.cpp:138
GLuint instance_buffer[SPHERE_LODS]
Definition: scene.hpp:79
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
unsigned buffer_index
Definition: scene.hpp:78
GLuint physics_program
Definition: scene.hpp:83
void update_camera(float rotation_y, float rotation_x, unsigned viewport_width, unsigned viewport_height)
Definition: scene.cpp:231