The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 6b394e72 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

work on Issue #88: cleaned up VertexArrayObject interface. It's now simpler...

work on Issue #88: cleaned up VertexArrayObject interface. It's now simpler and more straight-forward.
parent b2374103
......@@ -135,7 +135,6 @@ namespace campvis {
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "core/glsl/passthrough.frag", "", false);
if (_shader != 0) {
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
_shader->setAttributeLocation(2, "in_Color");
}
else {
......@@ -152,9 +151,6 @@ namespace campvis {
_geometries.clear();
if (_fbo != 0) {
_fbo->activate();
_fbo->detachAll();
_fbo->deactivate();
delete _fbo;
_fbo = 0;
}
......@@ -260,6 +256,7 @@ namespace campvis {
// deactivate Shader and FBO
_shader->deactivate();
_fbo->detachTexture(GL_COLOR_ATTACHMENT0);
_fbo->deactivate();
LGL_ERROR;
......
......@@ -84,7 +84,6 @@ namespace campvis {
}
void TFGeometry1D::render() const {
// TODO: get rid of intermediade mode?
if (_keyPoints.size() < 2)
return;
......@@ -100,7 +99,7 @@ namespace campvis {
colors.push_back(tgt::vec4(a->_color) / 255.f);
}
FaceGeometry fg(vertices, vertices, colors);
FaceGeometry fg(vertices, std::vector<tgt::vec3>(), colors);
fg.render(GL_TRIANGLE_STRIP);
}
TFGeometry1D* TFGeometry1D::createQuad(const tgt::vec2& interval, const tgt::col4& leftColor, const tgt::vec4& rightColor) {
......
......@@ -39,6 +39,7 @@ namespace tgt {
}
namespace campvis {
class FaceGeometry;
/**
* Defines a single shape for the GeometryTransferFunction class.
......@@ -110,6 +111,8 @@ namespace campvis {
protected:
std::vector<KeyPoint> _keyPoints; ///< vector of KeyPoints, KeyPoints are sorted by x-coordinate of the position
FaceGeometry* _tfRenderFace; ///< FaceGeometry used to render TF into the TF texture
FaceGeometry* _tfEditorFace; ///< FaceGeometry used to render TF into editor window
};
// ================================================================================================
......
......@@ -112,13 +112,13 @@ namespace campvis {
tgt::VertexArrayObject vao;
if (_verticesBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::VerticesAttribute, _verticesBuffer);
vao.setVertexAttributePointer(0, _verticesBuffer);
if (_texCoordsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::TextureCoordinatesAttribute, _texCoordsBuffer);
vao.setVertexAttributePointer(1, _texCoordsBuffer);
if (_colorsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::ColorsAttribute, _colorsBuffer);
vao.setVertexAttributePointer(2, _colorsBuffer);
if (_normalsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::NormalsAttribute, _normalsBuffer);
vao.setVertexAttributePointer(3, _normalsBuffer);
LGL_ERROR;
glDrawArrays(mode, 0, static_cast<GLsizei>(_vertices.size()));
......
......@@ -102,13 +102,13 @@ namespace campvis {
tgt::VertexArrayObject vao;
if (_verticesBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::VerticesAttribute, _verticesBuffer);
vao.setVertexAttributePointer(0, _verticesBuffer);
if (_texCoordsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::TextureCoordinatesAttribute, _texCoordsBuffer);
vao.setVertexAttributePointer(1, _texCoordsBuffer);
if (_colorsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::ColorsAttribute, _colorsBuffer);
vao.setVertexAttributePointer(2, _colorsBuffer);
if (_normalsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::NormalsAttribute, _normalsBuffer);
vao.setVertexAttributePointer(3, _normalsBuffer);
vao.bindIndexBuffer(_indicesBuffer);
glDrawElements(mode, static_cast<GLsizei>(_indices.size()), GL_UNSIGNED_SHORT, 0);
......
......@@ -91,13 +91,13 @@ namespace campvis {
tgt::VertexArrayObject vao;
if (_verticesBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::VerticesAttribute, _verticesBuffer);
vao.setVertexAttributePointer(0, _verticesBuffer);
if (_texCoordsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::TextureCoordinatesAttribute, _texCoordsBuffer);
vao.setVertexAttributePointer(1, _texCoordsBuffer);
if (_colorsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::ColorsAttribute, _colorsBuffer);
vao.setVertexAttributePointer(2, _colorsBuffer);
if (_normalsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::NormalsAttribute, _normalsBuffer);
vao.setVertexAttributePointer(3, _normalsBuffer);
LGL_ERROR;
GLint startIndex = 0;
......
......@@ -19,8 +19,6 @@ namespace tgt {
}
BufferObject::~BufferObject() {
tgtAssert(_assignedAttributes.empty(), "Destructing a BufferObject, that is still bound to a VertexAttribute.");
if (_id != 0) {
GLGC.addGarbageBufferObject(_id);
}
......@@ -42,14 +40,6 @@ namespace tgt {
glBufferSubData(_targetType, offset, numBytes, data);
}
void BufferObject::bindToVertexAttribute(const VertexAttribute* va) {
_assignedAttributes.insert(va);
}
void BufferObject::unbindFromVertexAttribute(const VertexAttribute* va) {
_assignedAttributes.erase(va);
}
BufferObject::BaseType BufferObject::getBaseType() const {
return _baseType;
}
......
......@@ -10,8 +10,6 @@ namespace tgt {
class VertexAttribute;
class BufferObject {
friend class VertexAttribute;
public:
enum TargetType {
ARRAY_BUFFER = GL_ARRAY_BUFFER,
......@@ -112,18 +110,6 @@ namespace tgt {
protected:
/**
* To be called from VertexAttribute's constructor, to keep track of the VBO-VA bindings.
* \param va The VertexAttribute this BufferObject was bound to.
*/
void bindToVertexAttribute(const VertexAttribute* va);
/**
* To be called from VertexAttribute destructor, to keep track of the VBO-VA binding.
* \param va The VertexAttribute this BufferObject is no longer bound to.
*/
void unbindFromVertexAttribute(const VertexAttribute* va);
GLuint _id; ///< OpenGL ID of this buffer
TargetType _targetType; ///< Target type of buffer object
......@@ -133,8 +119,6 @@ namespace tgt {
size_t _size; ///< Buffer size in bytes
size_t _numElements; ///< Number of elements in this buffer
std::set<const VertexAttribute*> _assignedAttributes; ///< Set of all VertexAttributes this buffer is assigned to (used for debugging purposes).
};
}
......
......@@ -6,36 +6,10 @@
namespace tgt {
const std::string VertexAttribute::loggerCat_ = "tgt.VertexAttribute";
VertexAttribute::VertexAttribute(GLuint index, BufferObject* bufferObject, GLsizei stride, size_t offset)
: _index(index)
, _stride(stride)
, _offset(offset)
, _bufferObject(bufferObject)
{
tgtAssert(_bufferObject != 0, "BufferObject must not be 0.");
_bufferObject->bindToVertexAttribute(this);
// Todo: implement normalized flag if needed
_bufferObject->bind();
glVertexAttribPointer(_index, static_cast<GLint>(_bufferObject->getElementSize()), _bufferObject->getBaseType(), false, _stride, reinterpret_cast<void*>(_offset));
}
VertexAttribute::~VertexAttribute() {
_bufferObject->unbindFromVertexAttribute(this);
}
// ================================================================================================
size_t VertexArrayObject::_currentlyBoundVertexArray = 0;
bool VertexArrayObject::_initialized = true;
const std::string VertexArrayObject::loggerCat_ = "tgt.VertexArrayObject";
VertexArrayObject::VertexArrayObject(bool autoBind) throw (tgt::Exception)
: _id(0)
, _enabledAttributes(16, false)
{
glGenVertexArrays(1, &_id);
if (_id == 0) {
......@@ -51,23 +25,11 @@ namespace tgt {
}
void VertexArrayObject::bind() {
if (!_initialized)
initStaticMembers();
//if (_currentlyBoundVertexArray != _id) {
glBindVertexArray(_id);
// _currentlyBoundVertexArray = _id;
// }
glBindVertexArray(_id);
}
void VertexArrayObject::unbind() {
if (!_initialized)
initStaticMembers();
// if (_currentlyBoundVertexArray != 0) {
glBindVertexArray(0);
// _currentlyBoundVertexArray = 0;
// }
glBindVertexArray(0);
}
void VertexArrayObject::bindIndexBuffer(BufferObject* bufferObject) {
......@@ -77,88 +39,45 @@ namespace tgt {
bufferObject->bind();
}
size_t VertexArrayObject::addVertexAttribute(AttributeType attributeType, BufferObject* bufferObject, GLsizei stride /*= 0*/, size_t offset /*= 0*/, bool enableNow /*= true*/) {
if (_attributes.size() > 16) {
// TODO: The better way would be to check glGet(GL_MAX_VERTEX_ATTRIBS), but the standard says 16 is the minimum
// number to be supported and that should be enough and I currently feel lazy. If you're reading this,
// feel free to improve this check...
LERROR("Could not add VertexAttribute: Tried to add more Vertex Attributes than supported.");
return 0;
}
tgtAssert(
attributeType != UnspecifiedAttribute || _attributeTypeMap.find(attributeType) != _attributeTypeMap.end(),
"Tried to add two VertexAttributes with the same type. This is currently not supported.");
void VertexArrayObject::setVertexAttributePointer(GLuint location, BufferObject* bufferObject, GLsizei stride /*= 0*/, size_t offset /*= 0*/, bool enableNow /*= true*/) {
tgtAssert(bufferObject != 0, "Pointer to buffer object must not be 0.");
tgtAssert(bufferObject->getTargetType() == BufferObject::ARRAY_BUFFER, "Buffer must be bound to the ARRAY_BUFFER target!");
// bind and create VertexAttribute
// Todo: implement normalized flag if needed
bind();
size_t index = _attributes.size();
_attributes.push_back(VertexAttribute(static_cast<GLuint>(index), bufferObject, stride, offset));
// add to attribute-type map
if (attributeType != UnspecifiedAttribute)
_attributeTypeMap.insert(std::make_pair(attributeType, index));
bufferObject->bind();
glVertexAttribPointer(location, static_cast<GLint>(bufferObject->getElementSize()), bufferObject->getBaseType(), false, stride, reinterpret_cast<void*>(offset));
_locationMap.insert(std::make_pair(bufferObject, location));
// enable if wanted
if (enableNow)
enableVertexAttribute(index);
return index;
}
void VertexArrayObject::updateVertexAttribute(size_t index, BufferObject* bufferObject, GLsizei stride /*= 0*/, size_t offset /*= 0*/) {
tgtAssert(index < _attributes.size(), "Index out of bounds.");
bind();
_attributes[index] = VertexAttribute(static_cast<GLuint>(index), bufferObject, stride, offset);
enableVertexAttribute(location);
}
void VertexArrayObject::enableVertexAttribute(size_t index) {
tgtAssert(index < _enabledAttributes.size(), "Index out of bounds.");
void VertexArrayObject::enableVertexAttribute(GLuint location) {
bind();
glEnableVertexAttribArray(static_cast<GLuint>(index));
_enabledAttributes[index] = true;
glEnableVertexAttribArray(location);
}
void VertexArrayObject::enableAllVertexAttributes() {
for (size_t i = 0; i < _attributes.size(); ++i)
enableVertexAttribute(i);
void VertexArrayObject::enableVertexAttribute(BufferObject* bufferObject) {
std::map<BufferObject*, GLuint>::const_iterator it = _locationMap.find(bufferObject);
if (it != _locationMap.end())
enableVertexAttribute(it->second);
else
tgtAssert(false, "Could not find Vertex Attribute location for this BufferObject. You have to add it first using setVertexAttributePointer()!");
}
void VertexArrayObject::disableVertexAttribute(size_t index) {
tgtAssert(index < _enabledAttributes.size(), "Index out of bounds.");
void VertexArrayObject::disableVertexAttribute(GLuint location) {
bind();
glDisableVertexAttribArray(static_cast<GLuint>(index));
_enabledAttributes[index] = false;
glDisableVertexAttribArray(location);
}
void VertexArrayObject::disableAllVertexAttributes() {
for (size_t i = 0; i < _attributes.size(); ++i)
disableVertexAttribute(i);
void VertexArrayObject::disableVertexAttribute(BufferObject* bufferObject) {
std::map<BufferObject*, GLuint>::const_iterator it = _locationMap.find(bufferObject);
if (it != _locationMap.end())
disableVertexAttribute(it->second);
else
tgtAssert(false, "Could not find Vertex Attribute location for this BufferObject. You have to add it first using setVertexAttributePointer()!");
}
void VertexArrayObject::initStaticMembers() {
// TODO: The better way would be to us glGet(GL_MAX_VERTEX_ATTRIBS) as dimension, but the standard says 16
// is the minimum number to be supported and that should be enough and I currently feel lazy. If
// you're reading this, feel free to improve this allocation...
_currentlyBoundVertexArray = 0;
_initialized = true;
}
size_t VertexArrayObject::getVertexAttributeIndexByType(AttributeType type) const {
tgtAssert(type != UnspecifiedAttribute, "Type most not be UnspecifiedAttribute, those attributes are not tracked.");
std::map<AttributeType, size_t>::const_iterator it = _attributeTypeMap.find(type);
if (it == _attributeTypeMap.end()) {
tgtAssert(false, "Could not find a VertexAttribute with the given type. Returning 0 as default value.");
LERROR("Could not find a VertexAttribute with the given type. Returning 0 as default value.");
return 0;
}
return it->second;
}
}
\ No newline at end of file
......@@ -13,66 +13,15 @@ namespace tgt {
class Shader;
class VertexArrayObject;
/**
* Class encapsulating an OpenGL Vertex Attribute state.
* \see http://www.opengl.org/wiki/Vertex_Array_Object
*/
class VertexAttribute {
friend class VertexArrayObject;
public:
/**
* Destructor
*/
~VertexAttribute();
protected:
/**
* Creates an OpenGL Vertex Attribute for the data in \a BufferObject and binds it to the uniform
* named \a uniformName in the given shader.
*
* \note VertexAttributes shall only be created by VertexArrayObject's member functions, hence the
* constructor is protected.
*
* \param index Index of the generic vertex attribute to be modified.
* \param bufferObject BufferObject to bind
*/
VertexAttribute(GLuint index, BufferObject* bufferObject, GLsizei stride, size_t offset);
GLuint _index; ///< Index of the generic vertex attribute to be modified.
GLsizei _stride; ///< Specifies the byte offset between consecutive generic vertex attributes.
size_t _offset; ///< Offset in bytes to the first element in the buffer.
BufferObject* _bufferObject; ///< BufferObject that is bound to this VertexAttribute.
static const std::string loggerCat_;
};
// ================================================================================================
/**
* Wrapper class for OpenGL Vertex Array Objects.
*
* \see http://www.opengl.org/wiki/Vertex_Array_Object
* \note Because all member methods require a valid locked OpenGL context, we have
* implicit thread-safety.
*/
class VertexArrayObject {
public:
/**
* Enumeration of different VertexAttribute types.
* Every added VertexAttribute may have the UnspecifiedAttribute, then its index cannot be
* re-acquired by getVertexAttributeIndexByType(). In contrast, each other attribute types
* can only be assigned to one single VertexAttribute which then can be re-acquired by
* getVertexAttributeIndexByType().
*/
enum AttributeType {
UnspecifiedAttribute,
VerticesAttribute,
NormalsAttribute,
TextureCoordinatesAttribute,
ColorsAttribute
};
VertexArrayObject(bool autoBind = true) throw (tgt::Exception);
/**
......@@ -97,73 +46,47 @@ namespace tgt {
void bindIndexBuffer(BufferObject* bufferObject);
/**
* Add a VertexAttribute to this VertexArrayObject.
* Add a VertexAttribute for \a bufferObject to this VertexArrayObject.
* A VertexAttribute refers to a BufferObject and defines where to find the (geometry, normal, ...) data
* in it.
* \param attributeType
* \param bufferObject
* \param stride
* \param offset
* \return
*/
size_t addVertexAttribute(AttributeType attributeType, BufferObject* bufferObject, GLsizei stride = 0, size_t offset = 0, bool enable = true);
/**
*
* \param index
* \param bufferObject
* \param stride
* \param offset
* \param location Location where this VertexAttribute is bound to the vertex shader.
* \param bufferObject BufferObject to bind
* \param stride Stride
* \param offset Offset
*/
void updateVertexAttribute(size_t index, BufferObject* bufferObject, GLsizei stride = 0, size_t offset = 0);
void setVertexAttributePointer(GLuint location, BufferObject* bufferObject, GLsizei stride = 0, size_t offset = 0, bool enable = true);
/**
* Enables the VertexAttribute with the given index in the OpenGL client state.
* \param index Index of the VertexAttribute to enable.
* Enables the VertexAttribute with the given location in the OpenGL client state.
* \param location Index of the VertexAttribute to enable.
*/
void enableVertexAttribute(size_t index);
void enableVertexAttribute(GLuint location);
/**
* Enables all VertexAttributes of this VAO.
* Enables the VertexAttribute assigned to the given BufferObject.
* \note The BufferObject has to be added to this VAO first using setVertexAttributePointer().
* \param bufferObject BufferObject whose VertexAttribute shall be enabled
*/
void enableAllVertexAttributes();
void enableVertexAttribute(BufferObject* bufferObject);
/**
* Disables the VertexAttribute with the given index in the OpenGL client state.
* \param index Index of the VertexAttribute to disable.
* \param location Index of the VertexAttribute to disable.
*/
void disableVertexAttribute(size_t index);
void disableVertexAttribute(GLuint location);
/**
* Disables all VertexAttributes of this VAO.
* Disables the VertexAttribute assigned to the given BufferObject.
* \note The BufferObject has to be added to this VAO first using setVertexAttributePointer().
* \param bufferObject BufferObject whose VertexAttribute shall be disabled
*/
void disableAllVertexAttributes();
/**
* Returns the index of the VertexAttribute which was previously created with the given type.
* \note A VertexAttribute of type \a type must have been created beforehand. Otherwise
* this method will raise an error and just return 0 (which is also a perfectly
* valid index).
* \param type Type of the VertexAttribute to search for. Must not be UnspecifiedAttribute, must have been created beforehand!
* \return The index of the VertexAttribute, which was created with the given type. If no such
* VA was created, this method raises an error and returns 0 as default value (which is
* also a perfect valid return value!).
*/
size_t getVertexAttributeIndexByType(AttributeType type) const;
void disableVertexAttribute(BufferObject* bufferObject);
protected:
/**
* Initializes all static members.
*/
static void initStaticMembers();
GLuint _id; ///< Id of the internal OpenGL handle to the VAO.
std::vector<VertexAttribute> _attributes; ///< List of all VertexAttributes of this VAO.
std::vector<bool> _enabledAttributes; ///< List of the enabled VertexAttributes.
std::map<AttributeType, size_t> _attributeTypeMap; ///< Map of the AttributeTypes to their indices in the VertexAttributes list.
GLuint _id; ///< Id of the internal OpenGL handle to the VAO.
static bool _initialized; ///< Flag whether the static members are initialized;
static size_t _currentlyBoundVertexArray; ///< Id of the VertexArrayObject which was bound most recently. 0 if the most recent bind call was unbind().
std::map<BufferObject*, GLuint> _locationMap; ///< Mapping added BufferObjects to locations.
static const std::string loggerCat_;
};
......
......@@ -153,7 +153,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
}
// lookup intensity and TF
float intensity = getElement3DNormalized(_volume, _volumeTextureParams, samplePosition).a;
float intensity = getElement3DNormalized(_volume, _volumeTextureParams, samplePosition).r;
vec4 color = lookupTF(_transferFunction, _transferFunctionParams, intensity);
#ifdef INTERSECTION_REFINEMENT
......@@ -172,7 +172,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
vec3 newSamplePosition = entryPoint.rgb + newT * direction;
// lookup refined intensity + TF
float newIntensity = getElement3DNormalized(_volume, _volumeTextureParams, newSamplePosition).a;
float newIntensity = getElement3DNormalized(_volume, _volumeTextureParams, newSamplePosition).r;
vec4 newColor = lookupTF(_transferFunction, _transferFunctionParams, newIntensity);
if (newColor.a <= 0.0) {
......
......@@ -93,7 +93,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
vec3 samplePosition = entryPoint.rgb + t * direction;
// lookup intensity and TF
float intensity = getElement3DNormalized(_volume, _volumeTextureParams, samplePosition).a;
float intensity = getElement3DNormalized(_volume, _volumeTextureParams, samplePosition).r;
vec4 color = lookupTF(_transferFunction, _transferFunctionParams, intensity);
#ifdef ENABLE_SHADOWING
......@@ -109,7 +109,7 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
// traverse ray from sample to light
while (! finished) {
// grab intensity and TF opacity
intensity = getElement3DNormalized(_volume, _volumeTextureParams, position).a;
intensity = getElement3DNormalized(_volume, _volumeTextureParams, position).r;
shadowFactor += lookupTF(_transferFunction, _transferFunctionParams, intensity).a;
position += L;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment