Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ACGL
acgl
Commits
77c39515
Commit
77c39515
authored
Feb 07, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started working on new texture classes, first iteration of TextureRectangle
parent
81399d36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
17 deletions
+185
-17
include/ACGL/OpenGL/Objects/Texture.hh
include/ACGL/OpenGL/Objects/Texture.hh
+76
-6
src/ACGL/OpenGL/Objects/Texture.cc
src/ACGL/OpenGL/Objects/Texture.cc
+109
-11
No files found.
include/ACGL/OpenGL/Objects/Texture.hh
View file @
77c39515
...
@@ -54,8 +54,7 @@ public:
...
@@ -54,8 +54,7 @@ public:
mWidth
(
0
),
mWidth
(
0
),
mHeight
(
1
),
mHeight
(
1
),
mDepth
(
1
),
mDepth
(
1
),
mInternalFormat
(
GL_RGBA
),
mInternalFormat
(
GL_RGBA
)
mType
(
GL_UNSIGNED_BYTE
)
{
{
glGenTextures
(
1
,
&
mObjectName
);
glGenTextures
(
1
,
&
mObjectName
);
if
(
openGLCriticalErrorOccured
()
)
{
if
(
openGLCriticalErrorOccured
()
)
{
...
@@ -79,7 +78,6 @@ public:
...
@@ -79,7 +78,6 @@ public:
inline
GLsizei
getHeight
(
void
)
const
{
return
mHeight
;
}
inline
GLsizei
getHeight
(
void
)
const
{
return
mHeight
;
}
inline
GLsizei
getDepth
(
void
)
const
{
return
mDepth
;
}
inline
GLsizei
getDepth
(
void
)
const
{
return
mDepth
;
}
inline
GLenum
getInternalFormat
(
void
)
const
{
return
mInternalFormat
;
}
inline
GLenum
getInternalFormat
(
void
)
const
{
return
mInternalFormat
;
}
inline
GLenum
getType
(
void
)
const
{
return
mType
;
}
inline
GLint
getMinFilter
(
void
)
const
{
return
getParameterI
(
GL_TEXTURE_MIN_FILTER
);
}
inline
GLint
getMinFilter
(
void
)
const
{
return
getParameterI
(
GL_TEXTURE_MIN_FILTER
);
}
inline
GLint
getMagFilter
(
void
)
const
{
return
getParameterI
(
GL_TEXTURE_MAG_FILTER
);
}
inline
GLint
getMagFilter
(
void
)
const
{
return
getParameterI
(
GL_TEXTURE_MAG_FILTER
);
}
inline
GLint
getMinLOD
(
void
)
const
{
return
getParameterI
(
GL_TEXTURE_MIN_LOD
);
}
inline
GLint
getMinLOD
(
void
)
const
{
return
getParameterI
(
GL_TEXTURE_MIN_LOD
);
}
...
@@ -160,8 +158,7 @@ protected:
...
@@ -160,8 +158,7 @@ protected:
GLsizei
mWidth
;
GLsizei
mWidth
;
GLsizei
mHeight
;
GLsizei
mHeight
;
GLsizei
mDepth
;
GLsizei
mDepth
;
GLenum
mInternalFormat
;
GLenum
mInternalFormat
;
// often used, so store it here
GLenum
mType
;
// Checks what texture is currently bound at the texture target used by this texture
// Checks what texture is currently bound at the texture target used by this texture
// to be later used to restore that texture (to be side effect free). Then binds this texture.
// to be later used to restore that texture (to be side effect free). Then binds this texture.
...
@@ -170,9 +167,80 @@ protected:
...
@@ -170,9 +167,80 @@ protected:
// generic get parameter functions:
// generic get parameter functions:
GLfloat
getParameterF
(
GLenum
_name
)
const
;
GLfloat
getParameterF
(
GLenum
_name
)
const
;
GLint
getParameterI
(
GLenum
_name
)
const
;
GLint
getParameterI
(
GLenum
_name
)
const
;
//! returns a format compatible with the internal, only used to
//! reserve memory, not to upload actual data!
GLenum
getCompatibleFormat
(
GLenum
_internalFormat
);
GLenum
getCompatibleType
(
GLenum
_internalFormat
);
};
};
ACGL_SMARTPOINTER_TYPEDEFS
(
TextureBase
)
ACGL_SMARTPOINTER_TYPEDEFS
(
TextureBase
)
// missing classes:
// GL_TEXTURE_1D
// GL_TEXTURE_2D
// GL_TEXTURE_3D
// GL_TEXTURE_1D_ARRAY
// GL_TEXTURE_2D_ARRAY
// GL_TEXTURE_RECTANGLE
// GL_TEXTURE_2D_MULTISAMPLE
// GL_TEXTURE_2D_MULTISAMPLE_ARRAY
// GL_TEXTURE_BINDING_CUBE_MAP
// GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
// the combination of Image and SharedTextureBase will identify a Rendertarget etc.:
struct
Image
{
unsigned
int
mipmapLevel
;
// always 0 if texture has no mipmaps
unsigned
int
layer
;
// array layer or slice in a 3D texture, always 0 if texture is 1D or 2D
GLenum
cubeMapFace
;
// GL_INVALID_ENUM if texture is not a cube map
};
class
TextureRectangle
:
public
TextureBase
{
public:
TextureRectangle
(
GLenum
_internalFormat
=
GL_RGBA
)
:
TextureBase
(
GL_TEXTURE_RECTANGLE
)
{
mInternalFormat
=
_internalFormat
;
// default would be MipMapped but that's not supported for Rect Textures!
setMinFilter
(
GL_LINEAR
);
}
TextureRectangle
(
const
glm
::
uvec2
&
_size
,
GLenum
_internalFormat
=
GL_RGBA
)
:
TextureBase
(
GL_TEXTURE_RECTANGLE
)
{
mInternalFormat
=
_internalFormat
;
// default would be MipMapped but that's not supported for Rect Textures!
setMinFilter
(
GL_LINEAR
);
resize
(
_size
);
}
//! sets the content to the given TextureData, might resize the texture
//void setImageData( const SharedTextureData &_data );
//! content of the texture is undefined after this, this texture will be bound to the active binding point
//! nothing should be bound to the pixel unpack buffer when calling this
void
resize
(
const
glm
::
uvec2
&
_newSize
);
private:
void
generateMipmaps
(
void
)
{
ACGL
::
Utils
::
error
()
<<
"Rectangle Textures don't support MipMaps!"
<<
std
::
endl
;
}
};
ACGL_SMARTPOINTER_TYPEDEFS
(
TextureRectangle
)
class
Texture2D
:
public
TextureBase
{
public:
Texture2D
()
:
TextureBase
(
GL_TEXTURE_2D
)
{}
//void setImageData( const SharedTextureData &_data, const Image &_target );
};
ACGL_SMARTPOINTER_TYPEDEFS
(
Texture2D
)
class
Texture2DArray
:
public
TextureBase
{
public:
Texture2DArray
()
:
TextureBase
(
GL_TEXTURE_2D_ARRAY
)
{}
};
ACGL_SMARTPOINTER_TYPEDEFS
(
Texture2DArray
)
//
//
// Full compatibility with the old Texture class:
// Full compatibility with the old Texture class:
//
//
...
@@ -184,7 +252,7 @@ class Texture : public TextureBase
...
@@ -184,7 +252,7 @@ class Texture : public TextureBase
// ============================================================================================ CONSTRUCTORS \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
// ========================================================================================================= \/
public:
public:
Texture
(
GLenum
_target
)
:
TextureBase
(
_target
)
{
mFormat
=
GL_RGBA
;
}
Texture
(
GLenum
_target
)
:
TextureBase
(
_target
)
{
mFormat
=
GL_RGBA
;
mType
=
GL_UNSIGNED_BYTE
;
}
// ==================================================================================================== \/
// ==================================================================================================== \/
...
@@ -192,6 +260,7 @@ public:
...
@@ -192,6 +260,7 @@ public:
// ==================================================================================================== \/
// ==================================================================================================== \/
public:
public:
inline
GLenum
getFormat
(
void
)
const
{
return
mFormat
;
}
inline
GLenum
getFormat
(
void
)
const
{
return
mFormat
;
}
inline
GLenum
getType
(
void
)
const
{
return
mType
;
}
// ===================================================================================================== \/
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ============================================================================================ WRAPPERS \/
...
@@ -455,6 +524,7 @@ private:
...
@@ -455,6 +524,7 @@ private:
// =================================================================================================== \/
// =================================================================================================== \/
private:
private:
GLenum
mFormat
;
GLenum
mFormat
;
GLenum
mType
;
};
};
ACGL_SMARTPOINTER_TYPEDEFS
(
Texture
)
ACGL_SMARTPOINTER_TYPEDEFS
(
Texture
)
...
...
src/ACGL/OpenGL/Objects/Texture.cc
View file @
77c39515
...
@@ -148,6 +148,7 @@ GLint TextureBase::getParameterI( GLenum _name ) const
...
@@ -148,6 +148,7 @@ GLint TextureBase::getParameterI( GLenum _name ) const
GLint
param
;
GLint
param
;
glGetTexParameteriv
(
mTarget
,
_name
,
&
param
);
glGetTexParameteriv
(
mTarget
,
_name
,
&
param
);
glBindTexture
(
mTarget
,
prevTexture
);
glBindTexture
(
mTarget
,
prevTexture
);
openGLRareError
();
return
param
;
return
param
;
}
}
...
@@ -157,6 +158,7 @@ GLfloat TextureBase::getParameterF( GLenum _name ) const
...
@@ -157,6 +158,7 @@ GLfloat TextureBase::getParameterF( GLenum _name ) const
GLfloat
param
;
GLfloat
param
;
glGetTexParameterfv
(
mTarget
,
_name
,
&
param
);
glGetTexParameterfv
(
mTarget
,
_name
,
&
param
);
glBindTexture
(
mTarget
,
prevTexture
);
glBindTexture
(
mTarget
,
prevTexture
);
openGLRareError
();
return
param
;
return
param
;
}
}
...
@@ -164,17 +166,17 @@ GLuint TextureBase::bindAndGetOldTexture() const
...
@@ -164,17 +166,17 @@ GLuint TextureBase::bindAndGetOldTexture() const
{
{
GLint
prevTexture
=
0
;
GLint
prevTexture
=
0
;
if
(
mTarget
==
GL_TEXTURE_1D
)
glGetIntegerv
(
GL_TEXTURE_BINDING_1D
,
&
prevTexture
);
if
(
mTarget
==
GL_TEXTURE_1D
)
glGetIntegerv
(
GL_TEXTURE_BINDING_1D
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_3D
)
glGetIntegerv
(
GL_TEXTURE_BINDING_3D
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_3D
)
glGetIntegerv
(
GL_TEXTURE_BINDING_3D
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_1D_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_1D_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_1D_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_1D_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_RECTANGLE
)
glGetIntegerv
(
GL_TEXTURE_BINDING_RECTANGLE
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_RECTANGLE
)
glGetIntegerv
(
GL_TEXTURE_BINDING_RECTANGLE
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D_MULTISAMPLE
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D_MULTISAMPLE
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D_MULTISAMPLE
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D_MULTISAMPLE
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_2D_MULTISAMPLE_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_
BINDING_
CUBE_MAP
)
glGetIntegerv
(
GL_TEXTURE_BINDING_CUBE_MAP
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_CUBE_MAP
)
glGetIntegerv
(
GL_TEXTURE_BINDING_CUBE_MAP
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_
BINDING_
CUBE_MAP_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_CUBE_MAP_ARRAY
)
glGetIntegerv
(
GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_B
INDING_B
UFFER
)
glGetIntegerv
(
GL_TEXTURE_BINDING_BUFFER
,
&
prevTexture
);
else
if
(
mTarget
==
GL_TEXTURE_BUFFER
)
glGetIntegerv
(
GL_TEXTURE_BINDING_BUFFER
,
&
prevTexture
);
else
{
else
{
ACGL
::
Utils
::
error
()
<<
"Unknown texture target, will create sideeffecs as old bound texture can not get restored!"
<<
std
::
endl
;
ACGL
::
Utils
::
error
()
<<
"Unknown texture target, will create sideeffecs as old bound texture can not get restored!"
<<
std
::
endl
;
}
}
...
@@ -184,6 +186,102 @@ GLuint TextureBase::bindAndGetOldTexture() const
...
@@ -184,6 +186,102 @@ GLuint TextureBase::bindAndGetOldTexture() const
return
(
GLuint
)
prevTexture
;
return
(
GLuint
)
prevTexture
;
}
}
GLenum
TextureBase
::
getCompatibleFormat
(
GLenum
_internalFormat
)
{
if
(
_internalFormat
==
GL_DEPTH_COMPONENT
||
_internalFormat
==
GL_DEPTH_COMPONENT16
||
_internalFormat
==
GL_DEPTH_COMPONENT24
||
_internalFormat
==
GL_DEPTH_COMPONENT32F
||
_internalFormat
==
GL_DEPTH24_STENCIL8
)
{
return
GL_DEPTH_COMPONENT
;
}
if
(
_internalFormat
==
GL_R8I
||
_internalFormat
==
GL_R8UI
||
_internalFormat
==
GL_R16I
||
_internalFormat
==
GL_R16UI
||
_internalFormat
==
GL_R32I
||
_internalFormat
==
GL_R32UI
||
_internalFormat
==
GL_RG8I
||
_internalFormat
==
GL_RG8UI
||
_internalFormat
==
GL_RG16I
||
_internalFormat
==
GL_RG16UI
||
_internalFormat
==
GL_RG32I
||
_internalFormat
==
GL_RG32UI
||
_internalFormat
==
GL_RGB8I
||
_internalFormat
==
GL_RGB8UI
||
_internalFormat
==
GL_RGB16I
||
_internalFormat
==
GL_RGB16UI
||
_internalFormat
==
GL_RGB32I
||
_internalFormat
==
GL_RGB32UI
||
_internalFormat
==
GL_RGBA8I
||
_internalFormat
==
GL_RGBA8UI
||
_internalFormat
==
GL_RGBA16I
||
_internalFormat
==
GL_RGBA16UI
||
_internalFormat
==
GL_RGBA32I
||
_internalFormat
==
GL_RGBA32UI
)
{
return
GL_RGBA_INTEGER
;
}
// there are probably some cases missing that don't work with RGBA
return
GL_RGBA
;
}
GLenum
TextureBase
::
getCompatibleType
(
GLenum
_internalFormat
)
{
if
(
_internalFormat
==
GL_R8I
||
_internalFormat
==
GL_R8UI
||
_internalFormat
==
GL_R16I
||
_internalFormat
==
GL_R16UI
||
_internalFormat
==
GL_R32I
||
_internalFormat
==
GL_R32UI
||
_internalFormat
==
GL_RG8I
||
_internalFormat
==
GL_RG8UI
||
_internalFormat
==
GL_RG16I
||
_internalFormat
==
GL_RG16UI
||
_internalFormat
==
GL_RG32I
||
_internalFormat
==
GL_RG32UI
||
_internalFormat
==
GL_RGB8I
||
_internalFormat
==
GL_RGB8UI
||
_internalFormat
==
GL_RGB16I
||
_internalFormat
==
GL_RGB16UI
||
_internalFormat
==
GL_RGB32I
||
_internalFormat
==
GL_RGB32UI
||
_internalFormat
==
GL_RGBA8I
||
_internalFormat
==
GL_RGBA8UI
||
_internalFormat
==
GL_RGBA16I
||
_internalFormat
==
GL_RGBA16UI
||
_internalFormat
==
GL_RGBA32I
||
_internalFormat
==
GL_RGBA32UI
)
{
return
GL_INT
;
}
// not sure if this works for all formats:
return
GL_BYTE
;
}
void
TextureRectangle
::
resize
(
const
glm
::
uvec2
&
_newSize
)
{
if
(
_newSize
.
x
!=
(
unsigned
int
)
mWidth
||
_newSize
.
y
!=
(
unsigned
int
)
mHeight
)
{
mWidth
=
_newSize
.
x
;
mHeight
=
_newSize
.
y
;
openGLCriticalErrorOccured
();
bind
();
glTexImage2D
(
mTarget
,
0
,
// there are no mipmaps for Rect Textures!
mInternalFormat
,
mWidth
,
mHeight
,
0
,
// no border
getCompatibleFormat
(
mInternalFormat
),
// nothing gets uploaded, but this still has to be compatible with the internal format
getCompatibleType
(
mInternalFormat
),
// nothing gets uploaded, but this still has to be compatible with the internal format
NULL
);
openGLCriticalErrorOccured
();
// the guess of compatible formats might be wrong so better test for errors!
}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
//
// old Texture class:
// old Texture class:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment