OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
glfft_common.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015 Hans-Kristian Arntzen <maister@archlinux.us>
2  *
3  * Permission is hereby granted, free of charge,
4  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation the rights to
6  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17  */
18 
19 #include "glfft_common.hpp"
20 
21 using namespace std;
22 using namespace GLFFT;
23 
24 Texture::~Texture()
25 {
26  if (name)
27  {
28  GL_CHECK(glDeleteTextures(1, &name));
29  }
30 }
31 
32 Texture::Texture(GLuint tex)
33  : name(tex)
34 {}
35 
36 void Texture::init(unsigned width, unsigned height, unsigned levels, GLenum internal_format,
37  GLenum wrap_s, GLenum wrap_t, GLenum min_filter, GLenum mag_filter)
38 {
39  if (name)
40  {
41  GL_CHECK(glDeleteTextures(1, &name));
42  }
43  GL_CHECK(glGenTextures(1, &name));
44  GL_CHECK(glBindTexture(GL_TEXTURE_2D, name));
45  GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, levels, internal_format, width, height));
46  GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s));
47  GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t));
48  GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter));
49  GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter));
50  GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
51 }
52 
54  unsigned x_off, unsigned y_off, unsigned width, unsigned height)
55 {
56  if (!name)
57  {
58  throw logic_error("Cannot upload to null-texture.");
59  }
60  GL_CHECK(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
61  GL_CHECK(glBindTexture(GL_TEXTURE_2D, name));
62  GL_CHECK(glTexSubImage2D(GL_TEXTURE_2D, 0, x_off, y_off, width, height, format, type, data));
63  GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
64 }
65 
67 {
68  if (this != &texture)
69  {
70  if (name)
71  {
72  GL_CHECK(glDeleteTextures(1, &name));
73  }
74  name = texture.name;
75  texture.name = 0;
76  }
77  return *this;
78 }
79 
81 {
82  *this = move(texture);
83 }
84 
86 {
87  if (name)
88  {
89  GL_CHECK(glDeleteBuffers(1, &name));
90  }
91 }
92 
94  : name(buffer)
95 {}
96 
97 void Buffer::init(const void *data, size_t size, GLenum access)
98 {
99  if (name)
100  {
101  GL_CHECK(glDeleteBuffers(1, &name));
102  }
103  GL_CHECK(glGenBuffers(1, &name));
104  GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, name));
105  GL_CHECK(glBufferData(GL_SHADER_STORAGE_BUFFER, size, data, access));
106 }
107 
109 {
110  if (this != &buffer)
111  {
112  if (name)
113  {
114  GL_CHECK(glDeleteBuffers(1, &name));
115  }
116  name = buffer.name;
117  buffer.name = 0;
118  }
119  return *this;
120 }
121 
123 {
124  *this = move(buffer);
125 }
126 
128  : name(prog)
129 {}
130 
132 {
133  if (name)
134  {
135  GL_CHECK(glDeleteProgram(name));
136  }
137 }
138 
140 {
141  if (this != &prog)
142  {
143  if (name)
144  {
145  GL_CHECK(glDeleteProgram(name));
146  }
147  name = prog.name;
148  prog.name = 0;
149  }
150  return *this;
151 }
152 
154 {
155  *this = move(prog);
156 }
157 
158 
Buffer()=default
GLenum access
Definition: gl2ext.h:1958
Buffer & operator=(Buffer &&buffer)
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
void upload(const void *data, GLenum format, GLenum type, unsigned x_off, unsigned y_off, unsigned width, unsigned height)
void init(unsigned width, unsigned height, unsigned levels, GLenum internal_format, GLenum wrap_s=GL_REPEAT, GLenum wrap_t=GL_REPEAT, GLenum min_filter=GL_NEAREST, GLenum mag_filter=GL_NEAREST)
GLint GLsizei GLsizei GLenum format
Definition: gl2ext.h:179
Texture & operator=(Texture &&texture)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
Definition: gl2ext.h:179
Program & operator=(Program &&prog)
void init(const void *data, size_t size, GLenum access)
#define GL_CHECK(x)
Definition: AstcTextures.h:59
GLsizei levels
Definition: gl2ext.h:1816
GLenum GLuint texture
Definition: gl2ext.h:385
GLenum type
Definition: gl2ext.h:133
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629
GLuint name
Definition: gl2ext.h:139
GLenum GLuint buffer
Definition: gl2ext.h:628
Texture()=default
GLint GLsizei width
Definition: gl2ext.h:179
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
Program()=default