Commit 54aa81c8 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Refactored multiple classes in order to separate glew from Qt5GL.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18898 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f2b03b2c
......@@ -51,6 +51,7 @@
//== INCLUDES =================================================================
#include <GL/glew.h>
#include <ACG/GL/AntiAliasing.hh>
#include <ACG/Math/VectorT.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
......
......@@ -56,8 +56,8 @@
//== INCLUDES =================================================================
// GL
#include <ACG/GL/gl.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/GL/gl.hh>
// C++
#include <vector>
......
This diff is collapsed.
......@@ -60,14 +60,14 @@
#include <OpenMesh/Core/Utils/Property.hh>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <ACG/Config/ACGDefines.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/GL/GLState.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/MeshCompiler.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/Config/ACGDefines.hh>
//== FORWARDDECLARATIONS ======================================================
......@@ -77,6 +77,80 @@ namespace ACG {
//== CLASS DEFINITION =========================================================
/**
* This class holds non-templated code and is intended to be inherited
* by the templated DrawMeshT class.
*/
class ACGDLLEXPORT DrawMeshBase {
protected:
DrawMeshBase();
~DrawMeshBase();
void deleteIbo();
void bindVbo();
void bindIbo();
void bindLineIbo();
void bindPickVertexIbo();
void createIndexBuffer();
void fillLineBuffer(size_t n_edges, void *data);
void fillVertexBuffer();
void fillInvVertexMap(size_t n_vertices, void *data);
public:
unsigned int getNumTris() const { return numTris_; }
unsigned int getNumVerts() const { return numVerts_; }
/** \brief get mesh compiler used to create the draw mesh
*/
MeshCompiler* getMeshCompiler() {return meshComp_;}
unsigned int getNumSubsets() const {return meshComp_->getNumSubsets();}
/** \brief get index type of index buffer
*/
GLenum getIndexType() const {return indexType_;}
/** \brief get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
*
* @return index buffer object (UNSIGNED_INT), might be 0 if the openmesh object is a point cloud
*/
GLuint pickVertexIBO_opt() {return pickVertexIBO_;} // does not work
protected:
GLuint vbo_, ibo_;
size_t numTris_, numVerts_;
MeshCompiler* meshComp_;
/// index buffer used in Wireframe / Hiddenline mode
GLuint lineIBO_;
/// support for 2 and 4 byte unsigned integers
GLenum indexType_;
/** final vertex buffer used for rendering
* raw byte array, use write__() functions for access
*/
std::vector<char> vertices_;
/// vertex buffer layout declaration with per vertex colors
VertexDeclaration* vertexDecl_;
/// vertex buffer layout declaration with per edge colors
VertexDeclaration* vertexDeclEdgeCol_;
/// vertex buffer layout declaration with per halfedge colors
VertexDeclaration* vertexDeclHalfedgeCol_;
/// vertex buffer layout declaration with halfedge positions only
VertexDeclaration* vertexDeclHalfedgePos_;
/// map from openmesh vertex to vbo vertex id
GLuint pickVertexIBO_;
};
/** \brief Mesh Drawing Class
*
......@@ -88,7 +162,7 @@ namespace ACG {
*/
template <class Mesh>
class DrawMeshT
class DrawMeshT : public DrawMeshBase
{
private:
......@@ -131,14 +205,6 @@ public:
*/
GLuint getIBO();
/** \brief get index type of index buffer
*/
GLenum getIndexType() const {return indexType_;}
/** \brief get mesh compiler used to create the draw mesh
*/
MeshCompiler* getMeshCompiler() {return meshComp_;}
/** \brief get vertex declaration of the current vbo layout
*/
......@@ -193,10 +259,6 @@ public:
void addPointRenderObjects(IRenderer* _renderer, const RenderObject* _baseObj);
unsigned int getNumTris() const {return numTris_;}
unsigned int getNumVerts() const {return numVerts_;}
unsigned int getNumSubsets() const {return meshComp_->getNumSubsets();}
/** \brief measures the size in bytes of allocated memory.
eventually prints a report to std::cout
......@@ -431,13 +493,6 @@ public:
#endif // GL_ARB_texture_buffer_object
/** \brief get an index buffer mapping from openmesh vertices to drawmesh vbo vertices
*
* @return index buffer object (UNSIGNED_INT), might be 0 if the openmesh object is a point cloud
*/
GLuint pickVertexIBO_opt() {return pickVertexIBO_;} // does not work
private:
/// The vertex buffer used for vertex picking
......@@ -451,9 +506,6 @@ private:
TextureBuffer pickVertexMapTBO_;
#endif // GL_ARB_texture_buffer_object
// map from openmesh vertex to vbo vertex id
GLuint pickVertexIBO_;
// vertex picking shader
GLSL::Program* pickVertexShader_;
......@@ -762,18 +814,9 @@ private:
/// OpenMesh object to be rendered
Mesh& mesh_;
MeshCompiler* meshComp_;
size_t numTris_, numVerts_;
/// final index buffer used for rendering
unsigned int* indices_;
/** final vertex buffer used for rendering
* raw byte array, use write__() functions for access
*/
std::vector<char> vertices_;
/// hint on what to rebuild
unsigned int rebuild_;
......@@ -783,15 +826,6 @@ private:
size_t prevNumFaces_,prevNumVerts_;
GLuint vbo_,
ibo_;
/// index buffer used in Wireframe / Hiddenline mode
GLuint lineIBO_;
/// support for 2 and 4 byte unsigned integers
GLenum indexType_;
/// Color Mode: 0: none, 1: per vertex, else: per face
int colorMode_;
......@@ -823,18 +857,6 @@ private:
unsigned int* invVertexMap_;
/// vertex buffer layout declaration with per vertex colors
VertexDeclaration* vertexDecl_;
/// vertex buffer layout declaration with per edge colors
VertexDeclaration* vertexDeclEdgeCol_;
/// vertex buffer layout declaration with per halfedge colors
VertexDeclaration* vertexDeclHalfedgeCol_;
/// vertex buffer layout declaration with halfedge positions only
VertexDeclaration* vertexDeclHalfedgePos_;
//========================================================================
// flexible vertex layout
......@@ -1041,9 +1063,9 @@ private:
//=============================================================================
} // namespace ACG
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ACG_DRAW_MESH_C)
#if defined(INCLUDE_TEMPLATES) && !defined(ACG_DRAW_MESH_TCC)
#define ACG_DRAW_MESH_TEMPLATES
#include "DrawMesh.cc"
#include "DrawMesh.tcc"
#endif
//=============================================================================
#endif // ACG_DRAW_MESH_HH defined
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
//== INCLUDES =================================================================
#include <GL/glew.h>
#include "FBO.hh"
#include "GLState.hh"
#include "GLError.hh"
......
......@@ -40,6 +40,7 @@
* *
\*===========================================================================*/
#include <GL/glew.h>
#include <iostream>
#include <cstdio>
......
......@@ -49,6 +49,7 @@
//== INCLUDES =================================================================
#include <GL/glew.h>
#include "GLState.hh"
......@@ -2059,6 +2060,38 @@ void GLState::useProgram(GLuint _program)
}
}
void GLState::genBuffersARB(GLsizei n, GLuint* buffers) {
glGenBuffersARB(n, buffers);
}
void GLState::genBuffers(GLsizei n, GLuint* buffers) {
glGenBuffers(n, buffers);
}
void GLState::bufferDataARB(
GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) {
glBufferDataARB(target, size, data, usage);
}
void GLState::bufferData(
GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) {
glBufferData(target, size, data, usage);
}
void GLState::deleteBuffers(GLsizei n, const GLuint* buffers) {
glDeleteBuffers(n, buffers);
}
GLvoid* GLState::mapBuffer (GLenum target, GLenum access) {
return glMapBuffer(target, access);
}
GLboolean GLState::unmapBuffer (GLenum target) {
return unmapBuffer(target);
}
//---------------------------------------------------------------------
......
......@@ -484,6 +484,50 @@ public:
* @{ */
//===========================================================================
/**
* Simple wrapper around glGenBuffersARB.
* Useful where glew cannot be included.
*/
static void genBuffersARB(GLsizei n, GLuint* buffers);
/**
* Simple wrapper around glGenBuffers.
* Useful where glew cannot be included.
*/
static void genBuffers(GLsizei n, GLuint* buffers);
/**
* Simple wrapper around glBufferDataARB.
* Useful where glew cannot be included.
*/
static void bufferDataARB(
GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
/**
* Simple wrapper around glBufferData.
* Useful where glew cannot be included.
*/
static void bufferData(
GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
/**
* Simple wrapper around glMapBuffer.
* Useful where glew cannot be included.
*/
static GLvoid* mapBuffer (GLenum target, GLenum access);
/**
* Simple wrapper around glUnmapBuffer.
* Useful where glew cannot be included.
*/
static GLboolean unmapBuffer (GLenum target);
/**
* Simple wrapper around glDeleteBuffers.
* Useful where glew cannot be included.
*/
static void deleteBuffers(GLsizei n, const GLuint* buffers);
/// replaces glBindBuffer, supports locking
static void bindBuffer(GLenum _target, GLuint _buffer);
/// same function as bindBuffer
......
......@@ -40,6 +40,7 @@
* *
\*===========================================================================*/
#include <GL/glew.h>
#include <cstdio>
#include <cstring>
#include <iostream>
......
......@@ -51,7 +51,7 @@
//== INCLUDES =================================================================
#include <GL/glew.h>
#include "ScreenQuad.hh"
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/GLError.hh>
......
......@@ -40,6 +40,7 @@
* *
\*===========================================================================*/
#include <GL/glew.h>
#include <ACG/GL/gl.hh>
#include <ACG/GL/GLState.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
......
......@@ -73,7 +73,6 @@
#else
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#include <GL/glew.h>
#include "globjects.hh"
namespace ACG {
#if defined(GL_ARB_vertex_buffer_object)
void VertexBufferObject::del() {
if (valid)
glDeleteBuffersARB(1, &vbo);
valid = false;
}
void VertexBufferObject::upload(
GLsizeiptr size, const GLvoid* data, GLenum usage) {
if(!valid)
gen();
glBufferDataARB(target, size, data, usage);
}
void VertexBufferObject::uploadSubData(
GLuint _offset, GLuint _size, const GLvoid* _data ) {
glBufferSubDataARB(target, _offset, _size, _data);
}
void VertexBufferObject::gen() {
glGenBuffersARB(1, &vbo);
if(vbo > 0u)
valid = true;
}
#endif
#if defined(GL_ARB_texture_buffer_object)
TextureBuffer::~TextureBuffer() {
if (buffer_)
glDeleteBuffers(1, &buffer_);
}
void TextureBuffer::setBufferData(
int _size, const void* _data, GLenum _internalFormat, GLenum _usage) {
// setup buffer object
if (!buffer_)
glGenBuffers(1, &buffer_);
glBindBuffer(GL_TEXTURE_BUFFER, buffer_);
glBufferData(GL_TEXTURE_BUFFER, _size, _data, _usage);
// bind buffer to texture
if (getUnit() == GL_NONE)
setUnit(GL_TEXTURE0);
bind();
glTexBuffer(GL_TEXTURE_BUFFER, _internalFormat, buffer_);
bufferSize_ = _size;
}
#endif
#if defined(GL_NV_vertex_program) || defined(GL_NV_fragment_program)
void ProgramBaseNV::bind() {
if (!valid)
gen();
glBindProgramNV(target, program);
}
void ProgramBaseNV::unbind() {
glBindProgramNV(target, 0);
}
bool ProgramBaseNV::load(const char* prog_text) {
int size = int(strlen(prog_text));
if (!valid)
gen();
glLoadProgramNV(target, program, size, (const GLubyte *) prog_text);
GLint errpos;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errpos);
if (errpos != -1) {
fprintf(stderr, "\nprogram error:\n");
int bgn = std::max(0, errpos - 10), end = std::min(size, bgn + 30);
for (int i = bgn; i < end; ++i)
fputc(prog_text[i], stderr);
fputc('\n', stderr);
return false;
}
return true;
}
void ProgramBaseNV::gen() {
glGenProgramsNV(1, &program);
valid = true;
}
void ProgramBaseNV::del() {
if (valid)
glDeleteProgramsNV(1, &program);
valid = false;
}
#endif
#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
void ProgramBaseARB::bind() {
if (!valid)
gen();
glBindProgramARB(target, program);
}
void ProgramBaseARB::unbind() {
glBindProgramARB(target, 0);
}
bool ProgramBaseARB::load(const char* prog_text) {
int size = int(strlen(prog_text));
if (!valid)
gen();
bind();
glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, size, prog_text);
GLint errpos;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errpos);
if (errpos != -1) {
fprintf(stderr, "\nprogram error:\n");
int bgn = std::max(0, errpos - 10), end = std::min(size, bgn + 30);
for (int i = bgn; i < end; ++i)
fputc(prog_text[i], stderr);
fputc('\n', stderr);
return false;
}
return true;
}
void ProgramBaseARB::gen() {
glGenProgramsARB(1, &program);
valid = true;
}
void ProgramBaseARB::del() {
if (valid)
glDeleteProgramsARB(1, &program);
valid = false;
}
#endif
} /* namespace ACG */
......@@ -125,22 +125,16 @@ public:
virtual ~VertexBufferObject() { del(); }
void del() { if(valid) glDeleteBuffersARB(1, &vbo); valid = false; }
void del();
bool is_valid() const { return valid; }
void bind() { if(!valid) gen(); ACG::GLState::bindBuffer(target, vbo); }
void unbind() { ACG::GLState::bindBuffer(target, 0); }
void upload(GLsizeiptr size, const GLvoid* data, GLenum usage)
{
if(!valid) gen();
glBufferDataARB(target, size, data, usage);
}
void upload(GLsizeiptr size, const GLvoid* data, GLenum usage);
// Upload a subset of the buffer data
void uploadSubData(GLuint _offset, GLuint _size, const GLvoid* _data ) {
glBufferSubDataARB(target, _offset, _size, _data);
}
void uploadSubData(GLuint _offset, GLuint _size, const GLvoid* _data );
char* offset(unsigned int _offset) const
{
......@@ -151,7 +145,7 @@ public:
private:
void gen() { glGenBuffersARB(1, &vbo); if(vbo > 0u) valid = true; }
void gen();
GLenum target;
bool valid;
......@@ -353,36 +347,13 @@ public:
TextureBuffer(GLenum u=GL_NONE)
: Texture(GL_TEXTURE_BUFFER, u), bufferSize_(0), buffer_(0) {}
~TextureBuffer()