Commit a2e5eab1 authored by Robert Menzel's avatar Robert Menzel

cleanups and added functions to get unsupported GL pointers

parent c27d804a
/***********************************************************************
* Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
* Copyright 2011-2014 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
......@@ -16,79 +16,26 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Debug.hh>
namespace ACGL{
namespace OpenGL{
//! queries some limits of the runtime which are used in ACGL internally. Client apps should not rely on these values, they are subject to changes. Gets called by ACGL::init()
void initRuntimeDependentLimits();
extern GLfloat ACGL_MAX_TEXTURE_MAX_ANISOTROPY;
//! returns the size in bytes of the common gl types named by there GLenums.
inline GLint getGLTypeSize ( GLenum _type )
{
switch(_type)
{
case GL_BYTE: return sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_FLOAT: return sizeof(GLfloat);
#ifndef ACGL_OPENGL_ES
case GL_DOUBLE: return sizeof(GLdouble);
#endif
//case GL_INT64_NV: return sizeof(GLint64);
//case GL_UNSIGNED_INT64_NV: return sizeof(GLuint64);
//case GL_HALF_FLOAT: return sizeof(GLhalf);
case GL_FIXED: return 4; // fixed are packed in a 32bit int (see 2.1.2 of the spec.)
}
return 0;
}
inline GLuint getNumberOfChannels( GLenum _format )
{
// GLES formats:
if (_format == GL_ALPHA || _format == GL_DEPTH_COMPONENT) return 1;
if (_format == GL_RGB) return 3;
if (_format == GL_RGBA) return 4;
#ifdef ACGL_OPENGL_CORE_PROFILE
// removed from core:
if (_format == GL_LUMINANCE) return 1;
if (_format == GL_LUMINANCE_ALPHA) return 2;
#endif
//! returns the size in bytes of the common gl types named by there GLenums (GL_BYTE, GL_UNSIGNED_INT etc.)
//! returns 0 for unknown types, so be careful ;-)
GLint getGLTypeSize ( GLenum _type );
#ifndef ACGL_OPENGL_ES
// additional desktop formats:
if ( _format == GL_R8I || _format == GL_R16I || _format == GL_R32I
|| _format == GL_R8UI || _format == GL_R16UI || _format == GL_R32UI
|| _format == GL_R16F || _format == GL_R32F ) return 1;
if (_format == GL_RED_INTEGER || _format == GL_GREEN_INTEGER || _format == GL_BLUE_INTEGER ) return 1;
if (_format == GL_RG || _format == GL_RG8I || _format == GL_RG16I || _format == GL_RG32I
|| _format == GL_RG8UI || _format == GL_RG16UI || _format == GL_RG32UI
|| _format == GL_RG16F || _format == GL_RG32F ) return 2;
if (_format == GL_RG_INTEGER ) return 2;
if (_format == GL_RGB8I || _format == GL_RGB16I || _format == GL_RGB32I
|| _format == GL_RGB8UI || _format == GL_RGB16UI || _format == GL_RGB32UI
|| _format == GL_RGB16F || _format == GL_RGB32F ) return 3;
if (_format == GL_BGR || _format == GL_RGB_INTEGER || _format == GL_BGR_INTEGER) return 3;
if ( _format == GL_RGBA8I || _format == GL_RGBA16I || _format == GL_RGBA32I
|| _format == GL_RGBA8UI || _format == GL_RGBA16UI || _format == GL_RGBA32UI
|| _format == GL_RGBA16F || _format == GL_RGBA32F ) return 4;
if (_format == GL_BGRA || _format == GL_RGBA_INTEGER || _format == GL_BGRA_INTEGER) return 4;
#endif
return 1; // unknown number of channels, assume 1
}
//! returns the number of channels (1,2,3 or 4) for a GL format (e.g. GL_RGB, GL_RGB_INTEGER)
//! returns 1 for unknown formats
GLuint getNumberOfChannels( GLenum _format );
//! OpenGL X.Y -> returns Y
uint32_t getOpenGLMinorVersionNumber();
//! OpenGL X.Y -> returns X
uint32_t getOpenGLMajorVersionNumber();
// returns the combined version number as 10*major + minor for easy comparing
//! returns the combined version number as 10*major + minor for easy comparing
//! OpenGL X.Y -> returns XY
uint32_t getOpenGLVersionNumber();
// query support for specific shader stages:
......@@ -96,6 +43,36 @@ bool doesSupportGeometryShader();
bool doesSupportTessellationShader();
bool doesSupportComputeShader();
#if (ACGL_OPENGL_VERSION >= 30)
//! Test if a given extension is supported. Note that features which were added to
//! OpenGL itself are not required to get also supported as extensions (sometimes there
//! are minor differences and at least the names of the functions end enums are different).
//!
//! Note that this function is slow and should only be used at initialisation! It does not rely on
//! prefetched extension lists from the function loader (glLoadGen, GLEW etc) which has to be known
//! at compile time but calls the GL functions and thus can detect new extensions.
bool doesSupportExtension( const char *_extensionName );
#endif
#if defined(ACGL_EXTENSION_LOADER_GLLOADGEN)
//! Can load an OpenGL function pointer and is only needed for extensions which are not supported by
//! the extension loader ACGL was compiled with. It is based on the OS specific loader from glLoadGen
//! and thus only works if ACGL was compiled with it. This is also why the implementation is located
//! in gl_select.cc !
void *loadOpenGLFunctionPointer( const char *_name);
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///
/// Mostly internally used functions:
///
///////////////////////////////////////////////////////////////////////////////////////////////////
/// ///////////////////////////////////////////////////////////////////////////////////////////////
//! queries some limits of the runtime which are used in ACGL internally. Client apps should not rely on these values, they are subject to changes. Gets called by ACGL::init()
void initRuntimeDependentLimits();
extern GLfloat ACGL_MAX_TEXTURE_MAX_ANISOTROPY;
// Define the shader kinds for older and embedded GL versions so the file extension detection
// can work correctly.
......@@ -139,6 +116,14 @@ GLenum getShaderTypeByFileEnding( const std::string _fileName, bool _ignoreUnsup
// looks up the enum and gives a human readable version
const GLubyte* acglShaderTypeString( GLenum _shaderType );
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///
/// Error checking, mostly for internal use.
///
///////////////////////////////////////////////////////////////////////////////////////////////////
/// ///////////////////////////////////////////////////////////////////////////////////////////////
// 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
// (read: iOS)
......
......@@ -15,6 +15,24 @@ using namespace std;
namespace ACGL{
namespace OpenGL{
#if (ACGL_OPENGL_VERSION >= 30)
bool doesSupportExtension( const char *_extensionName )
{
// move beginning of the extension string by 3 chars if the requested extension name does not include the mandatory "GL_"
// move by 0 (don't move) otherwise:
size_t pointerOffset = (strncmp(_extensionName, "GL_", 3) == 0)?0:3;
GLint n = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
for (GLint i = 0; i < n; i++)
{
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
extension += pointerOffset;
if (strcmp(extension, _extensionName) == 0) return true;
}
return false;
}
#endif
GLfloat ACGL_MAX_TEXTURE_MAX_ANISOTROPY = -1.0f;
void initRuntimeDependentLimits()
{
......@@ -25,6 +43,68 @@ void initRuntimeDependentLimits()
}
}
//! returns the size in bytes of the common gl types named by there GLenums.
GLint getGLTypeSize ( GLenum _type )
{
switch(_type)
{
case GL_BYTE: return sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_FLOAT: return sizeof(GLfloat);
#ifndef ACGL_OPENGL_ES
case GL_DOUBLE: return sizeof(GLdouble);
#endif
//case GL_INT64_NV: return sizeof(GLint64);
//case GL_UNSIGNED_INT64_NV: return sizeof(GLuint64);
//case GL_HALF_FLOAT: return sizeof(GLhalf);
case GL_FIXED: return 4; // fixed are packed in a 32bit int (see 2.1.2 of the spec.)
}
return 0;
}
GLuint getNumberOfChannels( GLenum _format )
{
// GLES formats:
if (_format == GL_ALPHA || _format == GL_DEPTH_COMPONENT) return 1;
if (_format == GL_RGB) return 3;
if (_format == GL_RGBA) return 4;
#ifdef ACGL_OPENGL_CORE_PROFILE
// removed from core:
if (_format == GL_LUMINANCE) return 1;
if (_format == GL_LUMINANCE_ALPHA) return 2;
#endif
#ifndef ACGL_OPENGL_ES
// additional desktop formats:
if ( _format == GL_R8I || _format == GL_R16I || _format == GL_R32I
|| _format == GL_R8UI || _format == GL_R16UI || _format == GL_R32UI
|| _format == GL_R16F || _format == GL_R32F ) return 1;
if (_format == GL_RED_INTEGER || _format == GL_GREEN_INTEGER || _format == GL_BLUE_INTEGER ) return 1;
if (_format == GL_RG || _format == GL_RG8I || _format == GL_RG16I || _format == GL_RG32I
|| _format == GL_RG8UI || _format == GL_RG16UI || _format == GL_RG32UI
|| _format == GL_RG16F || _format == GL_RG32F ) return 2;
if (_format == GL_RG_INTEGER ) return 2;
if (_format == GL_RGB8I || _format == GL_RGB16I || _format == GL_RGB32I
|| _format == GL_RGB8UI || _format == GL_RGB16UI || _format == GL_RGB32UI
|| _format == GL_RGB16F || _format == GL_RGB32F ) return 3;
if (_format == GL_BGR || _format == GL_RGB_INTEGER || _format == GL_BGR_INTEGER) return 3;
if ( _format == GL_RGBA8I || _format == GL_RGBA16I || _format == GL_RGBA32I
|| _format == GL_RGBA8UI || _format == GL_RGBA16UI || _format == GL_RGBA32UI
|| _format == GL_RGBA16F || _format == GL_RGBA32F ) return 4;
if (_format == GL_BGRA || _format == GL_RGBA_INTEGER || _format == GL_BGRA_INTEGER) return 4;
#endif
return 1; // unknown number of channels, assume 1
}
//
// This is a "private" function that should not be called from outside of this file.
//
......
......@@ -65,4 +65,15 @@ using namespace std;
#pragma GCC diagnostic pop
#endif
namespace ACGL{
namespace OpenGL{
void *loadOpenGLFunctionPointer( const char *_name) {
// IntGetProcAddress is a define which was defined in one of the *.inc files from glLoadGen
return (void*) IntGetProcAddress( _name );
}
} // namespace
} // namespace
#endif // ACGL_EXTENSION_LOADER_GLLOADGEN
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