Commit d53f361c authored by Robert Menzel's avatar Robert Menzel
Browse files

changed mixed CRLF/LF to LF

parent 3a8b2ebe
CMAKE_MINIMUM_REQUIRED (VERSION 2.6) CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
################################################################################ ################################################################################
# Global Settings # Global Settings
################################################################################ ################################################################################
# Name of the Project # Name of the Project
PROJECT(ACGL) PROJECT(ACGL)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/CompileOptions.txt) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/CompileOptions.txt)
# Specify dependencies # Specify dependencies
SET(NEED_ACGL_GLOBAL_EXTERN_DIR TRUE) SET(NEED_ACGL_GLOBAL_EXTERN_DIR TRUE)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/GlobalAndLocalExternACGL.txt) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/GlobalAndLocalExternACGL.txt)
# OpenGL Support # OpenGL Support
IF(NOT DEFINED OPENGL_SUPPORT) IF(NOT DEFINED OPENGL_SUPPORT)
IF(NOT DEFINED OPENGL_SUPPORT_CORE_4_0) IF(NOT DEFINED OPENGL_SUPPORT_CORE_4_0)
SET(OPENGL_SUPPORT_CORE_4_0 TRUE CACHE BOOL "") SET(OPENGL_SUPPORT_CORE_4_0 TRUE CACHE BOOL "")
ENDIF() ENDIF()
IF(NOT DEFINED OPENGL_SUPPORT_ES_2_1) IF(NOT DEFINED OPENGL_SUPPORT_ES_2_1)
SET(OPENGL_SUPPORT_ES_2_1 TRUE CACHE BOOL "") SET(OPENGL_SUPPORT_ES_2_1 TRUE CACHE BOOL "")
ENDIF() ENDIF()
IF(OPENGL_SUPPORT_CORE_4_0) IF(OPENGL_SUPPORT_CORE_4_0)
SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT_LIST} GL_CORE_4_0) SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT_LIST} GL_CORE_4_0)
ENDIF() ENDIF()
IF(OPENGL_SUPPORT_ES_2_1) IF(OPENGL_SUPPORT_ES_2_1)
SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT_LIST} GL_ES_2_1) SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT_LIST} GL_ES_2_1)
ENDIF() ENDIF()
ELSE() ELSE()
SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT}) SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT})
ENDIF() ENDIF()
FOREACH(OPENGL_SUPPORT ${OPENGL_SUPPORT_LIST} ) FOREACH(OPENGL_SUPPORT ${OPENGL_SUPPORT_LIST} )
################################################################################ ################################################################################
# Basic Configuration # Basic Configuration
################################################################################ ################################################################################
# Name of the Project # Name of the Project
PROJECT(AC${OPENGL_SUPPORT}) PROJECT(AC${OPENGL_SUPPORT})
# Where to find the cmake finders? # Where to find the cmake finders?
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Target directory # Target directory
SET(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib") SET(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib")
################################################################################ ################################################################################
# Project Files # Project Files
################################################################################ ################################################################################
# Find all used files of certain file-types # Find all used files of certain file-types
FILE(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc") FILE(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc")
FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hh") FILE(GLOB_RECURSE INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hh")
# Add ACGL to the include path # Add ACGL to the include path
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include") INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include")
################################################################################ ################################################################################
# External Libraries # External Libraries
################################################################################ ################################################################################
# Qt # Qt
SET(QT_USE_QTOPENGL TRUE) SET(QT_USE_QTOPENGL TRUE)
FIND_PACKAGE(Qt4 REQUIRED) FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE}) INCLUDE(${QT_USE_FILE})
SET(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES}) SET(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES})
# GLM # GLM
FIND_PACKAGE(GLM REQUIRED) FIND_PACKAGE(GLM REQUIRED)
INCLUDE_DIRECTORIES(${GLM_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${GLM_INCLUDE_DIR})
# GLEW # GLEW
FIND_PACKAGE(GLEW REQUIRED) FIND_PACKAGE(GLEW REQUIRED)
INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR})
SET(LIBRARIES ${LIBRARIES} ${GLEW_LIBRARIES}) SET(LIBRARIES ${LIBRARIES} ${GLEW_LIBRARIES})
################################################################################ ################################################################################
# Final Definition # Final Definition
################################################################################ ################################################################################
# Define the Project, add all required sources and dependencies to it # Define the Project, add all required sources and dependencies to it
ADD_LIBRARY(AC${OPENGL_SUPPORT}${COMPILE_POSTFIX} STATIC ${SOURCE_FILES} ${INCLUDE_FILES}) ADD_LIBRARY(AC${OPENGL_SUPPORT}${COMPILE_POSTFIX} STATIC ${SOURCE_FILES} ${INCLUDE_FILES})
TARGET_LINK_LIBRARIES(AC${OPENGL_SUPPORT}${COMPILE_POSTFIX} ${LIBRARIES}) TARGET_LINK_LIBRARIES(AC${OPENGL_SUPPORT}${COMPILE_POSTFIX} ${LIBRARIES})
ENDFOREACH() ENDFOREACH()
...@@ -3,112 +3,114 @@ ...@@ -3,112 +3,114 @@
// All rights reserved. // // All rights reserved. //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_GLUTILS_TOOLS_HH #ifndef ACGL_GLUTILS_TOOLS_HH
#define ACGL_GLUTILS_TOOLS_HH #define ACGL_GLUTILS_TOOLS_HH
#include <ACGL/ACGL.hh> #include <ACGL/ACGL.hh>
#include <ACGL/GL.hh> #include <ACGL/GL.hh>
namespace ACGL{ namespace ACGL{
namespace GLUtils{ namespace GLUtils{
namespace Tools{ namespace Tools{
inline GLint getGLTypeSize ( GLenum _type ) inline GLint getGLTypeSize ( GLenum _type )
{ {
switch(_type) switch(_type)
{ {
case GL_BYTE: return sizeof(GLubyte); case GL_BYTE: return sizeof(GLubyte);
case GL_UNSIGNED_BYTE: return sizeof(GLbyte); case GL_UNSIGNED_BYTE: return sizeof(GLbyte);
case GL_SHORT: return sizeof(GLshort); case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort); case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_INT: return sizeof(GLint); case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint); case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_FLOAT: return sizeof(GLfloat); case GL_FLOAT: return sizeof(GLfloat);
case GL_DOUBLE: return sizeof(GLdouble); case GL_DOUBLE: return sizeof(GLdouble);
} }
return 0; return 0;
} }
// for every OpenGL error enum this will return a human readable version of it // for every OpenGL error enum this will return a human readable version of it
// similar to gluErrorString, but that function is not available on all plattforms // similar to gluErrorString, but that function is not available on all plattforms
// (read: iOS) // (read: iOS)
const GLubyte* acglErrorString( GLenum err ); const GLubyte* acglErrorString( GLenum err );
/* /*
* This function can be used outside of the ACGL framework to check always(!) for * This function can be used outside of the ACGL framework to check always(!) for
* OpenGL errors. It will print the errors and return the error code of the last one. * OpenGL errors. It will print the errors and return the error code of the last one.
* Each OpenGL command can only throw one error, errors can only stack up if this * Each OpenGL command can only throw one error, errors can only stack up if this
* function or glGetError was not called often enough (and some OpenGL implementations * function or glGetError was not called often enough (and some OpenGL implementations
* will forget old errors if new ones occur). * will forget old errors if new ones occur).
*/ */
#define openGLError() openGLError_( __FILE__, __LINE__ ) #define openGLError() openGLError_( __FILE__, __LINE__ )
/* /*
* This function is used internally in ACGL - but not directly. It gets called from all * This function is used internally in ACGL - but not directly. It gets called from all
* other rare/common/critical error checks. The __FILE__ __LINE macros have to be used in * other rare/common/critical error checks. The __FILE__ __LINE macros have to be used in
* those to get the correct values from the caller file, if we would use the macro * those to get the correct values from the caller file, if we would use the macro
* above we could get the file/line from this file, which isn't helping. * above we could get the file/line from this file, which isn't helping.
*/ */
GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber ); GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber );
/* /*
* Inside of ACGL we distinguish between rare, common and critical errors. Each kind can be * Inside of ACGL we distinguish between rare, common and critical errors. Each kind can be
* switched off which turns the function into nothing after compiler optimization. If an * switched off which turns the function into nothing after compiler optimization. If an
* error check is turned off it will always behave as if there was no error, even if there * error check is turned off it will always behave as if there was no error, even if there
* is one... * is one...
* *
* Per default a debug build enables critical and common errors, a release build only critical * Per default a debug build enables critical and common errors, a release build only critical
* ones. * ones.
* *
* We have two functions for each kind: * We have two functions for each kind:
* openGL____Error() will print error messages and return the last error (or GL_NO_ERROR) * openGL____Error() will print error messages and return the last error (or GL_NO_ERROR)
* openGL____ErrorOccured() will print error messages and retrun true if there was an error * openGL____ErrorOccured() will print error messages and retrun true if there was an error
* *
* The definition of rare/common/critical is a bit fuzzy: * The definition of rare/common/critical is a bit fuzzy:
* *
* critical: Errors which can occur even in a bug-free app, like out-of-memory errors. * critical: Errors which can occur even in a bug-free app, like out-of-memory errors.
* These checks are rare, stuff like glCreate calls get checked here. * These checks are rare, stuff like glCreate calls get checked here.
* Tests for critical errors should not impact the performance of the app measurably. * Tests for critical errors should not impact the performance of the app measurably.
* *
* common: Errors which are quite common while developing. Misuse of the library etc. * common:
* Setting uniforms which don't exist or shader compile errors are candidates for * Errors which are quite common while developing. Misuse of the library etc.
* common errors. Places where OpenGL resources are calles by a string etc. * Setting uniforms which don't exist or shader compile errors are candidates for
* * common errors. Places where OpenGL resources are calles by a string etc.
* rare: Errors which are so uncommon that we don't even check those ina normal debug build. *
* Switching these on can impact performance as there can be alot of them. If theres a * rare: Errors which are so uncommon that we don't even check those ina normal debug build.
* OpenGL error somewhere in the code, switch these checks on to find the correct spot. * Switching these on can impact performance as there can be alot of them. If theres a
* * OpenGL error somewhere in the code, switch these checks on to find the correct spot.
* OpenGL error checks that are more complicated than just a glGetError call will be wrapped in the *
* same defines, this can be used in application code as well. * OpenGL error checks that are more complicated than just a glGetError call will be wrapped in the
* * same defines, this can be used in application code as well.
*/ *
#ifdef ACGL_CHECK_CRITICAL_GL_ERRORS */
# define openGLCriticalError() openGLError_( __FILE__, __LINE__ ) #ifdef ACGL_CHECK_CRITICAL_GL_ERRORS
# define openGLCriticalErrorOccured() (openGLError_( __FILE__, __LINE__ ) != GL_NO_ERROR) # define openGLCriticalError() openGLError_( __FILE__, __LINE__ )
#else # define openGLCriticalErrorOccured() (openGLError_( __FILE__, __LINE__ ) != GL_NO_ERROR)
inline GLenum openGLCriticalError() { return GL_NO_ERROR; } #else
inline bool openGLCriticalErrorOccured() { return false; } inline GLenum openGLCriticalError() { return GL_NO_ERROR; }
#endif inline bool openGLCriticalErrorOccured() { return false; }
#endif
#ifdef ACGL_CHECK_COMMON_GL_ERRORS
# define openGLCommonError() openGLError_( __FILE__, __LINE__ ) #ifdef ACGL_CHECK_COMMON_GL_ERRORS
# define openGLCommonErrorOccured() (openGLError_( __FILE__, __LINE__ ) != GL_NO_ERROR) # define openGLCommonError() openGLError_( __FILE__, __LINE__ )
#else # define openGLCommonErrorOccured() (openGLError_( __FILE__, __LINE__ ) != GL_NO_ERROR)
inline GLenum openGLCommonError() { return GL_NO_ERROR; } #else
inline bool openGLCommonErrorOccured() { return false; } inline GLenum openGLCommonError() { return GL_NO_ERROR; }
#endif inline bool openGLCommonErrorOccured() { return false; }
#endif
#ifdef ACGL_CHECK_RARE_GL_ERRORS
# define openGLRareError() openGLError_( __FILE__, __LINE__ ) #ifdef ACGL_CHECK_RARE_GL_ERRORS
# define openGLRareErrorOccured() (openGLError_( __FILE__, __LINE__ ) != GL_NO_ERROR) # define openGLRareError() openGLError_( __FILE__, __LINE__ )
#else # define openGLRareErrorOccured() (openGLError_( __FILE__, __LINE__ ) != GL_NO_ERROR)
inline GLenum openGLRareError() { return GL_NO_ERROR; } #else
inline bool openGLRareErrorOccured() { return false; } inline GLenum openGLRareError() { return GL_NO_ERROR; }
#endif inline bool openGLRareErrorOccured() { return false; }
#endif
} // Tools
} // GLUtils } // Tools
} // ACGL } // GLUtils
} // ACGL
#endif // ACGL_GLUTILS_TOOLS_HH
#endif // ACGL_GLUTILS_TOOLS_HH
...@@ -3,179 +3,179 @@ ...@@ -3,179 +3,179 @@
// All rights reserved. // // All rights reserved. //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_RESOURCE_ARRAYBUFFER_HH #ifndef ACGL_RESOURCE_ARRAYBUFFER_HH
#define ACGL_RESOURCE_ARRAYBUFFER_HH #define ACGL_RESOURCE_ARRAYBUFFER_HH
#include <ACGL/GLUtils/Tools.hh> #include <ACGL/GLUtils/Tools.hh>
#include <ACGL/Types.hh> #include <ACGL/Types.hh>
#include <ACGL/GL.hh> #include <ACGL/GL.hh>
#include <string> #include <string>
#include <vector> #include <vector>
namespace ACGL{ namespace ACGL{
namespace Resource{ namespace Resource{
class ArrayBuffer class ArrayBuffer
{ {
// ==================================================================================================== \/ // ==================================================================================================== \/
// ============================================================================================ STRUCTS \/ // ============================================================================================ STRUCTS \/
// ==================================================================================================== \/ // ==================================================================================================== \/
public: public:
//! Each attribute has a dimension (#components, e.g. normal with x/y/z => 3) and an offset in the stride (in bytes) //! Each attribute has a dimension (#components, e.g. normal with x/y/z => 3) and an offset in the stride (in bytes)
struct Attribute struct Attribute
{ {
std::string name; std::string name;
GLenum type; GLenum type;
GLint dimension; GLint dimension;
GLint offset; GLint offset;
}; };
// ===================================================================================================== \/ // ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/ // ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/ // ===================================================================================================== \/
public: public:
typedef std::vector< Attribute > AttributeVec; typedef std::vector< Attribute > AttributeVec;
// ========================================================================================================= \/ // ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/ // ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/ // ========================================================================================================= \/
public: public:
ArrayBuffer( ArrayBuffer(
GLenum _usage = GL_STATIC_DRAW, GLenum _usage = GL_STATIC_DRAW,
GLenum _mode = GL_TRIANGLES) GLenum _mode = GL_TRIANGLES)
: mContext(0), : mContext(0),
mUsage(_usage), mUsage(_usage),
mMode(_mode), mMode(_mode),
mElements(0), mElements(0),
mStride(0), mStride(0),
mAttributes() mAttributes()
{ {
glGenBuffers(1, &mContext); glGenBuffers(1, &mContext);
} }
virtual ~ArrayBuffer(void) virtual ~ArrayBuffer(void)
{ {
if(mContext != 0) if(mContext != 0)
glDeleteBuffers(1, &mContext); glDeleteBuffers(1, &mContext);
} }
// ==================================================================================================== \/ // ==================================================================================================== \/
// ============================================================================================ GETTERS \/ // ============================================================================================ GETTERS \/
// ==================================================================================================== \/ // ==================================================================================================== \/
public: public:
inline GLuint getContext (void) const { return mContext; } inline GLuint getContext (void) const { return mContext; }
inline GLenum getUsage (void) const { return mUsage; } inline GLenum getUsage (void) const { return mUsage; }
inline GLenum getMode (void) const { return mMode; } inline GLenum getMode (void) const { return mMode; }
inline GLsizei getElements (void) const { return mElements; } inline GLsizei getElements (void) const { return mElements; }
inline GLsizei getStride (void) const { return mStride; } inline GLsizei getStride (void) const { return mStride; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; } inline const AttributeVec& getAttributes (void) const { return mAttributes; }
// ==================================================================================================== \/ // ==================================================================================================== \/
// ============================================================================================ SETTERS \/ // ============================================================================================ SETTERS \/
// ==================================================================================================== \/ // ==================================================================================================== \/
public: public:
inline void setUsage (GLenum _usage) { mUsage = _usage; } inline void setUsage (GLenum _usage) { mUsage = _usage; }
inline void setMode (GLenum _mode) { mMode = _mode; } inline void setMode (GLenum _mode) { mMode = _mode; }
// ==================================================================================================== \/ // ==================================================================================================== \/
// ============================================================================================ METHODS \/ // ============================================================================================ METHODS \/
// ==================================================================================================== \/ // ==================================================================================================== \/
public: public:
int_t getAttributeIndexByName(const std::string& _nameInArray) const; int_t getAttributeIndexByName(const std::string& _nameInArray) const;
inline void attachAttribute( inline void attachAttribute(
const std::string& _name, const std::string& _name,
GLenum _type, GLenum _type,
GLint _dimension) GLint _dimension)
{ {
Attribute attribute = { Attribute attribute = {
_name, _name,
_type, _type,
_dimension, _dimension,
mStride}; mStride};
mStride += GLUtils::Tools::getGLTypeSize(_type) * _dimension; mStride += GLUtils::Tools::getGLTypeSize(_type) * _dimension;
mAttributes.push_back(attribute); mAttributes.push_back(attribute);
} }
inline void removeAttributes(void) inline void removeAttributes(void)
{ {
mStride = 0; mStride = 0;
mAttributes.clear(); mAttributes.clear();
} }
// ===================================================================================================== \/ // ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/ // ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/ // ===================================================================================================== \/
public: public:
void render(void) const; void render(void) const;
void draw(void) const void draw(void) const
{ {
glDrawArrays(mMode, 0, mElements); glDrawArrays(mMode, 0, mElements);
} }
//! Bind this buffer //! Bind this buffer
inline void bind(void) const inline void bind(void) const
{ {
glBindBuffer(GL_ARRAY_BUFFER, mContext); glBindBuffer(GL_ARRAY_BUFFER, mContext);
} }
inline void setPointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const inline void setPointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
{ {
glVertexAttribPointer( glVertexAttribPointer(
_indexInShader, _indexInShader,
mAttributes[_indexInArray].dimension, mAttributes[_indexInArray].dimension,
mAttributes[_indexInArray].type, mAttributes[_indexInArray].type,
GL_FALSE, GL_FALSE,
mStride, mStride,
reinterpret_cast<GLvoid*>(mAttributes[_indexInArray].offset)); reinterpret_cast<GLvoid*>(mAttributes[_indexInArray].offset));
} }
inline bool setPointer(const std::string& _nameInArray, GLuint _indexInShader) const inline bool setPointer(const std::string& _nameInArray, GLuint _indexInShader) const
{ {
int_t index = getAttributeIndexByName(_nameInArray); int_t index = getAttributeIndexByName(_nameInArray);
if(index == -1) if(index == -1)
return false; return false;
setPointer(index, _indexInShader);