Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
acgl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ACGL
acgl
Commits
67c4cd79
Commit
67c4cd79
authored
Jan 30, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added TextureBuffer
parent
ff726547
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
0 deletions
+113
-0
include/ACGL/OpenGL/Objects/Texture.hh
include/ACGL/OpenGL/Objects/Texture.hh
+113
-0
No files found.
include/ACGL/OpenGL/Objects/Texture.hh
View file @
67c4cd79
...
...
@@ -22,9 +22,122 @@
#include <vector>
#include <ACGL/OpenGL/Objects/Buffer.hh>
namespace
ACGL
{
namespace
OpenGL
{
/*
class TextureNG
{
ACGL_NOT_COPYABLE(TextureNG)
public:
TextureNG(GLenum _target) : mObjectName(0),
mTarget(_target) {
glGenTextures(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
}
}
virtual ~TextureNG()
{
// object name 0 will get ignored by OpenGL
glDeleteTextures(1, &mObjectName);
}
inline GLuint getObjectName () const { return mObjectName; }
inline GLenum getTarget () const { return mTarget; }
//! Activate texture unit and bind this texture.
void bind(GLuint _textureUnit = 0) const
{
glActiveTexture(GL_TEXTURE0 + _textureUnit);
glBindTexture(mTarget, mObjectName);
openGLRareError();
}
private:
GLuint mObjectName;
GLenum mTarget;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureNG)
*/
#if (ACGL_OPENGL_VERSION >= 30)
/*
* TextureBuffers are 1D textures which store there data in a Buffer.
* They are useful to access large chunks of data from within a shader.
* Technically they are accessed as textures (uniform samplerBuffer) via texelFetch
* with a 1D coordinate (int coordinate, so no filtering). This means they benefit from
* texture caches.
* Use these if the data doesn't fit into a UniformBufferObject.
*
* Data gets stored in the Buffer, no glTexImage calles are allowed!
*/
class
TextureBuffer
:
public
Buffer
{
public:
// _reservedMemory is counted in bytes
TextureBuffer
(
GLenum
_dataType
,
size_t
_reservedMemory
=
1
)
:
Buffer
(
GL_TEXTURE_BUFFER
)
{
glGenTextures
(
1
,
&
mTextureObjectName
);
if
(
openGLCriticalErrorOccured
()
)
{
ACGL
::
Utils
::
error
()
<<
"could not generate texture object for texture buffer!"
<<
std
::
endl
;
}
mDataType
=
_dataType
;
Buffer
::
setData
(
_reservedMemory
);
attachBufferToTexture
();
}
//! the GL buffer can get changed at any time
void
setBufferObject
(
SharedBufferObject
_pBuffer
)
{
Buffer
::
setBufferObject
(
_pBuffer
);
if
(
_pBuffer
==
NULL
)
{
// detach all buffers:
glTexBuffer
(
GL_TEXTURE_BUFFER
,
mDataType
,
0
);
}
else
{
attachBufferToTexture
();
}
}
~
TextureBuffer
()
{
setBufferObject
(
SharedBufferObject
()
);
// detach the Buffer
glDeleteTextures
(
1
,
&
mTextureObjectName
);
}
void
bindTexture
(
GLuint
_textureUnit
=
0
)
const
{
glActiveTexture
(
GL_TEXTURE0
+
_textureUnit
);
glBindTexture
(
GL_TEXTURE_BUFFER
,
mTextureObjectName
);
openGLRareError
();
}
void
bindBuffer
()
const
{
Buffer
::
bind
();
}
inline
GLuint
getTextureObjectName
()
const
{
return
mTextureObjectName
;
}
inline
GLuint
getBufferObjectName
()
const
{
return
Buffer
::
getObjectName
();
}
private:
//! private to prevent it from being called -> it's not clear whether the texture or the buffer should get bound, call
//! bindBuffer() or bindTexture() directly!
void
bind
()
{}
void
attachBufferToTexture
()
{
assert
(
Buffer
::
getSize
()
>
0
&&
"glTexBuffer will fail if the buffer is empty"
);
TextureNG
::
bind
();
openGLCriticalErrorOccured
();
glTexBuffer
(
GL_TEXTURE_BUFFER
,
mDataType
,
Buffer
::
getObjectName
()
);
openGLCriticalErrorOccured
();
}
GLenum
mDataType
;
GLuint
mTextureObjectName
;
};
ACGL_SMARTPOINTER_TYPEDEFS
(
TextureBuffer
)
#endif // OpenGL 3.0+
class
Texture
{
ACGL_NOT_COPYABLE
(
Texture
)
...
...
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