1 #ifndef INCLUDE_AL_GRAPHICS_TEXTURE_HPP
2 #define INCLUDE_AL_GRAPHICS_TEXTURE_HPP
48 #include "al/graphics/al_GPUObject.hpp"
49 #include "al/graphics/al_OpenGL.hpp"
60 #define AL_TEX_MAX_BINDING_UNIT 48
62 #define AL_TEX_TEMP_BINDING_UNIT 47
92 enum DataType :
unsigned int {
94 UBYTE = GL_UNSIGNED_BYTE,
96 USHORT = GL_UNSIGNED_SHORT,
98 UINT = GL_UNSIGNED_INT,
103 enum Target :
unsigned int {
104 TEX_1D = GL_TEXTURE_1D,
105 TEX_2D = GL_TEXTURE_2D,
106 TEX_3D = GL_TEXTURE_3D,
107 TEX_1D_ARRAY = GL_TEXTURE_1D_ARRAY,
108 TEX_2D_ARRAY = GL_TEXTURE_2D_ARRAY,
109 TEX_RECTANGLE = GL_TEXTURE_RECTANGLE,
110 TEX_CUBE_MAP = GL_TEXTURE_CUBE_MAP,
111 TEX_BUFFER = GL_TEXTURE_BUFFER,
112 TEX_2D_MULTISAMPLE = GL_TEXTURE_2D_MULTISAMPLE,
113 TEX_2D_MULTISAMPLE_ARRAY = GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
118 CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
119 CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER,
120 MIRRORED_REPEAT = GL_MIRRORED_REPEAT,
125 NEAREST = GL_NEAREST,
128 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
129 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
130 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
131 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
134 enum Format :
unsigned int {
141 DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
142 DEPTH_STENCIL = GL_DEPTH_STENCIL
145 enum Internal :
int {
146 RGBA32F = GL_RGBA32F,
148 RGBA16F = GL_RGBA16F,
150 SRGB8_ALPHA8 = GL_SRGB8_ALPHA8,
167 DEPTH_COMPONENT32F = GL_DEPTH_COMPONENT32F,
168 DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
169 DEPTH_COMPONENT16 = GL_DEPTH_COMPONENT16,
170 DEPTH32F_STENCIL8 = GL_DEPTH32F_STENCIL8,
171 DEPTH24_STENCIL8 = GL_DEPTH24_STENCIL8
179 void create1D(GLsizei
width, GLint
internal = GL_RGBA8,
180 GLenum
format = GL_RGBA, GLenum
type = GL_UNSIGNED_BYTE);
182 void create2D(
unsigned int width,
unsigned int height,
183 int internal = GL_RGBA8,
unsigned int format = GL_RGBA,
184 unsigned int type = GL_UNSIGNED_BYTE
187 void create2DArray(
unsigned int width,
unsigned int height,
unsigned int depth,
188 int internal = GL_RGBA8,
unsigned int format = GL_RGBA,
189 unsigned int type = GL_UNSIGNED_BYTE);
194 unsigned int size,
int internal = GL_RGBA8,
unsigned int format = GL_RGBA,
195 unsigned int type = GL_UNSIGNED_BYTE
200 void bind(
int binding_point = 0);
207 void unbind_temp() {
unbind(AL_TEX_TEMP_BINDING_UNIT,
target()); }
208 static void unbind(
int binding_point,
unsigned int target);
211 unsigned int target()
const {
return mTarget; }
217 unsigned int format()
const {
return mFormat; }
220 unsigned int type()
const {
return mType; }
223 unsigned int width()
const {
return mWidth; }
226 unsigned int height()
const {
return mHeight; }
229 unsigned int depth()
const {
return mDepth; }
238 int wrapS()
const {
return mWrapS; }
241 int wrapT()
const {
return mWrapT; }
244 int wrapR()
const {
return mWrapR; }
246 bool mipmap()
const {
return mUseMipmap; }
267 bool resize(
unsigned int w,
unsigned int h,
int internal,
unsigned int format,
269 bool resize(
unsigned int w,
unsigned int h) {
270 return resize(w, h, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
274 void resize(
unsigned w,
unsigned h,
unsigned d) {}
289 void wrap(
int S,
int T,
int R);
297 void wrapS(
int v) {
wrap(v, mWrapT, mWrapR); }
298 void wrapT(
int v) {
wrap(mWrapS, v, mWrapR); }
299 void wrapR(
int v) {
wrap(mWrapS, mWrapT, v); }
321 void generateMipmap();
322 void disableMipmap();
334 int texx = 0,
int texy = 0,
int texz = 0);
348 void update_filter();
350 void update_mipmap();
355 void update_param(
const T &v, T &var,
bool &flag) {
362 unsigned int mTarget = GL_TEXTURE_2D;
363 int mInternalFormat = GL_RGBA8;
364 unsigned int mWidth = 0, mHeight = 0, mDepth = 0;
365 unsigned int mFormat = GL_RGBA;
366 unsigned int mType = GL_UNSIGNED_BYTE;
368 int mWrapS = GL_CLAMP_TO_EDGE, mWrapT = GL_CLAMP_TO_EDGE,
369 mWrapR = GL_CLAMP_TO_EDGE;
370 int mFilterMin = GL_NEAREST, mFilterMag = GL_NEAREST;
371 bool mUseMipmap =
false;
373 bool mFilterUpdated =
true;
374 bool mWrapUpdated =
true;
375 bool mUsingMipmapUpdated =
true;
void filter(int v)
Set minification and magnification filter types all at once.
int filterMin() const
Get minification filter type.
unsigned int width() const
Get width, in pixels.
void wrap(int S, int T)
Set 2D wrapping modes.
void filterMag(int v)
Set magnification filter type.
void onCreate() override
Called when currently assigned context is created.
unsigned int type() const
Get pixel component data type.
void wrap(int v)
Set wrapping mode for all dimensions.
void unbind(int binding_point=0)
Unbind the texture (from a multitexture unit)
int filterMag() const
Get magnification filter type.
bool resize(unsigned int w, unsigned int h, int internal, unsigned int format, unsigned int type)
Resize 2D texture.
unsigned int height() const
Get height, in pixels.
void resize(unsigned w, unsigned h, unsigned d)
Resize 3D texture.
void wrap(int S, int T, int R)
Set 3D wrapping modes.
unsigned int target() const
Get target type (e.g., TEXTURE_2D)
unsigned int format() const
Get pixel (color) format.
int internalFormat() const
Get internal format.
void filterMin(int v)
Set minification filter type.
int wrapR() const
Get R wrapping type.
void bind(int binding_point=0)
void resize(unsigned w)
Get number of components per pixel.
unsigned numComponents() const
Get number of components per pixel.
static int numComponents(Texture::Format v)
Returns number of components for given color type.
void onDestroy() override
Called when currently assigned context is destroyed.
void submit(const void *pixels, unsigned int format, unsigned int type)
int wrapT() const
Get T wrapping type.
int wrapS() const
Get S wrapping type.
void mipmap(bool b)
Set whether to generate mipmaps.
void copyFrameBuffer(int w=-1, int h=-1, int fbx=0, int fby=0, int texx=0, int texy=0, int texz=0)
Copy pixels from current frame buffer to texture texels.
unsigned int depth() const
Get depth, in pixels.
Color represented by red, green, and blue components.