9 #ifndef GlobeEngine_Texture_h
10 #define GlobeEngine_Texture_h
12 #include "OpenGL_Includes.h"
17 #include <vmmlib/vector.hpp>
25 #include <ApplicationServices/ApplicationServices.h>
35 for (
int i = 0; i<D; i++) {
36 this->
param[i] = GL_CLAMP_TO_EDGE;
41 for (
int i = 0; i<D; i++) {
42 this->
param[i] = copy->param[i];
61 this->
param[0] = GL_CLAMP_TO_EDGE;
62 this->
param[1] = GL_CLAMP_TO_EDGE;
88 min = GL_NEAREST; mag = GL_NEAREST;
92 min = _min; mag = _mag;
100 void set(GLint _min, GLint _mag){
101 min = _min; mag = _mag;
133 this->
set(_colorComponents, _pixelformat,_datatype);
137 colorComponents = copy->colorComponents;
138 pixelformat = copy->pixelformat;
139 datatype = copy->datatype;
143 void set(GLint _colorComponents, GLenum _pixelformat, GLenum _datatype){
144 colorComponents = _colorComponents;
145 pixelformat = _pixelformat;
146 datatype = _datatype;
153 if (pixelformat == GL_RED || pixelformat == GL_R32F ||
154 pixelformat == GL_R8I || pixelformat == GL_R8 ||
155 pixelformat == GL_R16 || pixelformat == GL_R16F ||
156 pixelformat == GL_R16I || pixelformat == GL_R16UI ||
157 pixelformat == GL_R32UI || pixelformat == GL_R32I)
161 else if (pixelformat == GL_RGB || pixelformat == GL_BGR){
163 }
else if(pixelformat == GL_RGBA || pixelformat == GL_RGBA32F ||
164 pixelformat == GL_RGBA32I || pixelformat == GL_RGBA32UI ||
165 pixelformat == GL_BGRA || pixelformat == GL_RGBA32UI ||
166 pixelformat == GL_BGRA_INTEGER){
209 compareFunc = _compareFunc;
211 compareMode = _compareMode;
215 compareFunc = copy->compareFunc;
217 compareMode = copy->compareMode;
235 this->wrapProperties = copy->wrapProperties;
236 this->minmagParameters = copy->minmagParameters;
237 this->
type = copy->type;
263 for (
int i = 0; i<D; i++) {
275 for (
int i = 0; i<D; i++) {
285 glTexParameteri(this->
target, GL_TEXTURE_MIN_FILTER, this->
properties.minmag.min);
286 glTexParameteri(this->
target, GL_TEXTURE_MAG_FILTER, this->
properties.minmag.mag);
292 glGenerateMipmap(this->
target);
295 #ifndef GENGINE_GL_BELOW_410
298 GLboolean _layered, GLint _layer, GLenum _access) {
299 return glBindImageTexture(_unit, this->
handle, _level, _layered,
300 _layer, _access, this->internalFormat);
304 friend std::ostream& operator<< (std::ostream &out, const TextureType<D, T, PROPERTIES> &tex) {
305 out <<
"Dim: (" << tex.dim[0];
306 for (
int i = 1; i<D; i++) {
307 out <<
"," << tex.dim[i];
325 #ifndef GENGINE_GL_BELOW_410
326 return this->
textureBuffer.template mapBufferStorage<T>(storageSize);
328 return this->
textureBuffer.template mapBuffer<T>(storageSize);
361 vmml::vector< D, short>
dim;
383 this->
setSize(vmml::Vector1s(_width));
402 glTexParameteri(this->
target, GL_TEXTURE_WRAP_S, _wrap.
param[0]);
407 glTexImage2D(this->
target, 0, this->
properties.type.colorComponents, this->dim[0], 1, 0, this->properties.type.pixelformat, this->properties.type.datatype, _pixels);
442 if( _allocateTexImage )
449 this->
loadEmpty(_dim,_type,_minmag,_wrap,
false);
494 #ifndef GENGINE_GL_BELOW_410
497 this->
properties.type.colorComponents = _internalFormat;
498 glTextureStorage2DEXT(this->
handle, this->
target, _levels, this->
properties.type.colorComponents, this->dim[0], this->dim[1]);
505 imageRef = std::make_shared<Image>();
515 glTexParameteri(this->
target, GL_TEXTURE_WRAP_S, this->
properties.wrap.param[0]);
516 if (-1 != _wrap.
param[1]) {
517 glTexParameteri(this->
target, GL_TEXTURE_WRAP_T, this->
properties.wrap.param[1]);
523 glTexImage2D(this->
target, 0, this->
properties.type.colorComponents, this->dim[0], this->dim[1], 0, this->properties.type.pixelformat, this->properties.type.datatype, _pixels);
593 glTexParameteri(this->
target, GL_DEPTH_TEXTURE_MODE, _prop.
mode);
606 #ifndef GENGINE_GL_BELOW_410
607 glTexParameteri(this->
target, GL_DEPTH_STENCIL_TEXTURE_MODE, _mode);
630 int sumDim = this->
dim.x() * this->
dim.y() * this->
dim.z();
644 int sumDim = this->
dim.x() * this->
dim.y() * this->
dim.z();
656 glTexParameteri(this->
target, GL_TEXTURE_WRAP_S, _wrap.
param[0]);
657 if (-1 != _wrap.
param[1]) {
658 glTexParameteri(this->
target, GL_TEXTURE_WRAP_T, _wrap.
param[1]);
660 if (-1 != _wrap.
param[2]) {
661 glTexParameteri(this->
target, GL_TEXTURE_WRAP_R, _wrap.
param[2]);
667 glTexImage3D(this->
target, 0, this->
properties.type.colorComponents, this->dim[0], this->dim[1], this->dim[2], 0, this->properties.type.pixelformat, this->properties.type.datatype, _pixels);
Texture1D< GLubyte, TextureProperties< TextureWrapParameter< 1 > > > Texture1Drgb
Definition: Texture.h:415
std::string getName()
Definition: Texture.h:313
Texture2D< GLshort, TextureProperties< TextureWrapParameter< 2 > > > Texture2Ds
Definition: Texture.h:533
void setWrapParameter(TextureWrapParameter3D _wrap)
Definition: Texture.h:654
TextureWrapParameter2D(GLint _s, GLint _t)
Definition: Texture.h:65
Texture3D< GLushort, TextureProperties< TextureWrapParameter< 3 > > > Texture3Dus
Definition: Texture.h:677
TextureWrapParameter()
Definition: Texture.h:34
TextureProperties< TextureWrapParameter1D > TextureProperties1D
Definition: Texture.h:245
GLuint load(const vmml::Vector3s &_dim, TextureTypeInternals _type, float *_data)
Definition: Texture.h:627
GLuint loadFromImage(std::string _filename)
Definition: Texture.h:484
Definition: Texture.h:105
void setWrapParameter(TextureWrapParameter2D _wrap)
Definition: Texture.h:512
Definition: Texture.h:249
GLint compareFunc
Definition: Texture.h:198
TextureMinMagParameters minmag
Definition: Texture.h:241
short getHeight() const
Definition: Texture.h:314
TextureDepthProperties(GLint _compareFunc, GLenum _mode, GLenum _compareMode)
Definition: Texture.h:208
const T & getData() const
Definition: Texture.h:321
void unmapStoragePointer()
Definition: Texture.h:345
WRAP wrap
Definition: Texture.h:242
DepthTexture< GLubyte, TextureProperties< TextureWrapParameter< 2 > > > DepthMap2Drgba
Definition: Texture.h:616
void setDepthParameter(TextureDepthProperties _prop)
Definition: Texture.h:588
Texture2D< GLubyte, TextureProperties< TextureWrapParameter< 2 > > > Texture2Drgb
Definition: Texture.h:541
void clear()
Definition: Buffer.h:29
Texture2D< GLubyte, TextureProperties< TextureWrapParameter< 2 > > > Texture2Drgba
Definition: Texture.h:542
Texture2D< GLubyte, TextureProperties< TextureWrapParameter< 2 > > > Texture2Dub
Definition: Texture.h:539
GLuint load(short _width, TextureTypeInternals _type, T *_data)
Definition: Texture.h:391
void setDepthStencilMode(GLenum _mode)
Definition: Texture.h:603
GLenum target
Definition: TextureHandle.h:83
static TextureTypeInternals r32ui()
Definition: Texture.h:175
GLint param[D]
Definition: Texture.h:46
void setTextureData(T *_pixels)
Definition: Texture.h:405
GLuint loadEmpty(short _width, TextureTypeInternals _type)
Definition: Texture.h:381
void bindTextureForCompute(GLuint _unit, GLint _level, GLboolean _layered, GLint _layer, GLenum _access)
Definition: Texture.h:297
TextureWrapParameter1D(GLint _in)
Definition: Texture.h:52
Texture2D< GLushort, TextureProperties< TextureWrapParameter< 2 > > > Texture2Dus
Definition: Texture.h:534
Texture3D< GLshort, TextureProperties< TextureWrapParameter< 3 > > > Texture3Ds
Definition: Texture.h:676
TextureWrapParameter2D()
Definition: Texture.h:60
TextureDepthProperties()
Definition: Texture.h:202
void generateMipMaps()
Definition: Texture.h:290
static TextureTypeInternals rgba32i()
Definition: Texture.h:186
TextureTypeInternals(GLint _colorComponents, GLenum _pixelformat, GLenum _datatype)
Definition: Texture.h:132
void setTextureData(T *_pixels)
Definition: Texture.h:665
TextureMinMagParameters(GLint _min, GLint _mag)
Definition: Texture.h:91
TextureDepthProperties(const std::shared_ptr< TextureDepthProperties > copy)
Definition: Texture.h:214
Texture2D< GLfloat, TextureProperties< TextureWrapParameter< 2 > > > Texture2Dhdr
Definition: Texture.h:537
GLenum datatype
Definition: Texture.h:119
static TextureTypeInternals r16us()
Definition: Texture.h:176
Texture3D< GLfloat, TextureProperties< TextureWrapParameter< 3 > > > Texture3Df
Definition: Texture.h:679
GLuint load(const vmml::Vector2s &_dim, TextureTypeInternals _type, TextureMinMagParameters _minmag, TextureWrapParameter2D _wrap, T *_data)
Definition: Texture.h:447
GLint colorComponents
Definition: Texture.h:110
Texture3D< GLubyte, TextureProperties< TextureWrapParameter< 3 > > > Texture3Drgba
Definition: Texture.h:684
GLenum getType() const
Definition: Texture.h:320
GLint mode
Definition: Texture.h:199
DepthTexture()
Definition: Texture.h:558
short getWidth() const
Definition: Texture.h:315
void unpackPBO()
Definition: Texture.h:350
void setSize(vmml::vector< D, short > _dim)
Definition: Texture.h:357
GLuint loadSynchWithDefaultParameter(const vmml::Vector2s &_dim, TextureTypeInternals _type, T *_data)
Definition: Texture.h:462
void setWrapParameter(TextureWrapParameter1D _wrap)
Definition: Texture.h:398
void createHandle(GLenum _target)
Definition: TextureHandle.cpp:43
std::shared_ptr< ge::Image > imageRef
Definition: Texture.h:526
static TextureTypeInternals rgba32f()
Definition: Texture.h:185
void preloadCommit()
Definition: Texture.h:474
TextureTypeInternals type
Definition: Texture.h:240
GLuint loadEmptyWithDefaultParameter(vmml::Vector2s _dim, TextureTypeInternals _type, bool _allocateTexImage=true)
Definition: Texture.h:428
T * data
Definition: Texture.h:362
TextureProperties(TextureTypeInternals _type, TextureMinMagParameters _minmag, WRAP _wrap)
Definition: Texture.h:225
static TextureTypeInternals rgba8i()
Definition: Texture.h:183
static TextureTypeInternals rgba8()
Definition: Texture.h:182
virtual void setTextureData(T *_pixels)=0
void set(GLint _min, GLint _mag)
Definition: Texture.h:100
static TextureTypeInternals r32f()
Definition: Texture.h:173
Definition: Texture.h:623
Definition: Texture.h:376
void bind(GLint _unit=-1) const
Definition: TextureHandle.cpp:65
Texture1D< GLfloat, TextureProperties< TextureWrapParameter< 1 > > > Texture1Df
Definition: Texture.h:413
Definition: Texture.h:423
GLint mag
Definition: Texture.h:85
int getStorageSize() const
Definition: Texture.h:316
Texture2D< GLuint, TextureProperties< TextureWrapParameter< 2 > > > Texture2Dui
Definition: Texture.h:531
void setTextureStorage(const vmml::Vector2s &_dim, GLsizei _levels, GLenum _internalFormat)
Definition: Texture.h:495
Texture3D< GLubyte, TextureProperties< TextureWrapParameter< 3 > > > Texture3Dub
Definition: Texture.h:682
Texture2D< GLfloat, TextureProperties< TextureWrapParameter< 2 > > > Texture2Df
Definition: Texture.h:536
GLint getInternalFormat() const
Definition: Texture.h:318
TextureWrapParameter(const std::shared_ptr< TextureWrapParameter > copy)
Definition: Texture.h:40
Definition: Texture.h:555
static TextureTypeInternals rgba32ui()
Definition: Texture.h:187
GLenum pixelformat
Definition: Texture.h:114
GLuint loadEmpty(const vmml::Vector2s &_dim, TextureTypeInternals _type, TextureMinMagParameters _minmag, TextureWrapParameter2D _wrap, bool _allocateTexImage=true)
Definition: Texture.h:435
TextureMinMagParameters(const std::shared_ptr< TextureMinMagParameters > copy)
Definition: Texture.h:95
TextureType()
Definition: Texture.h:252
Definition: Texture.h:196
Texture3D< GLfloat, TextureProperties< TextureWrapParameter< 3 > > > Texture3Dhdr
Definition: Texture.h:680
TextureTypeInternals()
Definition: Texture.h:126
GLint compareMode
Definition: Texture.h:200
GLint min
Definition: Texture.h:84
Texture1D< GLubyte, TextureProperties< TextureWrapParameter< 1 > > > Texture1Dub
Definition: Texture.h:414
Texture3D()
Definition: Texture.h:626
GLuint loadEmpty(const vmml::Vector3s &_dim, TextureTypeInternals _type)
Definition: Texture.h:641
vmml::vector< D, short > dim
Definition: Texture.h:361
void bindBuffer()
Definition: Buffer.h:96
GLuint loadWithDefaultParameter(const vmml::Vector2s &_dim, TextureTypeInternals _type, T *_data)
Definition: Texture.h:455
Texture3D< GLuint, TextureProperties< TextureWrapParameter< 3 > > > Texture3Dui
Definition: Texture.h:674
TextureProperties(const std::shared_ptr< TextureProperties > copy)
Definition: Texture.h:234
void loadDataToPBO(T *_data)
Definition: Texture.h:336
TextureMinMagParameters()
Definition: Texture.h:87
void setTextureData(T *_pixels)
Definition: Texture.h:521
Texture3D< GLint, TextureProperties< TextureWrapParameter< 3 > > > Texture3Di
Definition: Texture.h:673
Texture3D< GLubyte, TextureProperties< TextureWrapParameter< 3 > > > Texture3Drgb
Definition: Texture.h:683
static TextureTypeInternals r16ui()
Definition: Texture.h:177
TextureTypeInternals(const std::shared_ptr< TextureTypeInternals > copy)
Definition: Texture.h:136
void setComponentCount()
Definition: Texture.h:150
~TextureType()
Definition: Texture.h:257
int countPixel() const
Definition: Texture.h:273
void clear()
Definition: Texture.h:261
GLenum getFormat() const
Definition: Texture.h:319
TextureProperties()
Definition: Texture.h:224
Texture1D()
Definition: Texture.h:379
vmml::vector< D, short > getDimensions() const
Definition: Texture.h:317
TextureWrapParameter3D(GLint _s, GLint _t, GLint _r)
Definition: Texture.h:74
Definition: AvalancheTrainingSimulationEngine.h:28
static TextureTypeInternals rgba8ui()
Definition: Texture.h:184
void set(GLint _colorComponents, GLenum _pixelformat, GLenum _datatype)
Definition: Texture.h:143
static TextureTypeInternals rg8()
Definition: Texture.h:180
void getOpenGLError(std::string _input)
Definition: TextureHandle.cpp:137
Texture2D< GLint, TextureProperties< TextureWrapParameter< 2 > > > Texture2Di
Definition: Texture.h:530
void unmapBuffer()
Definition: Buffer.h:91
void loadImage(std::string _filename)
Definition: Texture.h:504
Texture1D< GLubyte, TextureProperties< TextureWrapParameter< 1 > > > Texture1Drgba
Definition: Texture.h:416
TextureProperties< TextureWrapParameter3D > TextureProperties3D
Definition: Texture.h:247
GLuint handle
Definition: TextureHandle.h:84
static TextureTypeInternals rg16f()
Definition: Texture.h:179
Definition: Texture.h:221
PROPERTIES properties
Definition: Texture.h:366
void preloadSyncWithDefaultParameter(const vmml::Vector2s &_dim, TextureTypeInternals _type, T *_data)
Definition: Texture.h:469
Texture2D< GLubyte, TextureProperties< TextureWrapParameter< 2 > > > Texture2Drg
Definition: Texture.h:540
static TextureTypeInternals rgb8()
Definition: Texture.h:181
ge::PixelUnpackBuffer textureBuffer
Definition: Texture.h:368
static TextureTypeInternals r16f()
Definition: Texture.h:178
GLuint loadEmpty(const vmml::Vector2s &_dim, TextureTypeInternals _type, TextureMinMagParameters _minmag, TextureWrapParameter2D _wrap)
Definition: Texture.h:573
static TextureTypeInternals r32i()
Definition: Texture.h:174
void setMinMagParameter(TextureMinMagParameters _minmag)
Definition: Texture.h:281
Texture2D()
Definition: Texture.h:426
void unbindBuffer()
Definition: Buffer.h:100
GLuint loadEmpty(const vmml::Vector2s &_dim, TextureTypeInternals _type, TextureMinMagParameters _minmag, TextureWrapParameter2D _wrap, TextureDepthProperties _prop)
Definition: Texture.h:560
std::string name
Definition: Texture.h:363
T * mapStoragePointer()
Definition: Texture.h:323
void unbind(GLint _unit=-1) const
Definition: TextureHandle.cpp:77
Definition: TextureHandle.h:18
short compCount
Definition: Texture.h:108
TextureProperties< TextureWrapParameter2D > TextureProperties2D
Definition: Texture.h:246