Commit 00d489a9 authored by schultezub's avatar schultezub

* refactored geometry BufferObjects into GeometryData

 * fixed TargetType and UsageType of BufferObjects simplifying method signature
 * fix in CLRaycaster

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@272 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent cc2ab402
......@@ -38,18 +38,12 @@ namespace TUMVis {
const std::string FaceGeometry::loggerCat_ = "TUMVis.core.datastructures.FaceGeometry";
FaceGeometry::FaceGeometry(const std::vector<tgt::vec3>& vertices, const std::vector<tgt::vec3>& textureCoordinates /*= std::vector<tgt::vec3>()*/, const std::vector<tgt::vec4>& colors /*= std::vector<tgt::vec4>()*/, const std::vector<tgt::vec3>& normals /*= std::vector<tgt::vec3>() */)
: AbstractData()
: GeometryData()
, _vertices(vertices)
, _textureCoordinates(textureCoordinates)
, _colors(colors)
, _normals(normals)
, _faceNormal(0.f)
, _buffersInitialized(false)
, _verticesBuffer(0)
, _texCoordsBuffer(0)
, _colorsBuffer(0)
, _normalsBuffer(0)
, _vao(0)
{
tgtAssert(textureCoordinates.empty() || textureCoordinates.size() == vertices.size(), "Texture coordinates vector must be either empty or of the same size as the vertex vector.");
tgtAssert(colors.empty() || colors.size() == vertices.size(), "Colors vector must be either empty or of the same size as the vertex vector.");
......@@ -62,11 +56,7 @@ namespace TUMVis {
}
FaceGeometry::~FaceGeometry() {
delete _vao;
delete _verticesBuffer;
delete _texCoordsBuffer;
delete _colorsBuffer;
delete _normalsBuffer;
}
FaceGeometry* FaceGeometry::clone() const {
......@@ -113,30 +103,32 @@ namespace TUMVis {
vao.addVertexAttribute(tgt::VertexArrayObject::ColorsAttribute, _colorsBuffer);
if (_normalsBuffer)
vao.addVertexAttribute(tgt::VertexArrayObject::NormalsAttribute, _normalsBuffer);
LGL_ERROR;
if (_vertices.size() > 2)
glDrawArrays(GL_POLYGON, 0, _vertices.size());
else
glDrawArrays(GL_LINES, 0, _vertices.size());
LGL_ERROR;
}
void FaceGeometry::createGLBuffers() {
if (! _buffersInitialized) {
try {
_verticesBuffer = new tgt::BufferObject();
_verticesBuffer->data(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW, &_vertices.front(), _vertices.size() * sizeof(tgt::vec3), tgt::BufferObject::FLOAT, 3);
_verticesBuffer = new tgt::BufferObject(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW);
_verticesBuffer->data(&_vertices.front(), _vertices.size() * sizeof(tgt::vec3), tgt::BufferObject::FLOAT, 3);
if (! _textureCoordinates.empty()) {
_texCoordsBuffer = new tgt::BufferObject();
_texCoordsBuffer->data(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW, &_textureCoordinates.front(), _textureCoordinates.size() * sizeof(tgt::vec3), tgt::BufferObject::FLOAT, 3);
_texCoordsBuffer = new tgt::BufferObject(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW);
_texCoordsBuffer->data(&_textureCoordinates.front(), _textureCoordinates.size() * sizeof(tgt::vec3), tgt::BufferObject::FLOAT, 3);
}
if (! _colors.empty()) {
_colorsBuffer = new tgt::BufferObject();
_colorsBuffer->data(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW, &_colors.front(), _colors.size() * sizeof(tgt::vec4), tgt::BufferObject::FLOAT, 4);
_colorsBuffer = new tgt::BufferObject(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW);
_colorsBuffer->data(&_colors.front(), _colors.size() * sizeof(tgt::vec4), tgt::BufferObject::FLOAT, 4);
}
if (! _normals.empty()) {
_normalsBuffer = new tgt::BufferObject();
_normalsBuffer->data(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW, &_normals.front(), _normals.size() * sizeof(tgt::vec3), tgt::BufferObject::FLOAT, 3);
_normalsBuffer = new tgt::BufferObject(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW);
_normalsBuffer->data(&_normals.front(), _normals.size() * sizeof(tgt::vec3), tgt::BufferObject::FLOAT, 3);
}
}
catch (tgt::Exception& e) {
......@@ -145,6 +137,7 @@ namespace TUMVis {
return;
}
LGL_ERROR;
_buffersInitialized = true;
}
}
......
......@@ -27,16 +27,12 @@
#ifndef FACEGEOMETRY_H__
#define FACEGEOMETRY_H__
#include "tgt/bounds.h"
#include "tgt/vector.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/geometrydata.h"
#include <vector>
namespace tgt {
class BufferObject;
class VertexArrayObject;
}
namespace TUMVis {
/**
......@@ -52,7 +48,7 @@ namespace TUMVis {
* \note Like all Geometry classes FaceGeometry has value-sematics: Once created, the
* vertices/colors/etc. cannot be altered anymore.
*/
class FaceGeometry : public AbstractData {
class FaceGeometry : public GeometryData {
public:
/**
* Creates a new FaceGeometry.
......@@ -116,18 +112,16 @@ namespace TUMVis {
* Renders this FaceGeometry.
* Must be called from a valid OpenGL context.
*/
void render();
virtual void render();
/**
* Creates the OpenGL VBOs and the VAO for this face's geometry.
* Must be called from a valid OpenGL context.
*/
void createGLBuffers();
virtual void createGLBuffers();
protected:
FaceGeometry(const FaceGeometry& rhs);
FaceGeometry& operator=(const FaceGeometry& rhs);
protected:
std::vector<tgt::vec3> _vertices; ///< The list of the vertex positions of the face.
std::vector<tgt::vec3> _textureCoordinates; ///< The list of vertex texture coordinates, may be empty.
std::vector<tgt::vec4> _colors; ///< The list of vertex colors, may be empty.
......@@ -135,16 +129,10 @@ namespace TUMVis {
tgt::vec3 _faceNormal; ///< The normal vector of this face.
bool _buffersInitialized;
tgt::BufferObject* _verticesBuffer;
tgt::BufferObject* _texCoordsBuffer;
tgt::BufferObject* _colorsBuffer;
tgt::BufferObject* _normalsBuffer;
tgt::VertexArrayObject* _vao;
static const std::string loggerCat_;
};
}
#endif // FACEGEOMETRY_H__
......@@ -27,15 +27,76 @@
// ================================================================================================
#include "geometrydata.h"
#include "tgt/buffer.h"
#include "tgt/vertexarrayobject.h"
namespace TUMVis {
GeometryData::GeometryData()
: AbstractData()
, _buffersInitialized(false)
, _verticesBuffer(0)
, _texCoordsBuffer(0)
, _colorsBuffer(0)
, _normalsBuffer(0)
{
}
GeometryData::GeometryData(const GeometryData& rhs)
: AbstractData(rhs)
, _buffersInitialized(false)
, _verticesBuffer(0)
, _texCoordsBuffer(0)
, _colorsBuffer(0)
, _normalsBuffer(0)
{
}
GeometryData::~GeometryData() {
delete _verticesBuffer;
delete _texCoordsBuffer;
delete _colorsBuffer;
delete _normalsBuffer;
}
GeometryData& GeometryData::operator=(const GeometryData& rhs) {
if (this == &rhs)
return *this;
AbstractData::operator=(rhs);
// delete old VBOs and null pointers
delete _verticesBuffer;
_verticesBuffer = 0;
delete _texCoordsBuffer;
_texCoordsBuffer = 0;
delete _colorsBuffer;
_colorsBuffer = 0;
delete _normalsBuffer;
_normalsBuffer = 0;
_buffersInitialized = false;
return *this;
}
const tgt::BufferObject* GeometryData::getVerticesBuffer() const {
return _verticesBuffer;
}
const tgt::BufferObject* GeometryData::getTextureCoordinatesBuffer() const {
return _texCoordsBuffer;
}
const tgt::BufferObject* GeometryData::getColorsBuffer() const {
return _colorsBuffer;
}
const tgt::BufferObject* GeometryData::getNormalsBuffer() const {
return _normalsBuffer;
}
}
\ No newline at end of file
......@@ -31,6 +31,10 @@
#include "core/datastructures/abstractdata.h"
namespace tgt {
class BufferObject;
}
namespace TUMVis {
/**
* Abstract base class for data handled by a DataHandle and stored in a DataContainer.
......@@ -41,12 +45,44 @@ namespace TUMVis {
public:
GeometryData();
GeometryData(const GeometryData& rhs);
/**
* Destructor, deletes VBOs/VAO if necessary. Hence, needs a valid OpenGL context
*/
virtual ~GeometryData();
GeometryData& operator=(const GeometryData& rhs);
virtual AbstractData* clone() const = 0;
/**
* Renders this GeometryData.
* Must be called from a valid OpenGL context.
*/
virtual void render() = 0;
/**
* Creates the OpenGL VBOs and the VAO for this geometry.
* Must be called from a valid OpenGL context.
*/
virtual void createGLBuffers() = 0;
const tgt::BufferObject* getVerticesBuffer() const;
const tgt::BufferObject* getTextureCoordinatesBuffer() const;
const tgt::BufferObject* getColorsBuffer() const;
const tgt::BufferObject* getNormalsBuffer() const;
protected:
bool _buffersInitialized;
tgt::BufferObject* _verticesBuffer;
tgt::BufferObject* _texCoordsBuffer;
tgt::BufferObject* _colorsBuffer;
tgt::BufferObject* _normalsBuffer;
};
}
......
......@@ -28,12 +28,37 @@
#version 330
in vec3 in_Position;
in vec3 in_TexCoords;
in vec3 in_Position; ///< incoming vertex position
in vec3 in_TexCoord; ///< incoming texture coordinate
in vec4 in_Color; ///< incoming color
out vec3 ex_TexCoord; ///< outgoing texture coordinate
out vec4 ex_Color; ///< outgoing color
/// Matrix defining model-to-world transformation
uniform mat4 _modelMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
/// Matrix defining view transformation
uniform mat4 _viewMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
/// Matrix defining projection transformation
uniform mat4 _projectionMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
out vec3 ex_TexCoords;
void main() {
gl_Position = vec4(in_Position, 1.0);
ex_TexCoords = in_TexCoords;
gl_Position = _projectionMatrix * (_viewMatrix * (_modelMatrix * vec4(in_Position, 1.0)));
ex_TexCoord = in_TexCoord;
ex_Color = in_Color;
}
......@@ -2,8 +2,10 @@
namespace tgt {
BufferObject::BufferObject()
BufferObject::BufferObject(TargetType target, UsageType usage)
: _id(0)
, _targetType(target)
, _usageType(usage)
, _baseType(BYTE)
, _elementSize(1)
, _size(0)
......@@ -22,20 +24,20 @@ namespace tgt {
glDeleteBuffers(1, &_id);
}
void BufferObject::bind(TargetType target) {
glBindBuffer(target, _id);
void BufferObject::bind() {
glBindBuffer(_targetType, _id);
}
void BufferObject::data(TargetType target, UsageType usage, const void* data, size_t numBytes, BaseType baseType, size_t elementSize) {
bind(target);
glBufferData(target, numBytes, data, usage);
void BufferObject::data(const void* data, size_t numBytes, BaseType baseType, size_t elementSize) {
bind();
glBufferData(_targetType, numBytes, data, _usageType);
_baseType = baseType;
_elementSize = elementSize;
}
void BufferObject::subdata(TargetType target, UsageType usage, size_t offset, const void* data, size_t numBytes) {
bind(target);
glBufferSubData(target, offset, numBytes, data);
void BufferObject::subdata(size_t offset, const void* data, size_t numBytes) {
bind();
glBufferSubData(_targetType, offset, numBytes, data);
}
void BufferObject::bindToVertexAttribute(const VertexAttribute* va) {
......
......@@ -44,9 +44,11 @@ namespace tgt {
/**
* Creates a new OpenGL buffer object and generates an ID for it.
* \param target Target type of buffer object.
* \param usage Usage of data.
* \throw tgt::Exception when OpenGL buffer generation failed.
*/
BufferObject() throw (tgt::Exception);
BufferObject(TargetType target, UsageType usage) throw (tgt::Exception);
/**
* Disposes and deletes the OpenGL buffer object.
......@@ -71,28 +73,24 @@ namespace tgt {
* Binds the buffer object to the current OpenGL context.
* \param target Target type of buffer object
*/
void bind(TargetType target);
void bind();
/**
* Binds the buffer, reserves space on the OpenGL device and initializes it with the given data in \a data.
* \param target Target type of buffer object.
* \param usage Usage of data.
* \param data Pointer to host memory containing the data.
* \param numBytes Size of \a data in bytes.
* \param baseType Base data type
* \param elementSize Number of elements per element (must be 1, 2, 3 or 4)
*/
void data(TargetType target, UsageType usage, const void* data, size_t numBytes, BaseType baseType, size_t elementSize);
void data(const void* data, size_t numBytes, BaseType baseType, size_t elementSize);
/**
* Updates a subset of the buffer's data.
* \param target Target type of buffer object.
* \param usage Usage of data.
* \param offset Offset where to start writing in buffer's data in bytes.
* \param data Pointer to host memory containing the data.
* \param numBytes Size of \a data in bytes.
*/
void subdata(TargetType target, UsageType usage, size_t offset, const void* data, size_t numBytes);
void subdata(size_t offset, const void* data, size_t numBytes);
protected:
......@@ -110,6 +108,8 @@ namespace tgt {
GLuint _id; ///< OpenGL ID of this buffer
TargetType _targetType; ///< Target type of buffer object
UsageType _usageType; ///< Usage type of data.
BaseType _baseType; ///< Base data type
size_t _elementSize; ///< Number of elements per element *lol* (must be 1, 2, 3 or 4)
......
......@@ -18,7 +18,7 @@ namespace tgt {
_bufferObject->bindToVertexAttribute(this);
// Todo: implement normalized flag if needed
_bufferObject->bind(BufferObject::ARRAY_BUFFER);
_bufferObject->bind();
glVertexAttribPointer(_index, _bufferObject->getElementSize(), _bufferObject->getBaseType(), false, _stride, reinterpret_cast<void*>(_offset));
}
......
......@@ -92,9 +92,11 @@ namespace TUMVis {
VisualizationProcessor::init();
_clContext = CLRtm.createGlSharingContext();
_clProgram = CLRtm.loadProgram(_clContext, "modules/vis/clraycaster.cl");
_clProgram->setBuildOptions(" -cl-fast-relaxed-math -cl-mad-enable");
_clProgram->build();
if (_clContext != 0) {
_clProgram = CLRtm.loadProgram(_clContext, "modules/vis/clraycaster.cl");
_clProgram->setBuildOptions(" -cl-fast-relaxed-math -cl-mad-enable");
_clProgram->build();
}
}
void CLRaycaster::deinit() {
......@@ -104,6 +106,9 @@ namespace TUMVis {
}
void CLRaycaster::process(DataContainer& data) {
if (_clContext == 0 || _clProgram == 0)
return;
DataContainer::ScopedTypedData<ImageDataLocal> img(data, _sourceImageID.getValue());
DataContainer::ScopedTypedData<ImageDataRenderTarget> entryPoints(data, _entryImageID.getValue());
DataContainer::ScopedTypedData<ImageDataRenderTarget> exitPoints(data, _exitImageID.getValue());
......
......@@ -90,7 +90,7 @@ namespace TUMVis {
rt->activate();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoords");
_shader->setAttributeLocation(1, "in_TexCoord");
QuadRdr.renderQuad();
rt->deactivate();
......
......@@ -28,7 +28,7 @@
#version 330
in vec3 ex_TexCoords;
in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/texture2d.frag"
......@@ -40,6 +40,6 @@ uniform sampler1D _tfTex;
uniform TFParameters _tfTextureParameters;
void main() {
float intensity = getElement2DNormalized(_texture, ex_TexCoords.xy).a;
float intensity = getElement2DNormalized(_texture, ex_TexCoord.xy).a;
out_Color = lookupTF(_tfTextureParameters, _tfTex, intensity);
}
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