Commit 5612a254 authored by Robert Menzel's avatar Robert Menzel

Android and OpenGL ES 2.0 specific changes, compiles now in NDK

parent 938376b3
......@@ -17,6 +17,8 @@
#include <vector>
#ifdef ACGL_SUPPORT_VAO
namespace ACGL{
namespace OpenGL{
......@@ -81,4 +83,6 @@ protected:
} // OpenGL
} // ACGL
#endif // #ifdef ACGL_SUPPORT_VAO
#endif // ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROL_HH
......@@ -14,6 +14,8 @@
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
#include <ACGL/OpenGL/Data/LocationMappings.hh>
#ifdef ACGL_SUPPORT_VAO
namespace ACGL{
namespace OpenGL{
......@@ -62,4 +64,6 @@ protected:
} // OpenGL
} // ACGL
#endif // #ifdef ACGL_SUPPORT_VAO
#endif // ACGL_OPENGL_CONTROLLER_VERTEXARRAYOBJECTCONTROLFILE_HH
......@@ -123,6 +123,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef ACGL_OPENGL_ES
// ES does not know 64bit ints but we need them for the Buffer class:
#include <stdint.h>
typedef int64_t GLint64;
#if (PLATFORM_IOS)
//iOS:
#if defined (ACGL_OPENGLES_VERSION_20)
......
......@@ -128,6 +128,9 @@ private:
return value;
}
#if ( !defined(ACGL_OPENGL_ES) || (ACGL_OPENGLES_VERSION >= 30))
// desktop or ES 3.0 onwards:
#if (ACGL_OPENGL_VERSION >= 32)
inline GLint64 getParameter64( GLenum _parameter ) const
{
......@@ -143,18 +146,21 @@ public:
//inline GLint64 getSize() const { return getParameter64( GL_BUFFER_SIZE ); }
inline GLint64 getMapOffset() const { return getParameter64( GL_BUFFER_MAP_OFFSET ); }
inline GLint64 getMapLength() const { return getParameter64( GL_BUFFER_MAP_LENGTH ); }
#else // OpenGL pre 3.2:
#else // OpenGL pre 3.2 or OpenGL ES 3.0:
public:
//inline GLint getSize() const { return getParameter ( GL_BUFFER_SIZE ); }
inline GLint getMapOffset() const { return getParameter ( GL_BUFFER_MAP_OFFSET ); }
inline GLint getMapLength() const { return getParameter ( GL_BUFFER_MAP_LENGTH ); }
#endif // OpenGL >= 3.2
inline GLenum getUsage() const { return (GLenum) getParameter ( GL_BUFFER_USAGE ); }
inline GLenum getAccess() const { return (GLenum) getParameter ( GL_BUFFER_ACCESS ); }
inline GLint getAccessFlags() const { return (GLint) getParameter ( GL_BUFFER_ACCESS_FLAGS ); }
inline GLboolean isMapped() const { return (GLboolean) getParameter ( GL_BUFFER_MAPPED ); }
#endif // desktop & ES 3
public:
inline GLenum getUsage() const { return (GLenum) getParameter ( GL_BUFFER_USAGE ); }
//! the size is in bytes
inline GLint64 getSize() const { return mSize; }
......@@ -200,7 +206,7 @@ public:
}
#if (ACGL_OPENGL_VERSION >= 30)
#if ((ACGL_OPENGL_VERSION >= 30) || (ACGL_OPENGLES_VERSION >= 30))
/** Map a part of the buffer to client memory
* _offset & _length are values in bytes relative to the buffer
* _access must contain one (or both) of:
......@@ -264,6 +270,7 @@ public:
#endif // OpenGL >= 3.0
#ifndef ACGL_OPENGLES_VERSION_20
//! Maps the whole buffer, if using GL 3+, better use mapRange!
//! _access is GL_READ_ONLY GL_WRITE_ONLY or GL_READ_WRITE
GLvoid *map( GLenum _target, GLenum _access ) {
......@@ -286,6 +293,7 @@ public:
inline GLboolean unmap() {
return unmap( mTarget );
}
#endif
// TODO: CopyBufferSubData
......
......@@ -13,6 +13,7 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#ifndef ACGL_OPENGLES_VERSION_20
namespace ACGL{
namespace OpenGL{
......@@ -183,4 +184,6 @@ ACGL_SMARTPOINTER_TYPEDEFS(PrimitiveQuery)
} // OpenGL
} // ACGL
#endif // ES 2.0
#endif // ACGL_OPENGL_OBJECTS_QUERY_HH
......@@ -68,6 +68,9 @@ public:
// ==================================================================================================== \/
public:
//! Get the actual number of samples
#ifdef ACGL_OPENGL_ES
inline int_t getSamples(void) const { return 1; }
#else
inline int_t getSamples(void) const
{
glBindRenderbuffer(GL_RENDERBUFFER, mObjectName);
......@@ -75,6 +78,7 @@ public:
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
return (int_t)samples;
}
#endif
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
......
......@@ -78,10 +78,13 @@ public:
inline GLenum getType (void) const { return mType; }
inline GLint getMinFilter (void) const { return mMinFilter; }
inline GLint getMagFilter (void) const { return mMagFilter; }
#ifndef ACGL_OPENGLES_VERSION_20
inline GLenum getWrapS (void) const { return mWrapS; }
inline GLenum getWrapT (void) const { return mWrapT; }
inline GLenum getWrapR (void) const { return mWrapR; }
#endif // ACGL_OPENGLES_VERSION_20
inline glm::uvec3 getSize (void) const { return glm::uvec3( mWidth, mHeight, mDepth ); }
// ===================================================================================================== \/
......@@ -142,10 +145,12 @@ public:
{
setImageData2D(_pData);
}
#ifndef ACGL_OPENGL_ES
else
{
setImageData1D(mTarget, mFormat, mType, _pData);
}
#endif
}
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(
......@@ -304,6 +309,7 @@ public:
_pData);
}
#ifndef ACGL_OPENGL_ES
//! Set data for specific area within the 3D texture
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setSubImageData3D(
......@@ -329,9 +335,12 @@ public:
mType,
_pData);
}
#endif
#ifndef ACGL_OPENGLES_VERSION_20
//! Returns a TextureData objects holding the contents of the texture
SharedTextureData getImageData(GLint _lod = 0, GLenum _type = GL_INVALID_ENUM) const;
#endif
//! Generate mipmaps from the current base texture (i.e. the texture from level 0)
//! Note: The function is not const, because it changes the corresponding GPU data
......@@ -374,6 +383,7 @@ private:
}
}
#ifndef ACGL_OPENGL_ES
//! Set texture data
inline void setImageData1D(GLenum _uploadTarget, GLenum _uploadFormat, GLenum _uploadType, const GLvoid* _pData = NULL)
{
......@@ -394,6 +404,7 @@ private:
ACGL::Utils::error() << "could not generate 1D texture!" << std::endl;
}
}
#endif
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
......
......@@ -43,6 +43,9 @@
namespace ACGL{
namespace OpenGL{
// if a VAO is present either because GL 3.0+ is present or because extensions are expected, singnal this using this define
// for classes that expect VAO to be present!
#define ACGL_SUPPORT_VAO
class VertexArrayObject
{
ACGL_NOT_COPYABLE(VertexArrayObject)
......
......@@ -30,7 +30,9 @@ inline GLint getGLTypeSize ( GLenum _type )
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);
......@@ -42,25 +44,34 @@ inline GLint getGLTypeSize ( GLenum _type )
inline GLuint getNumberOfChannels( GLenum _format )
{
if (/*_format == GL_R || */_format == GL_R8I || _format == GL_R16I || _format == GL_R32I
// GLES formats:
if (_format == GL_ALPHA || _format == GL_LUMINANCE || _format == GL_DEPTH_COMPONENT) return 1;
if (_format == GL_LUMINANCE_ALPHA) return 2;
if (_format == GL_RGB) return 3;
if (_format == GL_RGBA) return 4;
#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 /*|| _format == GL_ALPHA_INTEGER*/) 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_RGB || _format == GL_RGB8I || _format == GL_RGB16I || _format == GL_RGB32I
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_RGBA || _format == GL_RGBA8I || _format == GL_RGBA16I || _format == GL_RGBA32I
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
}
......
......@@ -19,7 +19,7 @@ namespace ACGL
bool init(void)
{
//
// init GLEW
// init GLEW or own extension loader, do nothing on ES
//
#ifdef ACGL_USE_GLEW
# ifdef ACGL_OPENGL_PROFILE_CORE
......@@ -33,7 +33,7 @@ bool init(void)
#endif
return false;
}
#else
#elif ACGL_EXTENSION_LOADER_GLLOADGEN
int loaded = ogl_LoadFunctions();
if (loaded == ogl_LOAD_FAILED)
{
......@@ -47,8 +47,14 @@ bool init(void)
//
Utils::debug() << "OpenGL Version: " << OpenGL::getOpenGLMajorVersionNumber() << "." << OpenGL::getOpenGLMinorVersionNumber() << std::endl;
if (OpenGL::getOpenGLVersionNumber() < ACGL_OPENGL_VERSION) {
Utils::error() << "At compile time an OpenGL context of version " << ACGL_OPENGL_VERSION
#ifdef ACGL_OPENGL_ES
int versionToTest = ACGL_OPENGLES_VERSION ;
#else
int versionToTest = ACGL_OPENGL_VERSION ;
#endif
if (OpenGL::getOpenGLVersionNumber() < versionToTest) {
Utils::error() << "At compile time an OpenGL context of version " << versionToTest
<< " was requested, but the current context only supports " << OpenGL::getOpenGLVersionNumber() << std::endl;
return false;
}
......
......@@ -6,8 +6,8 @@
#include <ACGL/Base/FileOperations.hh>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
using namespace ACGL;
......@@ -31,6 +31,9 @@ bool FileOperations::rawData(const std::string& _filename, char*& _pData, long_t
_size = ftell(pFile);
rewind(pFile);
#ifdef __ANDROID__
_pData = new char[_size];
#else
try
{
// allocate memory to contain the whole file:
......@@ -42,6 +45,7 @@ bool FileOperations::rawData(const std::string& _filename, char*& _pData, long_t
fclose (pFile);
return false;
}
#endif
// copy the file into the buffer:
result = fread(_pData, 1, _size, pFile);
......
......@@ -6,6 +6,8 @@
#include <ACGL/OpenGL/Controller/RenderObjectControl.hh>
#if (ACGL_OPENGL_VERSION >= 30)
using namespace ACGL::OpenGL;
SharedRenderObject RenderObjectControl::create()
......@@ -17,3 +19,5 @@ SharedRenderObject RenderObjectControl::create()
mpViewport
));
}
#endif
......@@ -15,7 +15,10 @@ SharedTexture TextureControlCubeMap::create(void)
texture->bind();
texture->setMinFilter(mMinFilter);
texture->setMagFilter(mMagFilter);
#ifndef ACGL_OPENGLES_VERSION_20
texture->setWrap(mWrapS, mWrapT, mWrapR);
#endif
if(mAnisotropicFilter > 0.0f) texture->setAnisotropicFilter(mAnisotropicFilter);
......
......@@ -77,7 +77,10 @@ SharedTexture TextureControlFile::create(void)
texture->bind();
texture->setMinFilter(mMinFilter == 0 ? GL_LINEAR_MIPMAP_LINEAR : mMinFilter);
texture->setMagFilter(mMagFilter == 0 ? GL_LINEAR : mMagFilter);
if(mWrapS > 0) texture->setWrap(mWrapS, mWrapT, mWrapR);
#ifndef ACGL_OPENGLES_VERSION_20
if(mWrapS > 0) texture->setWrap(mWrapS, mWrapT, mWrapR);
#endif
if(mAnisotropicFilter > 0.0f)
texture->setAnisotropicFilter(mAnisotropicFilter);
......
......@@ -198,7 +198,11 @@ bool TextureDataControlFilePNM::load(SharedTextureData& texture) const
texture->setDepth(1); // 2D so, depth is 1
texture->setHeight(height);
texture->setWidth(width);
#ifdef ACGL_OPENGL_ES
texture->setFormat(GL_RGB);
#else
texture->setFormat(components == 3 ? GL_RGB : GL_RED);
#endif
texture->setType(outputDataType);
return true;
......
......@@ -6,6 +6,8 @@
#include <ACGL/OpenGL/Controller/VertexArrayObjectControl.hh>
#ifdef ACGL_SUPPORT_VAO
using namespace ACGL::OpenGL;
SharedVertexArrayObject VertexArrayObjectControl::create()
......@@ -37,3 +39,5 @@ SharedVertexArrayObject VertexArrayObjectControl::create()
return vao;
}
#endif // #ifdef ACGL_SUPPORT_VAO
......@@ -7,6 +7,8 @@
#include <ACGL/OpenGL/Controller/VertexArrayObjectControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
#ifdef ACGL_SUPPORT_VAO
using namespace ACGL;
using namespace ACGL::OpenGL;
......@@ -80,3 +82,6 @@ bool VertexArrayObjectControlFile::update(SharedVertexArrayObject& vao)
updateFileModificationTime();
return true;
}
#endif // #ifdef ACGL_SUPPORT_VAO
......@@ -33,8 +33,10 @@ bool FrameBufferObject::isFrameBufferObjectComplete() const
Utils::error() << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
} else if (status == GL_FRAMEBUFFER_UNSUPPORTED) {
Utils::error() << "GL_FRAMEBUFFER_UNSUPPORTED";
#ifndef ACGL_OPENGLES_VERSION_20
} else if (status == GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
Utils::error() << "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
#endif
} else {
Utils::error() << status;
}
......@@ -87,8 +89,12 @@ bool FrameBufferObject::attachColorAttachment( const Attachment &_attachment )
{
int realLocation = -1;
GLint maxColorBuffers;
#ifdef ACGL_OPENGLES_VERSION_20
maxColorBuffers = 1;
#else
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxColorBuffers);
#endif
for (unsigned int i = 0; i < mColorAttachments.size(); ++i) {
if (mColorAttachments[i].name == _attachment.name) {
// replace this attachment
......@@ -139,7 +145,12 @@ bool FrameBufferObject::attachColorAttachment( const Attachment &_attachment )
void FrameBufferObject::remapAttachments()
{
GLint maxColorBuffers;
#ifdef ACGL_OPENGLES_VERSION_20
maxColorBuffers = 1;
#else
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxColorBuffers);
#endif
GLenum* bufferMappings = new GLenum[maxColorBuffers];
int attachments = std::min( maxColorBuffers, (int) mColorAttachments.size() );
......@@ -185,7 +196,9 @@ void FrameBufferObject::remapAttachments()
glDrawBuffers(0, (GLenum*)NULL);
#endif // __APPLE__
#ifndef ACGL_OPENGLES_VERSION_20
glDrawBuffers( maxColorBuffers, bufferMappings );
#endif
delete[] bufferMappings;
}
......@@ -228,8 +241,11 @@ SharedTextureData FrameBufferObject::getImageData(GLsizei _width, GLsizei _heigh
GLubyte* frameBufferData = new GLubyte[_width * _height * 3];
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#ifndef ACGL_OPENGLES_VERSION_20
if(_readBuffer != GL_INVALID_ENUM)
glReadBuffer(_readBuffer);
#endif
glReadPixels(_x, _y, _width, _height, GL_RGB, GL_UNSIGNED_BYTE, frameBufferData);
......
......@@ -83,6 +83,7 @@ void ShaderProgram::setAttributeLocations(ConstSharedLocationMappings _locationM
}
}
#if (ACGL_OPENGL_VERSION >= 30)
void ShaderProgram::setFragmentDataLocations(ConstSharedLocationMappings _locationMappings)
{
if (!_locationMappings) return;
......@@ -117,6 +118,7 @@ void ShaderProgram::setFragmentDataLocations(ConstSharedLocationMappings _locati
openGLRareError();
}
}
#endif // (ACGL_OPENGL_VERSION >= 30)
SharedLocationMappings ShaderProgram::getAttributeLocations() const
{
......@@ -153,6 +155,7 @@ SharedLocationMappings ShaderProgram::getAttributeLocations() const
return locationMap;
}
#if (ACGL_OPENGL_VERSION >= 30)
SharedLocationMappings ShaderProgram::getFragmentDataLocations()
{
SharedLocationMappings locationMap = SharedLocationMappings( new LocationMappings() );
......@@ -161,6 +164,7 @@ SharedLocationMappings ShaderProgram::getFragmentDataLocations()
return locationMap;
}
#endif //(ACGL_OPENGL_VERSION >= 30)
#if (ACGL_OPENGL_VERSION >= 31)
SharedLocationMappings ShaderProgram::getUniformOffsetsOfBlock( GLuint _blockIndex ) const
......
......@@ -9,6 +9,8 @@
using namespace ACGL::OpenGL;
#ifndef ACGL_OPENGLES_VERSION_20
void Texture::setWrapS( GLenum _wrapS )
{
glBindTexture(mTarget, mObjectName);
......@@ -52,6 +54,7 @@ void Texture::setWrap( GLenum _wrapS, GLenum _wrapT, GLenum _wrapR )
openGLRareError();
}
#endif // ACGL_OPENGLES_VERSION_20
void Texture::setAnisotropicFilter( GLfloat _sampleCount )
{
......@@ -75,12 +78,14 @@ void Texture::setAnisotropicFilter( GLfloat _sampleCount )
}
}
#ifndef ACGL_OPENGLES_VERSION_20
SharedTextureData Texture::getImageData(GLint _lod, GLenum _type) const
{
if(_type == GL_INVALID_ENUM) _type = mType;
// remember the previously bound texture
GLint prevTexture;
if (mTarget == GL_TEXTURE_1D) glGetIntegerv(GL_TEXTURE_BINDING_1D, &prevTexture);
else if(mTarget == GL_TEXTURE_2D) glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTexture);
else if(mTarget == GL_TEXTURE_3D) glGetIntegerv(GL_TEXTURE_BINDING_3D, &prevTexture);
......@@ -89,7 +94,6 @@ SharedTextureData Texture::getImageData(GLint _lod, GLenum _type) const
else if(mTarget == GL_TEXTURE_RECTANGLE) glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &prevTexture);
else if(mTarget == GL_TEXTURE_2D_MULTISAMPLE) glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &prevTexture);
else if(mTarget == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, &prevTexture);
// determine the required buffer size to hold the requested LOD level
bind();
GLint width, height, depth;
......@@ -118,3 +122,4 @@ SharedTextureData Texture::getImageData(GLint _lod, GLenum _type) const
return dataObject;
}
#endif // ES 2.0
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