Commit 472edd4d authored by Robert Menzel's avatar Robert Menzel

improved OpenGL ES support

parent b41d0668
......@@ -7,6 +7,8 @@
#ifndef ACGL_ACGL_HH
#define ACGL_ACGL_HH
#include <ACGL/Base/OSDetection.hh>
/*!
* Include this in all ACGL (header)-files. It will include stuff that is used in
* almost every file:
......
......@@ -37,8 +37,6 @@
#define ACGL_DEBUG
#endif
//#error foo
/*
* Map CMake generated error-level defines to internally used, more readable defines
*/
......
/***********************************************************************
* Copyright 2015-2015 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#pragma once
// Android autodetection:
#ifdef __ANDROID__
# define ACGL_PLATFORM_ANDROID
#endif
// If we're compiling for an Apple system we need this to distinquish between Mac and iOS:
#ifdef __APPLE__
# include <TargetConditionals.h>
#endif
#if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
# if (TARGET_OS_IPHONE == 1)
# define ACGL_PLATFORM_IOS
# endif
#endif
......@@ -26,7 +26,7 @@ public:
};
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
// only for internal use!
// THE_GL_TYPE has to be:
// GL_BUFFER, GL_SHADER, GL_PROGRAM, GL_VERTEX_ARRAY, GL_QUERY, GL_PROGRAM_PIPELINE,
......@@ -49,6 +49,26 @@ std::string getObjectLabelT( GLuint _objectName )
return labelName;
}
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (GL_EXT_debug_label == 1))
// OpenGL ES with extensions:
template <unsigned int THE_GL_TYPE>
void setObjectLabelT( GLuint _objectName, const std::string &_label ) {
glLabelObjectEXT( THE_GL_TYPE, _objectName, 0, _label.c_str() );
}
template <unsigned int THE_GL_TYPE>
std::string getObjectLabelT( GLuint _objectName )
{
GLsizei labelLenght;
glGetObjectLabelEXT(THE_GL_TYPE, _objectName, 0, &labelLenght, NULL);
GLchar *tmp = new GLchar[labelLenght+1]; // +1 to have space for the 0-termination
glGetObjectLabelEXT(THE_GL_TYPE, _objectName, labelLenght+1, NULL, tmp);
std::string labelName(tmp);
delete[] tmp;
return labelName;
}
#endif
//! converts a KHR debug source enum to a human readable string
......
......@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_GL_HH
#define ACGL_OPENGL_GL_HH
#include <ACGL/Base/OSDetection.hh>
/*
* This simple OpenGL wrapper is used to include OpenGL (and if needed GLEW)
* on different platforms.
......@@ -39,22 +41,8 @@
* (full/compatibility profile).
*/
// Android autodetection:
#ifdef __ANDROID__
#if (defined(ACGL_PLATFORM_IOS) || defined(ACGL_PLATFORM_ANDROID))
# define ACGL_OPENGL_ES
# define PLATFORM_ANDROID
#endif
// If we're compiling for an Apple system we need this to distinquish between Mac and iOS:
#ifdef __APPLE__
# include <TargetConditionals.h>
#endif
#if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
# if (TARGET_OS_IPHONE == 1)
# define ACGL_PLATFORM_IOS
# define ACGL_OPENGL_ES
# endif
#endif
// To compare the OpenGL version number we define a new ACGL_OPENGL_VERSION XY define here
......@@ -130,15 +118,15 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if ACGL_OPENGL_VERSION > 32
// prevents QT from redefining the debug functions
#define GL_ARB_debug_output
#define GL_KHR_debug
// prevents QT from redefining the debug functions
#define GL_ARB_debug_output
#define GL_KHR_debug
// debug label, debug groups:
#define ACGL_OPENGL_DEBUGGER_SUPPORT
// debug label, debug groups:
#define ACGL_OPENGL_DEBUGGER_SUPPORT
// debug callbacks:
#define ACGL_OPENGL_DEBUG_CALLBACK_SUPPORT
// debug callbacks:
#define ACGL_OPENGL_DEBUG_CALLBACK_SUPPORT
#endif
void CHECKGLERROR();
......@@ -158,10 +146,11 @@ void CHECKGLERROR();
#elif defined (ACGL_OPENGLES_VERSION_30)
#import <OpenGLES/ES3/gl.h>
#import <OpenGLES/ES3/glext.h>
#define ACGL_OPENGL_DEBUGGER_SUPPORT
#else
#error "location of ES headers not known"
#endif
#elif defined (PLATFORM_ANDROID)
#elif defined (ACGL_PLATFORM_ANDROID)
// Android:
#if defined (ACGL_OPENGLES_VERSION_20)
#include <GLES2/gl2.h>
......
......@@ -114,9 +114,12 @@ public:
public:
// Sets and gets a label visible inside of a OpenGL debugger if KHR_debug is supported at runtime *and*
// if ACGL_OPENGL_DEBUGGER_SUPPORT was defined during compile time. Does nothing otherwise!
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_BUFFER>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_BUFFER>(getObjectName()); }
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGLES_VERSION >= 10))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_BUFFER_OBJECT_EXT>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_BUFFER_OBJECT_EXT>(getObjectName()); }
#else
void setObjectLabel( const std::string & ) {}
std::string getObjectLabel() { return ""; }
......
......@@ -52,9 +52,12 @@ public:
public:
// Sets and gets a label visible inside of a OpenGL debugger if KHR_debug is supported at runtime *and*
// if ACGL_OPENGL_DEBUGGER_SUPPORT was defined during compile time. Does nothing otherwise!
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_QUERY>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_QUERY>(getObjectName()); }
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGLES_VERSION >= 10))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_QUERY_OBJECT_EXT>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_QUERY_OBJECT_EXT>(getObjectName()); }
#else
void setObjectLabel( const std::string & ) {}
std::string getObjectLabel() { return ""; }
......
......@@ -62,9 +62,12 @@ public:
public:
// Sets and gets a label visible inside of a OpenGL debugger if KHR_debug is supported at runtime *and*
// if ACGL_OPENGL_DEBUGGER_SUPPORT was defined during compile time. Does nothing otherwise!
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_SHADER>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_SHADER>(getObjectName()); }
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGLES_VERSION >= 10))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_SHADER_OBJECT_EXT>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_SHADER_OBJECT_EXT>(getObjectName()); }
#else
void setObjectLabel( const std::string & ) {}
std::string getObjectLabel() { return ""; }
......
......@@ -90,9 +90,12 @@ public:
public:
// Sets and gets a label visible inside of a OpenGL debugger if KHR_debug is supported at runtime *and*
// if ACGL_OPENGL_DEBUGGER_SUPPORT was defined during compile time. Does nothing otherwise!
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_PROGRAM>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_PROGRAM>(getObjectName()); }
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGLES_VERSION >= 10))
void setObjectLabel( const std::string &_label ) { setObjectLabelT<GL_PROGRAM_OBJECT_EXT>(getObjectName(),_label); }
std::string getObjectLabel() { return getObjectLabelT<GL_PROGRAM_OBJECT_EXT>(getObjectName()); }
#else
void setObjectLabel( const std::string & ) {}
std::string getObjectLabel() { return ""; }
......
......@@ -47,6 +47,9 @@ namespace FileHelpers
*/
std::string getDeviceDependentPathFor( const std::string &resource );
// resource path is important on iOS, "" everywhere else
std::string getDeviceResourcePath();
typedef time_t FileModificationTime;
/*
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
/*
* FileHelpersiOS.h
* iOS-Test
*
*/
/***********************************************************************
* Copyright 2011-2015 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
......@@ -46,13 +46,14 @@ bool init( bool forceDebuggingContext )
//
// check OpenGL version
//
Utils::debug() << "OpenGL Version: " << OpenGL::getOpenGLMajorVersionNumber() << "." << OpenGL::getOpenGLMinorVersionNumber() << std::endl;
#ifdef ACGL_OPENGL_ES
Utils::debug() << "OpenGL ES Version: ";
unsigned int versionToTest = ACGL_OPENGLES_VERSION ;
#else
Utils::debug() << "OpenGL Version: ";
unsigned int versionToTest = ACGL_OPENGL_VERSION ;
#endif
Utils::debug() << OpenGL::getOpenGLMajorVersionNumber() << "." << OpenGL::getOpenGLMinorVersionNumber() << std::endl;
if (OpenGL::getOpenGLVersionNumber() < versionToTest) {
Utils::error() << "At compile time an OpenGL context of version " << versionToTest
......
......@@ -97,9 +97,18 @@ void ShaderParser::parse(const std::string &_filename)
//readin( "./"+path+"/"+file );
readin( _filename );
#ifndef ACGL_OPENGL_ES
if (mMaxVersion > 110) {
mSources[0] = "#version "+StringHelpers::toString(mMaxVersion)+"\n";
}
#else
#if (ACGL_OPENGLES_VERSION == 20)
mSources[0] = "#version 200 es\n";
#else
mSources[0] = "#version 300 es\n";
#endif
mSources[0] = mSources[0]+"#define ACGL_OPENGL_ES\n";
#endif
}
int ShaderParser::registerSourceFile(const std::string &_name)
......
......@@ -17,7 +17,8 @@ using namespace ACGL::Utils;
namespace ACGL{
namespace OpenGL{
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
// desktop with native support
GLDebugAnnotation::GLDebugAnnotation( const char *_message )
{
GLuint messageID = 0;
......@@ -29,6 +30,17 @@ GLDebugAnnotation::~GLDebugAnnotation()
glPopDebugGroup();
}
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (GL_EXT_debug_marker == 1))
// OpenGL ES with extension:
GLDebugAnnotation::GLDebugAnnotation( const char *_message )
{
glPushGroupMarkerEXT( 0, _message );
}
GLDebugAnnotation::~GLDebugAnnotation()
{
glPopGroupMarkerEXT();
}
#else
GLDebugAnnotation::GLDebugAnnotation( const char *_message ){}
GLDebugAnnotation::~GLDebugAnnotation(){}
......
......@@ -278,22 +278,26 @@ GLuint TextureBase::bindAndGetOldTexture() const
GLenum TextureBase::getCompatibleFormat( GLenum _internalFormat )
{
#if ((ACGL_OPENGLES_VERSION >= 30) || (ACGL_OPENGL_VERSION >= 20))
#if ((ACGL_OPENGLES_VERSION >= 20))
if ( (_internalFormat == GL_ALPHA) || (_internalFormat == GL_RGB) || (_internalFormat == GL_RGBA)
|| (_internalFormat == GL_LUMINANCE) || (_internalFormat == GL_LUMINANCE_ALPHA)) {
return _internalFormat;
} else {
ACGL::Utils::error() << "Unsupported format for ES" << std::endl;
}
#else
// Desktop OpenGL
if (_internalFormat == GL_DEPTH24_STENCIL8) {
return GL_DEPTH_STENCIL;
}
#endif
if ( _internalFormat == GL_DEPTH_COMPONENT
|| _internalFormat == GL_DEPTH_COMPONENT16
#if ((ACGL_OPENGLES_VERSION >= 30) || (ACGL_OPENGL_VERSION >= 20))
|| _internalFormat == GL_DEPTH_COMPONENT24
|| _internalFormat == GL_DEPTH_COMPONENT32F
#endif
) {
return GL_DEPTH_COMPONENT;
}
#if ((ACGL_OPENGLES_VERSION >= 30) || (ACGL_OPENGL_VERSION >= 20))
if ( _internalFormat == GL_R8I
|| _internalFormat == GL_R8UI
|| _internalFormat == GL_R16I
......@@ -328,7 +332,7 @@ GLenum TextureBase::getCompatibleFormat( GLenum _internalFormat )
GLenum TextureBase::getCompatibleType( GLenum _internalFormat )
{
#if ((ACGL_OPENGLES_VERSION >= 30) || (ACGL_OPENGL_VERSION >= 20))
#if (ACGL_OPENGL_VERSION >= 20)
if (_internalFormat == GL_DEPTH24_STENCIL8) {
return GL_UNSIGNED_INT_24_8;
}
......@@ -360,7 +364,7 @@ GLenum TextureBase::getCompatibleType( GLenum _internalFormat )
}
#endif
// not sure if this works for all formats:
return GL_BYTE;
return GL_UNSIGNED_BYTE;
}
......@@ -738,6 +742,16 @@ void TextureBase::texSubImage1D( const SharedTextureData &_data, GLint _mipmapLe
void TextureBase::texImage2D( const SharedTextureData &_data, GLint _mipmapLevel )
{
#if (ACGL_OPENGLES_VERSION >= 10)
if (mInternalFormat != _data->getFormat()) {
ACGL::Utils::error() << "On ES the internal and external formats must match, chaning internal format" << std::endl;
mInternalFormat = _data->getFormat();
}
if ((_data->getType() != GL_UNSIGNED_BYTE) && (_data->getType() != GL_UNSIGNED_SHORT_5_6_5)
&& (_data->getType() != GL_UNSIGNED_SHORT_4_4_4_4) && (_data->getType() != GL_UNSIGNED_SHORT_5_5_5_1)) {
ACGL::Utils::error() << "External type is unsupported on ES, this might fail!" << std::endl;
}
#endif
bind();
mWidth = _data->getWidth();
mHeight = _data->getHeight();
......@@ -756,6 +770,17 @@ void TextureBase::texImage2D( const SharedTextureData &_data, GLint _mipmapLevel
void TextureBase::texSubImage2D( const SharedTextureData &_data, GLint _mipmapLevel, glm::uvec2 _offset )
{
#if (ACGL_OPENGLES_VERSION >= 10)
if (mInternalFormat != _data->getFormat()) {
ACGL::Utils::error() << "On ES the internal and external formats must match, chaning internal format" << std::endl;
mInternalFormat = _data->getFormat();
}
if ((_data->getType() != GL_UNSIGNED_BYTE) && (_data->getType() != GL_UNSIGNED_SHORT_5_6_5)
&& (_data->getType() != GL_UNSIGNED_SHORT_4_4_4_4) && (_data->getType() != GL_UNSIGNED_SHORT_5_5_5_1)) {
ACGL::Utils::error() << "External type is unsupported on ES, this might fail!" << std::endl;
}
#endif
bind();
GLsizei w = std::min( mWidth, _data->getWidth() );
GLsizei h = std::max( std::min( mHeight, _data->getHeight() ), 1);
......@@ -774,6 +799,17 @@ void TextureBase::texSubImage2D( const SharedTextureData &_data, GLint _mipmapLe
#if defined (ACGL_OPENGL_SUPPORTS_TEXTURE_3D)
void TextureBase::texImage3D( const SharedTextureData &_data, GLint _mipmapLevel )
{
#if (ACGL_OPENGLES_VERSION >= 10)
if (mInternalFormat != _data->getFormat()) {
ACGL::Utils::error() << "On ES the internal and external formats must match, chaning internal format" << std::endl;
mInternalFormat = _data->getFormat();
}
if ((_data->getType() != GL_UNSIGNED_BYTE) && (_data->getType() != GL_UNSIGNED_SHORT_5_6_5)
&& (_data->getType() != GL_UNSIGNED_SHORT_4_4_4_4) && (_data->getType() != GL_UNSIGNED_SHORT_5_5_5_1)) {
ACGL::Utils::error() << "External type is unsupported on ES, this might fail!" << std::endl;
}
#endif
bind();
mWidth = _data->getWidth();
mHeight = _data->getHeight();
......@@ -793,6 +829,17 @@ void TextureBase::texImage3D( const SharedTextureData &_data, GLint _mipmapLevel
void TextureBase::texSubImage3D( const SharedTextureData &_data, GLint _mipmapLevel, glm::uvec3 _offset )
{
#if (ACGL_OPENGLES_VERSION >= 10)
if (mInternalFormat != _data->getFormat()) {
ACGL::Utils::error() << "On ES the internal and external formats must match, chaning internal format" << std::endl;
mInternalFormat = _data->getFormat();
}
if ((_data->getType() != GL_UNSIGNED_BYTE) && (_data->getType() != GL_UNSIGNED_SHORT_5_6_5)
&& (_data->getType() != GL_UNSIGNED_SHORT_4_4_4_4) && (_data->getType() != GL_UNSIGNED_SHORT_5_5_5_1)) {
ACGL::Utils::error() << "External type is unsupported on ES, this might fail!" << std::endl;
}
#endif
bind();
GLsizei w = std::min( mWidth, _data->getWidth() );
GLsizei h = std::max( std::min( mHeight, _data->getHeight() ), 1);
......
......@@ -25,7 +25,7 @@ VertexArrayObject::VertexArrayObject( GLenum _mode ) :
mAttributes.resize( maxAttributes ); // reserve probably 16 slots, the size() can now be used to query the MAX_VERTEX_ATTRIBS
}
#ifdef ACGL_OPENGL_DEBUGGER_SUPPORT
#if (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGL_VERSION >= 32))
void VertexArrayObject::setObjectLabel( const std::string &_label )
{
setObjectLabelT<GL_VERTEX_ARRAY>(getObjectName(),_label);
......@@ -35,6 +35,16 @@ std::string VertexArrayObject::getObjectLabel()
{
return getObjectLabelT<GL_VERTEX_ARRAY>(getObjectName());
}
#elif (defined(ACGL_OPENGL_DEBUGGER_SUPPORT) && (ACGL_OPENGLES_VERSION >= 10))
void VertexArrayObject::setObjectLabel( const std::string &_label )
{
setObjectLabelT<GL_VERTEX_ARRAY_OBJECT_EXT>(getObjectName(),_label);
}
std::string VertexArrayObject::getObjectLabel()
{
return getObjectLabelT<GL_VERTEX_ARRAY_OBJECT_EXT>(getObjectName());
}
#else
void VertexArrayObject::setObjectLabel( const std::string & ) {}
std::string VertexArrayObject::getObjectLabel() { return ""; }
......
......@@ -189,7 +189,7 @@ uint32_t getOpenGLVersionNumber()
bool doesSupportGeometryShader()
{
#if defined(ACGL_OPENGL_ES)
#if (ACGL_OPENGL_ES_VERSION < 32))
#if (ACGL_OPENGL_ES_VERSION < 32)
return false;
#else
return true;
......@@ -203,7 +203,7 @@ bool doesSupportGeometryShader()
bool doesSupportTessellationShader()
{
#if defined(ACGL_OPENGL_ES)
#if (ACGL_OPENGL_ES_VERSION < 32))
#if (ACGL_OPENGL_ES_VERSION < 32)
return false;
#else
return true;
......@@ -217,7 +217,7 @@ bool doesSupportTessellationShader()
bool doesSupportComputeShader()
{
#if defined(ACGL_OPENGL_ES)
#if (ACGL_OPENGL_ES_VERSION < 31))
#if (ACGL_OPENGL_ES_VERSION < 31)
return false;
#else
return true;
......
......@@ -100,6 +100,8 @@ namespace FileHelpers
{
return resource;
}
std::string getDeviceResourcePath() {return "";}
#endif
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
/*
* FileHelpersiOS.c
* iOS-Test
*
*
*/
/***********************************************************************
* Copyright 2011-2015 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#include <ACGL/Utils/FileHelpers.hh>
#import <UIKit/UIKit.h>
namespace ACGL{
namespace Utils{
namespace FileHelpers{
std::string getDeviceDependentPathFor( const std::string &resource )
{
NSString *res = [NSString stringWithFormat:@"%s", resource.c_str() ];
NSString *path = [[NSBundle mainBundle] pathForResource: res ofType: nil ];
if (path) {
return std::string( [path cStringUsingEncoding:1] );
return std::string( [path cStringUsingEncoding:1] );
}
return ""; // file not found
}
std::string getDeviceResourcePath()
{
NSString *path = [[NSBundle mainBundle] resourcePath];
return std::string( [path cStringUsingEncoding:1] )+"/";
}
}
}
}
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