OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Heightmap.h
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 HEIGHTMAP_H__
22 #define HEIGHTMAP_H__
23 
24 #include <GLES3/gl3.h>
25 #include "vector_math.h"
26 #include <vector>
27 
28 class Heightmap
29 {
30 public:
31  Heightmap(unsigned int size, unsigned int levels);
32  ~Heightmap();
33 
34  void update_heightmap(const std::vector<vec2>& level_offsets);
35  void reset();
36  GLuint get_texture() const { return texture; }
37 
38 private:
41  unsigned int pixel_buffer_index;
42  unsigned int pixel_buffer_size;
43  unsigned int size;
44  unsigned int levels;
45 
46  struct LevelInfo
47  {
48  int x; // top-left coord of texture in texels.
49  int y;
50  bool cleared;
51  };
52  std::vector<LevelInfo> level_info;
53 
54  struct UploadInfo
55  {
56  int x;
57  int y;
58  int width;
59  int height;
60  int level;
61  uintptr_t offset;
62  };
63  std::vector<UploadInfo> upload_info;
64 
65  void update_level(vec2 *buffer, unsigned int& pixel_offset, const vec2& level_offset, unsigned level);
66  vec2 compute_heightmap(int x, int y, int level);
67  float sample_heightmap(int x, int y);
68  void update_region(vec2 *buffer, unsigned int& pixel_offset, int x, int y,
69  int width, int height,
70  int start_x, int start_y,
71  int level);
72 
73  std::vector<float> heightmap;
74  unsigned int heightmap_size;
75  void init_heightmap();
76 };
77 
78 #endif
Heightmap(unsigned int size, unsigned int levels)
Definition: Heightmap.cpp:31
void update_level(vec2 *buffer, unsigned int &pixel_offset, const vec2 &level_offset, unsigned level)
[Update region]
Definition: Heightmap.cpp:240
void update_heightmap(const std::vector< vec2 > &level_offsets)
Definition: Heightmap.cpp:415
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
void reset()
Definition: Heightmap.cpp:69
Definition: matrix.h:28
unsigned int pixel_buffer_size
Definition: Heightmap.h:42
GLuint get_texture() const
Definition: Heightmap.h:36
void init_heightmap()
Definition: Heightmap.cpp:116
std::vector< UploadInfo > upload_info
Definition: Heightmap.h:63
unsigned int size
Definition: Heightmap.h:43
unsigned int levels
Definition: Heightmap.h:44
GLsizei levels
Definition: gl2ext.h:1816
vec2 compute_heightmap(int x, int y, int level)
[Compute heightmap]
Definition: Heightmap.cpp:197
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629
void update_region(vec2 *buffer, unsigned int &pixel_offset, int x, int y, int width, int height, int start_x, int start_y, int level)
[Compute heightmap]
Definition: Heightmap.cpp:212
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
float sample_heightmap(int x, int y)
Definition: Heightmap.cpp:186
GLenum GLuint GLint level
Definition: gl2ext.h:385
GLenum GLuint buffer
Definition: gl2ext.h:628
GLuint texture
Definition: Heightmap.h:39
GLint GLsizei width
Definition: gl2ext.h:179
std::vector< LevelInfo > level_info
Definition: Heightmap.h:52
unsigned int heightmap_size
Definition: Heightmap.h:74
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
GLuint pixel_buffer[2]
Definition: Heightmap.h:40
GLint y
Definition: gl2ext.h:179
std::vector< float > heightmap
Definition: Heightmap.h:73
unsigned int pixel_buffer_index
Definition: Heightmap.h:41