Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
e542cd55
Commit
e542cd55
authored
Feb 03, 2012
by
Robert Menzel
Browse files
cleanups
parent
59980a01
Changes
10
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Objects/ArrayBuffer.hh
View file @
e542cd55
...
...
@@ -91,12 +91,14 @@ public:
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
//! creates an ArrayBuffer with a new OpenGL Buffer object
ArrayBuffer
()
:
Buffer
(
GL_ARRAY_BUFFER
),
mStride
(
0
),
mAttributes
()
{}
//! creates an ArrayBuffer with a pre-existing OpenGL Buffer
ArrayBuffer
(
SharedBufferObject
_pBuffer
)
:
Buffer
(
_pBuffer
,
GL_ARRAY_BUFFER
),
mStride
(
0
),
...
...
@@ -108,7 +110,7 @@ public:
// ==================================================================================================== \/
public:
//!
often
the number of vertices:
//!
elements is
the number of vertices
(unless this AB should get interpreted in a strange way)
:
inline
GLsizei
getElements
(
void
)
const
{
return
mSize
/
mStride
;
}
//! size in bytes of all attributes that make up one element (vertex):
...
...
@@ -122,64 +124,25 @@ public:
// ==================================================================================================== \/
public:
//! Adds the attribute at the end of the existing attributes, stride gets computed automatically
void
defineAttribute
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLboolean
_normalized
=
GL_FALSE
)
{
GLuint
offset
=
mStride
;
Attribute
attribute
=
{
_name
,
_type
,
_size
,
offset
,
_normalized
};
defineAttribute
(
attribute
);
}
void
defineAttribute
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLboolean
_normalized
=
GL_FALSE
);
//! Adds the attribute at the end of the existing attributes, stride gets computed automatically
//! + extra padding in bytes at the end
void
defineAttributeWithPadding
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLuint
_padding
,
GLboolean
_normalized
=
GL_FALSE
)
{
GLuint
offset
=
mStride
;
Attribute
attribute
=
{
_name
,
_type
,
_size
,
offset
,
_normalized
};
defineAttribute
(
attribute
);
// defineAttribute will shift the mStride to the end of this attribute, so we only have to
// add the explicit padding:
mStride
+=
_padding
;
}
void
defineAttributeWithPadding
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLuint
_padding
,
GLboolean
_normalized
=
GL_FALSE
);
//! Adds an attribute defined by an offset: this way an attribute can get added at arbitrary
//! locations in the stride. If it's added at the end, the stride gets resized. This way attributes can even
//! overlap, hope you know what you're doing...
void
defineAttributeWithOffset
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLuint
_offset
,
GLboolean
_normalized
=
GL_FALSE
)
{
Attribute
attribute
=
{
_name
,
_type
,
_size
,
_offset
,
_normalized
};
defineAttribute
(
attribute
);
}
void
defineAttributeWithOffset
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLuint
_offset
,
GLboolean
_normalized
=
GL_FALSE
);
//! Takes care of a valid stride size and adds the attribute
void
defineAttribute
(
const
Attribute
&
_attribute
)
{
// this way attribute definitions don't have to be in order!
GLsizei
attributeWidth
=
getGLTypeSize
(
_attribute
.
type
)
*
_attribute
.
size
;
// in bytes
mStride
=
std
::
max
(
(
GLsizei
)
_attribute
.
offset
+
attributeWidth
,
mStride
);
mAttributes
.
push_back
(
_attribute
);
}
void
defineAttribute
(
const
Attribute
&
_attribute
);
//! Returns the index of a named attribute
int_t
getAttributeIndexByName
(
const
std
::
string
&
_nameInArray
)
const
;
//! Setting of the stride size explicitly is not needed if the attributes are defined correctly (with padding)
inline
void
setStride
(
GLsizei
_stride
)
{
mStride
=
_stride
;
}
inline
void
setStride
(
GLsizei
_stride
)
{
mStride
=
_stride
;
}
//! removes all attributes
inline
void
removeAttributes
(
void
)
...
...
include/ACGL/OpenGL/Objects/Buffer.hh
View file @
e542cd55
...
...
@@ -113,6 +113,9 @@ public:
//! the GL buffer can get changed at any time
void
setBufferObject
(
SharedBufferObject
_pBuffer
)
{
mBuffer
=
_pBuffer
;
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
private:
inline
GLint
getParameter
(
GLenum
_parameter
)
{
bind
(
mTarget
);
...
...
@@ -130,10 +133,6 @@ private:
}
public:
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
//! not side effect free! will bind this buffer to it's last target!
//! caching of these values on RAM could be a good idea if needed very(!) often (as it's done with the size)!
//inline GLint64 getSize() { return getParameter64( GL_BUFFER_SIZE ); }
...
...
include/ACGL/OpenGL/Objects/ElementArrayBuffer.hh
View file @
e542cd55
...
...
@@ -57,10 +57,7 @@ public:
public:
//! _type has to be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT and indicates the
//! datatype of the indices
inline
void
setType
(
GLenum
_type
)
{
mType
=
_type
;
}
inline
void
setType
(
GLenum
_type
)
{
mType
=
_type
;
}
//! Returns the number of indices:
GLuint
getElements
()
{
...
...
include/ACGL/OpenGL/Objects/FrameBufferObject.hh
View file @
e542cd55
...
...
@@ -30,7 +30,6 @@
#include
<ACGL/OpenGL/Tools.hh>
#include
<ACGL/OpenGL/Objects/RenderBuffer.hh>
#include
<ACGL/OpenGL/Objects/Texture.hh>
//#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include
<ACGL/OpenGL/Objects/LocationMappings.hh>
#include
<vector>
...
...
@@ -116,22 +115,6 @@ public:
openGLRareError
();
// glBindFramebuffer can only fail if the object name is no valid FBO which shouldn't happen using this framework
}
// TODO: deprecate?
/*
inline void bindAsRenderTarget(GLenum _type = GL_FRAMEBUFFER) const
{
glBindFramebuffer(_type, mObjectName);
glDrawBuffers(mDrawBuffers, msBuffers);
openGLRareError();
}
inline void bindAsRenderTarget(GLint _x, GLint _y, GLsizei _w, GLsizei _h, GLenum _type = GL_FRAMEBUFFER) const
{
glBindFramebuffer(_type, mObjectName);
glDrawBuffers(mDrawBuffers, msBuffers);
openGLRareError();
}*/
//! let OpenGL validate the completeness
bool
isFrameBufferObjectComplete
()
const
;
...
...
include/ACGL/OpenGL/Objects/LocationMappings.hh
View file @
e542cd55
...
...
@@ -13,6 +13,8 @@
* or
* fragment outputs to fragdata locations
*
* (as long as there are no name clashes one map can be used for both)
*
* A mapping like this can be used to init all mappings of multiple ShaderProgram
* in the same way to they can be used with the same VAOs or FBOs, similar, these
* mapping objects can be used to configute VAOs and FBOs!
...
...
@@ -44,29 +46,15 @@ public:
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
LocationMappings
()
:
mMappings
()
{
}
~
LocationMappings
()
{
}
LocationMappings
()
{}
~
LocationMappings
()
{}
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
//! Returns the stored location for a given name or -1 if the name could not get found (similar to how GL behaves)
GLint
getLocation
(
const
std
::
string
&
_name
)
const
{
if
(
exists
(
_name
))
{
return
(
GLint
)
mMappings
.
at
(
_name
);
}
else
{
return
-
1
;
}
}
GLint
getLocation
(
const
std
::
string
&
_name
)
const
;
//! Returns the raw location map:
const
LocationMap
&
getLocations
()
const
{
return
mMappings
;
}
...
...
@@ -77,22 +65,14 @@ public:
public:
//! Adds one location:
inline
void
setLocation
(
const
std
::
string
&
_name
,
GLuint
_location
)
{
if
(
exists
(
_name
)
&&
(
mMappings
[
_name
]
!=
_location
))
{
ACGL
::
Utils
::
warning
()
<<
"LocationMappings: Overwriting location mapping for "
<<
_name
;
ACGL
::
Utils
::
warning
()
<<
" (previous value: "
<<
mMappings
[
_name
]
<<
", new value: "
<<
_location
<<
")"
<<
std
::
endl
;
}
mMappings
[
_name
]
=
_location
;
}
void
setLocation
(
const
std
::
string
&
_name
,
GLuint
_location
);
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
//! Tells whether a mapping for a given name exists
inline
bool
exists
(
const
std
::
string
&
_name
)
const
{
return
(
mMappings
.
find
(
_name
)
!=
mMappings
.
end
()
);
}
inline
bool
exists
(
const
std
::
string
&
_name
)
const
{
return
(
getLocation
(
_name
)
!=
-
1
);
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
...
...
include/ACGL/OpenGL/Objects/RenderBuffer.hh
View file @
e542cd55
...
...
@@ -6,6 +6,10 @@
#ifndef ACGL_OPENGL_OBJECTS_RENDERBUFFER_HH
#define ACGL_OPENGL_OBJECTS_RENDERBUFFER_HH
/*
* An OpenGL RenderBuffer that can be used with FBOs.
*/
#include
<ACGL/ACGL.hh>
#include
<ACGL/Base/Macros.hh>
...
...
@@ -29,8 +33,7 @@ public:
:
mObjectName
(
0
),
mInternalFormat
(
_internalFormat
),
mWidth
(
0
),
mHeight
(
0
),
mSamples
(
0
)
mHeight
(
0
)
{
glGenRenderbuffers
(
1
,
&
mObjectName
);
if
(
openGLCriticalErrorOccured
()
)
{
...
...
@@ -86,12 +89,12 @@ public:
{
mWidth
=
_width
;
mHeight
=
_height
;
mSamples
=
_samples
;
// the sample count will not get saved as the real samples returned by GL might differ this number anyway!
glBindRenderbuffer
(
GL_RENDERBUFFER
,
mObjectName
);
#if (ACGL_OPENGL_VERSION >= 30)
glRenderbufferStorageMultisample
(
GL_RENDERBUFFER
,
mS
amples
,
mInternalFormat
,
mWidth
,
mHeight
);
#else
glRenderbufferStorageMultisample
(
GL_RENDERBUFFER
,
_s
amples
,
mInternalFormat
,
mWidth
,
mHeight
);
#else
// OpenGL ES, as Desktop GL didn't have renderbuffers pre 3.0 anyway
glRenderbufferStorage
(
GL_RENDERBUFFER
,
mInternalFormat
,
mWidth
,
mHeight
);
#endif // OpenGL >= 3.0
...
...
@@ -105,7 +108,6 @@ protected:
GLenum
mInternalFormat
;
GLsizei
mWidth
;
GLsizei
mHeight
;
GLsizei
mSamples
;
};
ACGL_SHARED_TYPEDEF
(
RenderBuffer
)
...
...
include/ACGL/OpenGL/Objects/ShaderProgram.hh
View file @
e542cd55
...
...
@@ -54,12 +54,6 @@
namespace
ACGL
{
namespace
OpenGL
{
//class VertexArrayObject;
//ACGL_SHARED_TYPEDEF(VertexArrayObject)
//class FrameBufferObject;
//ACGL_SHARED_TYPEDEF(FrameBufferObject)
class
ShaderProgram
{
ACGL_NOT_COPYABLE
(
ShaderProgram
)
...
...
@@ -139,12 +133,6 @@ public:
SharedLocationMappings
getFragmentDataLocations
();
#endif // OpenGL >= 3.0
// Matches the attribute locations of this ShaderProgram to the names of the ArrayBuffer attributes currently attached to _vao
//void setAttributeLocationsByVAO( ConstSharedVertexArrayObject _vao );
// Matches the fragment data locations of this ShaderProgram to the names of the color attachments of _fbo
//void setFragmentDataLocationsByFBO( ConstSharedFrameBufferObject _fbo );
// ===================================================================================================== \/
// ============================================================================================ UNIFORMS \/
// ===================================================================================================== \/
...
...
src/ACGL/OpenGL/Objects/ArrayBuffer.cc
View file @
e542cd55
...
...
@@ -8,6 +8,51 @@
using
namespace
ACGL
;
using
namespace
ACGL
::
OpenGL
;
void
ArrayBuffer
::
defineAttribute
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLboolean
_normalized
)
{
GLuint
offset
=
mStride
;
Attribute
attribute
=
{
_name
,
_type
,
_size
,
offset
,
_normalized
};
defineAttribute
(
attribute
);
}
void
ArrayBuffer
::
defineAttributeWithPadding
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLuint
_padding
,
GLboolean
_normalized
)
{
GLuint
offset
=
mStride
;
Attribute
attribute
=
{
_name
,
_type
,
_size
,
offset
,
_normalized
};
defineAttribute
(
attribute
);
// defineAttribute will shift the mStride to the end of this attribute, so we only have to
// add the explicit padding:
mStride
+=
_padding
;
}
void
ArrayBuffer
::
defineAttributeWithOffset
(
const
std
::
string
&
_name
,
GLenum
_type
,
GLint
_size
,
GLuint
_offset
,
GLboolean
_normalized
)
{
Attribute
attribute
=
{
_name
,
_type
,
_size
,
_offset
,
_normalized
};
defineAttribute
(
attribute
);
}
void
ArrayBuffer
::
defineAttribute
(
const
Attribute
&
_attribute
)
{
// this way attribute definitions don't have to be in order!
GLsizei
attributeWidth
=
getGLTypeSize
(
_attribute
.
type
)
*
_attribute
.
size
;
// in bytes
mStride
=
std
::
max
(
(
GLsizei
)
_attribute
.
offset
+
attributeWidth
,
mStride
);
mAttributes
.
push_back
(
_attribute
);
}
int_t
ArrayBuffer
::
getAttributeIndexByName
(
const
std
::
string
&
_nameInArray
)
const
{
for
(
AttributeVec
::
size_type
i
=
0
;
i
<
mAttributes
.
size
();
++
i
)
...
...
src/ACGL/OpenGL/Objects/FrameBufferObject.cc
View file @
e542cd55
...
...
@@ -108,7 +108,7 @@ bool FrameBufferObject::attachColorAttachment( const Attachment &_attachment )
}
else
{
// it's a texture
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
GL_COLOR_ATTACHMENT0
+
realLocation
,
_attachment
.
texture
->
getTarget
(),
_attachment
.
texture
->
getObjectName
(),
0
);
Utils
::
debug
()
<<
"glFramebufferTexture2D( "
<<
_attachment
.
name
<<
" to "
<<
realLocation
<<
" )"
<<
std
::
endl
;
//
Utils::debug() << "glFramebufferTexture2D( " << _attachment.name << " to " << realLocation <<" )" << std::endl;
}
if
(
openGLCommonErrorOccured
())
{
...
...
@@ -126,12 +126,12 @@ void FrameBufferObject::remapAttachments()
glGetIntegerv
(
GL_MAX_DRAW_BUFFERS
,
&
maxColorBuffers
);
GLenum
*
bufferMappings
=
new
GLenum
[
maxColorBuffers
];
unsigned
int
attachments
=
std
::
min
(
maxColorBuffers
,
(
int
)
mColorAttachments
.
size
()
);
int
attachments
=
std
::
min
(
maxColorBuffers
,
(
int
)
mColorAttachments
.
size
()
);
for
(
unsigned
int
i
=
0
;
i
<
maxColorBuffers
;
++
i
)
{
for
(
int
i
=
0
;
i
<
maxColorBuffers
;
++
i
)
{
bufferMappings
[
i
]
=
GL_NONE
;
}
for
(
unsigned
int
i
=
0
;
i
<
attachments
;
++
i
)
{
for
(
int
i
=
0
;
i
<
attachments
;
++
i
)
{
if
(
bufferMappings
[
mColorAttachments
[
i
].
location
]
!=
GL_NONE
)
{
Utils
::
warning
()
<<
"FBO: Attachment mapping collision: Location "
<<
mColorAttachments
[
i
].
location
;
Utils
::
warning
()
<<
" maps to both attachments "
<<
mColorAttachments
[
i
].
name
;
...
...
src/ACGL/OpenGL/Objects/ShaderProgram.cc
View file @
e542cd55
...
...
@@ -100,7 +100,7 @@ void ShaderProgram::setFragmentDataLocations(ConstSharedLocationMappings _locati
&&
((
GLuint
)
fragmentDataLocation
)
!=
(
*
it
).
second
)
// fragment data location with that name not already bound correctly?
{
bindFragmentDataLocation
((
*
it
).
first
,
(
*
it
).
second
);
ACGL
::
Utils
::
debug
()
<<
"bindFragmentDataLocation("
<<
(
*
it
).
first
<<
", "
<<
(
*
it
).
second
<<
");"
<<
std
::
endl
;
//
ACGL::Utils::debug() << "bindFragmentDataLocation("<<(*it).first<<", "<<(*it).second<<");"<<std::endl;
needsRelink
=
true
;
}
}
...
...
@@ -137,8 +137,6 @@ SharedLocationMappings ShaderProgram::getAttributeLocations()
GLint
attribLocation
=
glGetAttribLocation
(
mObjectName
,
name
);
//ACGL::Utils::debug() << "found attrib " << name << " at " << attribLocation << std::endl;
locationMap
->
setLocation
(
std
::
string
(
name
),
(
GLuint
)
attribLocation
);
}
...
...
@@ -155,68 +153,3 @@ SharedLocationMappings ShaderProgram::getFragmentDataLocations()
return
locationMap
;
}
/*
void ShaderProgram::setAttributeLocationsByVAO(ConstSharedVertexArrayObject _vao)
{
// TODO: deprecate
bool needsRelink = false;
// search through all attributes of _vao
VertexArrayObject::AttributeVec vaoAttributes = _vao->getAttributes();
for(VertexArrayObject::AttributeVec::size_type i = 0; i < vaoAttributes.size(); ++i)
{
if(vaoAttributes[i].location == -1)
continue;
// find the name of the current attribute in its ArrayBuffer
std::string arrayBufferAttributeName = vaoAttributes[i].arrayBuffer->getAttributes()[vaoAttributes[i].attributeID].name;
// find out whether an attribute with a matching name exists in this ShaderProgram
GLint attribLocation = getAttributeLocation(arrayBufferAttributeName);
if(attribLocation != -1 // attribute with that name exists?
&& attribLocation != vaoAttributes[i].location) // attribute with that name not already bound correctly?
{
bindAttributeLocation(arrayBufferAttributeName, vaoAttributes[i].location);
needsRelink = true;
}
}
// re-link the program only if necessary
if(needsRelink)
{
link();
openGLRareError();
}
}*/
/*
void ShaderProgram::setFragmentDataLocationsByFBO(ConstSharedFrameBufferObject _fbo)
{
// TODO: deprecate
bool needsRelink = false;
// search through all color attachments of _fbo
FrameBufferObject::AttachmentVec fboAttachments = _fbo->getColorAttachments();
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < fboAttachments.size(); ++i)
{
// find out whether a fragment data location with a matching name exists in this shader
GLint fragmentDataLocation = getFragmentDataLocation(fboAttachments[i].name);
if ( fragmentDataLocation != -1 // fragment data location with that name exists?
&& fragmentDataLocation != (GLint) i) // fragment data location with that name not already bound correctly?
{
bindFragmentDataLocation(fboAttachments[i].name, i);
needsRelink = true;
}
}
// re-link the program only if necessary
if(needsRelink)
{
link();
openGLRareError();
}
}*/
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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