From b93beb94bac52ef2fe43ee61e6ecead5e0304b30 Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Sun, 6 Sep 2015 23:06:35 +0200 Subject: [PATCH 01/12] Enable new functionality of GL ES 2/3/3.1 via ifdefs --- libs/openFrameworks/gl/ofBufferObject.cpp | 4 +++- libs/openFrameworks/gl/ofBufferObject.h | 15 ++++++++------ .../gl/ofGLProgrammableRenderer.cpp | 8 +++----- libs/openFrameworks/gl/ofGLUtils.h | 20 +++++++++++-------- libs/openFrameworks/gl/ofShader.cpp | 6 +++--- libs/openFrameworks/gl/ofShader.h | 4 ++-- libs/openFrameworks/gl/ofTexture.cpp | 2 +- libs/openFrameworks/gl/ofTexture.h | 4 +++- libs/openFrameworks/utils/ofConstants.h | 7 +++++++ 9 files changed, 43 insertions(+), 27 deletions(-) diff --git a/libs/openFrameworks/gl/ofBufferObject.cpp b/libs/openFrameworks/gl/ofBufferObject.cpp index a4511eb0aa5..bf6309de0b4 100644 --- a/libs/openFrameworks/gl/ofBufferObject.cpp +++ b/libs/openFrameworks/gl/ofBufferObject.cpp @@ -70,7 +70,7 @@ void ofBufferObject::unbind(GLenum target) const{ glBindBuffer(target, 0); } -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) void ofBufferObject::bindBase(GLenum target,GLuint index) const{ if(data){ glBindBufferBase(target,index,data->id); @@ -152,7 +152,9 @@ void * ofBufferObject::map(GLenum access){ } return glMapBuffer(data->lastTarget,access); } +#endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) void ofBufferObject::unmap(){ if(!this->data) return; diff --git a/libs/openFrameworks/gl/ofBufferObject.h b/libs/openFrameworks/gl/ofBufferObject.h index 0e3900c220d..ff4bc702fb4 100644 --- a/libs/openFrameworks/gl/ofBufferObject.h +++ b/libs/openFrameworks/gl/ofBufferObject.h @@ -38,7 +38,7 @@ class ofBufferObject { /// binds the passed target to buffer 0 void unbind(GLenum target) const; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) /// glBindBufferBase: https://www.opengl.org/sdk/docs/man4/html/glBindBufferBase.xhtml void bindBase(GLenum target,GLuint index) const; @@ -91,18 +91,21 @@ class ofBufferObject { /// for this buffer and mapping that target void * map(GLenum access); - /// glUnmapNamedBuffer: https://www.opengl.org/sdk/docs/man4/html/glUnmapBuffer.xhtml - /// before GL 4.5 emulates glUnmapNamedBuffer by unmapping and unbinding - /// the last known target for this buffer - void unmap(); - /// typed version of map, returns an array of T when used like: /// buffer.map(access) template T * map(GLenum access){ return static_cast(map(access)); } + +#endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) + /// glUnmapNamedBuffer: https://www.opengl.org/sdk/docs/man4/html/glUnmapBuffer.xhtml + /// before GL 4.5 emulates glUnmapNamedBuffer by unmapping and unbinding + /// the last known target for this buffer + void unmap(); + /// glMapNamedBufferRange: https://www.opengl.org/sdk/docs/man4/html/glMapBufferRange.xhtml /// before GL 4.5 emulates glMapNamedBufferRange by binding to last known target /// for this buffer and mapping that target diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp index b4c1cb26b7e..55091a66e9d 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp @@ -435,7 +435,7 @@ void ofGLProgrammableRenderer::drawElements(const ofVbo & vbo, GLuint drawMode, if(vbo.getUsingVerts()) { vbo.bind(); const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); -#ifdef TARGET_OPENGLES +#if defined(TARGET_OPENGLES) && !defined(GL_ES_VERSION_2_0) glDrawElements(drawMode, amt, GL_UNSIGNED_SHORT, nullptr); #else glDrawElements(drawMode, amt, GL_UNSIGNED_INT, nullptr); @@ -449,9 +449,7 @@ void ofGLProgrammableRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, if(vbo.getUsingVerts()) { vbo.bind(); const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); -#ifdef TARGET_OPENGLES - // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 - // unfortunately there is currently no easy way within oF to query the current OpenGL version. +#if defined(TARGET_OPENGLES) && !defined(GL_ES_VERSION_3_0) // https://www.khronos.org/opengles/sdk/docs/man3/xhtml/glDrawElementsInstanced.xml ofLogWarning("ofVbo") << "drawInstanced(): hardware instancing is not supported on OpenGL ES < 3.0"; // glDrawArraysInstanced(drawMode, first, total, primCount); @@ -467,7 +465,7 @@ void ofGLProgrammableRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint d if(vbo.getUsingVerts()) { vbo.bind(); const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); -#ifdef TARGET_OPENGLES +#if defined(TARGET_OPENGLES) && !defined(GL_ES_VERSION_3_0) // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 // unfortunately there is currently no easy way within oF to query the current OpenGL version. // https://www.khronos.org/opengles/sdk/docs/man3/xhtml/glDrawElementsInstanced.xml diff --git a/libs/openFrameworks/gl/ofGLUtils.h b/libs/openFrameworks/gl/ofGLUtils.h index 4c5939096c7..0c6e028c3e7 100644 --- a/libs/openFrameworks/gl/ofGLUtils.h +++ b/libs/openFrameworks/gl/ofGLUtils.h @@ -131,14 +131,18 @@ string ofGLSLVersionFromGL(int major, int minor); #endif #endif - #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES - #define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES - - #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES - #define GL_DEPTH_STENCIL GL_DEPTH24_STENCIL8_OES - #define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES - #ifdef GL_DEPTH_COMPONENT32_OES - #define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES + #ifndef GL_UNSIGNED_INT_24_8 + #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES + #define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES + #endif + + #ifndef GL_DEPTH24_STENCIL8 + #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES + #define GL_DEPTH_STENCIL GL_DEPTH24_STENCIL8_OES + #define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES + #ifdef GL_DEPTH_COMPONENT32_OES + #define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES + #endif #endif #ifdef TARGET_OPENGLES #ifndef GL_UNSIGNED_INT diff --git a/libs/openFrameworks/gl/ofShader.cpp b/libs/openFrameworks/gl/ofShader.cpp index 47a77fb590f..b7a8f96bcd8 100644 --- a/libs/openFrameworks/gl/ofShader.cpp +++ b/libs/openFrameworks/gl/ofShader.cpp @@ -541,7 +541,7 @@ void ofShader::end() const{ ofGetGLRenderer()->unbind(*this); } -#if !defined(TARGET_OPENGLES) && defined(glDispatchCompute) +#ifdef GL_COMPUTE_SHADER //-------------------------------------------------------------- void ofShader::dispatchCompute(GLuint x, GLuint y, GLuint z) const{ glDispatchCompute(x,y,z); @@ -989,10 +989,10 @@ string ofShader::nameForType(GLenum type){ case GL_FRAGMENT_SHADER: return "GL_FRAGMENT_SHADER"; #ifndef TARGET_OPENGLES case GL_GEOMETRY_SHADER_EXT: return "GL_GEOMETRY_SHADER_EXT"; - #ifdef glDispatchCompute + #endif + #if (!defined(TARGET_OPENGLES) && defined(glDispatchCompute)) || defined(GL_ES_VERSION_3_1) case GL_COMPUTE_SHADER: return "GL_COMPUTE_SHADER"; #endif - #endif default: return "UNKNOWN SHADER TYPE"; } } diff --git a/libs/openFrameworks/gl/ofShader.h b/libs/openFrameworks/gl/ofShader.h index 6b9fa8c05d7..729d6cc699a 100644 --- a/libs/openFrameworks/gl/ofShader.h +++ b/libs/openFrameworks/gl/ofShader.h @@ -44,8 +44,8 @@ class ofShader { void begin() const; void end() const; - -#if !defined(TARGET_OPENGLES) && defined(glDispatchCompute) + +#ifdef GL_COMPUTE_SHADER void dispatchCompute(GLuint x, GLuint y, GLuint z) const; #endif diff --git a/libs/openFrameworks/gl/ofTexture.cpp b/libs/openFrameworks/gl/ofTexture.cpp index d91f1940f0b..54c00a31248 100644 --- a/libs/openFrameworks/gl/ofTexture.cpp +++ b/libs/openFrameworks/gl/ofTexture.cpp @@ -716,7 +716,7 @@ void ofTexture::unbind(int textureLocation) const{ ofGetGLRenderer()->unbind(*this,textureLocation); } -#if !defined(TARGET_OPENGLES) && defined(glBindImageTexture) +#if (!defined(TARGET_OPENGLES) && defined(glBindImageTexture)) || defined(GL_ES_VERSION_3_1) //---------------------------------------------------------- void ofTexture::bindAsImage(GLuint unit, GLenum access, GLint level, GLboolean layered, GLint layer){ glBindImageTexture(unit,texData.textureID,level,layered,layer,access,texData.glInternalFormat); diff --git a/libs/openFrameworks/gl/ofTexture.h b/libs/openFrameworks/gl/ofTexture.h index 1acb71cbdf2..afad06ca794 100644 --- a/libs/openFrameworks/gl/ofTexture.h +++ b/libs/openFrameworks/gl/ofTexture.h @@ -681,7 +681,9 @@ class ofTexture : public ofBaseDraws { /// void unbind(int textureLocation=0) const; -#if !defined(TARGET_OPENGLES) && defined(glBindImageTexture) + // note: defined(someMethod) doesn't actually always work + // there is no reliable way to check for a function being defined just with the preprocessor +#if (!defined(TARGET_OPENGLES) && defined(glBindImageTexture)) || defined(GL_ES_VERSION_3_1) /// Calls glBindImageTexture on the texture /// /// Binds the texture as an read or write image, only available since OpenGL 4.2 diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index c53e31666e8..953714c4bdc 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -209,12 +209,19 @@ enum ofTargetPlatform{ #ifdef TARGET_ANDROID #include #include + #include #define GL_GLEXT_PROTOTYPES #include + // we have to include the GLES 3 headers first since gl2.h and gl3.h are incompatible due to glShaderSource + #include "GLES3/gl3.h" + #include "GLES3/gl31.h" // only works on Android-21+ + #include "GLES3/gl3ext.h" +#ifndef __gl3_h_ #include #include +#endif #define TARGET_LITTLE_ENDIAN #endif From f6a4550a467cec5e30015c0118424ffae24be8ce Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Sun, 6 Sep 2015 23:26:29 +0200 Subject: [PATCH 02/12] Android Studio 1.3/1.4 compatibility, and a fix. --- libs/openFrameworks/utils/ofConstants.h | 8 +++++--- libs/openFrameworksCompiled/project/android/build.gradle | 2 +- .../project/android/gradle.properties | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 libs/openFrameworksCompiled/project/android/gradle.properties diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index 953714c4bdc..c607750d634 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -215,9 +215,11 @@ enum ofTargetPlatform{ #include // we have to include the GLES 3 headers first since gl2.h and gl3.h are incompatible due to glShaderSource - #include "GLES3/gl3.h" - #include "GLES3/gl31.h" // only works on Android-21+ - #include "GLES3/gl3ext.h" + #if __ANDROID_API__ >= 21 + #include "GLES3/gl3.h" + #include "GLES3/gl31.h" // only works on Android-21+ + #include "GLES3/gl3ext.h" + #endif #ifndef __gl3_h_ #include #include diff --git a/libs/openFrameworksCompiled/project/android/build.gradle b/libs/openFrameworksCompiled/project/android/build.gradle index 75f898dc1ce..a84a6b28538 100644 --- a/libs/openFrameworksCompiled/project/android/build.gradle +++ b/libs/openFrameworksCompiled/project/android/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.1' + classpath 'com.android.tools.build:gradle:1.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/libs/openFrameworksCompiled/project/android/gradle.properties b/libs/openFrameworksCompiled/project/android/gradle.properties new file mode 100644 index 00000000000..d72861d28d9 --- /dev/null +++ b/libs/openFrameworksCompiled/project/android/gradle.properties @@ -0,0 +1 @@ +android.useDeprecatedNdk=true \ No newline at end of file From a1c6f72926032bde184a4c5a111b525a1e9648b2 Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Tue, 8 Sep 2015 22:22:57 +0200 Subject: [PATCH 03/12] Get an OpenGL ES 3.1 context if possible. --- .../cc/openframeworks/OFAndroidWindow.java | 17 ++++--- addons/ofxAndroid/src/ofAppAndroidWindow.cpp | 50 +++++++++++++------ libs/openFrameworks/app/ofAppRunner.cpp | 14 +++++- libs/openFrameworks/app/ofWindowSettings.h | 31 +++++++----- .../gl/ofGLProgrammableRenderer.cpp | 23 ++++++++- libs/openFrameworks/gl/ofGLRenderer.cpp | 7 ++- libs/openFrameworks/gl/ofGLUtils.cpp | 11 +++- libs/openFrameworks/gl/ofMaterial.cpp | 2 + libs/openFrameworks/gl/ofTexture.cpp | 6 ++- libs/openFrameworks/graphics/ofGraphics.cpp | 10 ++-- libs/openFrameworks/utils/ofConstants.h | 23 ++++++--- .../project/android/config.android.default.mk | 3 +- 12 files changed, 142 insertions(+), 55 deletions(-) diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java index 21fc1e6a4c5..2f891d1f5f9 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java @@ -22,15 +22,19 @@ public OFEGLConfigChooser(int r, int g, int b, int a, int depth, int stencil) { mAlphaSize = a; mDepthSize = depth; mStencilSize = stencil; + mGLESVersion = 0; } public static void setGLESVersion(int version){ if(version==1) EGL_OPENGL_ES_BIT=1; - else EGL_OPENGL_ES_BIT=4; + else EGL_OPENGL_ES_BIT=4; // == EGL_OPENGL_ES2_BIT + mGLESVersion = version; } public static int getGLESVersion(){ - return EGL_OPENGL_ES_BIT==1?1:2; + if(mGLESVersion == 0) + throw new IllegalStateException("You need to set the GLES version!"); + return mGLESVersion; } /* This EGL config specification is used to specify 1.x rendering. @@ -213,6 +217,7 @@ private void printConfig(EGL10 egl, EGLDisplay display, protected int mAlphaSize; protected int mDepthSize; protected int mStencilSize; + protected static int mGLESVersion; private int[] mValue = new int[1]; } @@ -220,9 +225,7 @@ class OFGLSurfaceView extends GLSurfaceView{ public OFGLSurfaceView(Context context) { super(context); mRenderer = new OFAndroidWindow(getWidth(),getHeight()); - if(OFEGLConfigChooser.getGLESVersion()==2){ - setEGLContextClientVersion(2); - } + setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersion()); getHolder().setFormat( PixelFormat.OPAQUE ); OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0); setEGLConfigChooser(configChooser); @@ -232,9 +235,7 @@ public OFGLSurfaceView(Context context) { public OFGLSurfaceView(Context context,AttributeSet attributes) { super(context,attributes); mRenderer = new OFAndroidWindow(getWidth(),getHeight()); - if(OFEGLConfigChooser.getGLESVersion()==2){ - setEGLContextClientVersion(2); - } + setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersion()); getHolder().setFormat( PixelFormat.OPAQUE ); OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0); setEGLConfigChooser(configChooser); diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index c734fe6aa3d..0c827b44538 100644 --- a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp +++ b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp @@ -43,6 +43,9 @@ static bool threadedTouchEvents = false; static bool appSetup = false; static bool accumulateTouchEvents = false; +static int sGLESVersionMajor = 2; +static int sGLESVersionMinor = 0; + void ofExitCallback(); @@ -100,9 +103,21 @@ jobject ofGetOFActivityObject(){ ofAppAndroidWindow::ofAppAndroidWindow() -:currentRenderer(new ofGLRenderer(this)) -,glesVersion(1){ - window = this; +#ifdef TARGET_PROGRAMMABLE_GL + :currentRenderer(new ofGLProgrammableRenderer(this)) { + #ifdef GL_ES_VERSION_3_0 + sGLESVersionMajor = 3; + #ifdef GL_ES_VERSION_3_1 + sGLESVersionMinor = 1; + #endif + #else + sGLESVersionMajor = 2; + #endif +#else + :currentRenderer(new ofGLRenderer(this)) { + sGLESVersionMajor = 1; +#endif + window = this; } @@ -111,13 +126,15 @@ ofAppAndroidWindow::~ofAppAndroidWindow() { } void ofAppAndroidWindow::setup(const ofGLESWindowSettings & settings){ - glesVersion = settings.glesVersion; - ofLogError() << "setup gles" << glesVersion; - if(glesVersion<2){ + sGLESVersionMajor = settings.glesVersionMajor(); + sGLESVersionMinor = settings.glesVersionMinor(); + ofLogError() << "setup gles" << sGLESVersionMajor << "." << sGLESVersionMinor; +#ifndef TARGET_PROGRAMMABLE_GL + if(sGLESVersionMajor<2){ currentRenderer = make_shared(this); - }else{ + }else +#endif currentRenderer = make_shared(this); - } jclass javaClass = ofGetJNIEnv()->FindClass("cc/openframeworks/OFAndroid"); @@ -132,13 +149,12 @@ void ofAppAndroidWindow::setup(const ofGLESWindowSettings & settings){ return; } - ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,glesVersion); + ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,sGLESVersionMajor); - if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){ - static_cast(currentRenderer.get())->setup(settings.glesVersion,0); - }else{ - static_cast(currentRenderer.get())->setup(); - } + // note: we used to call renderer->setup here, but this is both wrong + // (because we most likely don't yet have a working GLES context) + // and superfluous, because we call setup in onSurfaceCreated + // (where the context exists, by definition) } void ofAppAndroidWindow::update(){ @@ -306,11 +322,15 @@ Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv* env, jclass thiz ){ ofPopStyle(); surfaceDestroyed = false; }else{ +#ifndef TARGET_PROGRAMMABLE_GL if(window->renderer()->getType()==ofGLProgrammableRenderer::TYPE){ - static_cast(window->renderer().get())->setup(2,0); +#endif + static_cast(window->renderer().get())->setup(sGLESVersionMajor,sGLESVersionMinor); +#ifndef TARGET_PROGRAMMABLE_GL }else{ static_cast(window->renderer().get())->setup(); } +#endif ofLogNotice() << "renderer created"; } } diff --git a/libs/openFrameworks/app/ofAppRunner.cpp b/libs/openFrameworks/app/ofAppRunner.cpp index 805e5bd00a9..faa7996c7d2 100644 --- a/libs/openFrameworks/app/ofAppRunner.cpp +++ b/libs/openFrameworks/app/ofAppRunner.cpp @@ -165,7 +165,19 @@ int ofRunMainLoop(){ void ofSetupOpenGL(int w, int h, ofWindowMode screenMode){ #ifdef TARGET_OPENGLES ofGLESWindowSettings settings; - settings.glesVersion = 1; + #ifdef GL_ES_VERSION_3_0 + #ifdef GL_ES_VERSION_3_1 + settings.setGLESVersion(3,1); + #else + settings.setGLESVersion(3,0); + #endif + #else + #ifdef GL_ES_VERSION_2_0 + settings.setGLESVersion(2); + #else + settings.setGLESVersion(1); + #endif + #endif #else ofGLWindowSettings settings; settings.glVersionMajor = 2; diff --git a/libs/openFrameworks/app/ofWindowSettings.h b/libs/openFrameworks/app/ofWindowSettings.h index fdb68e8a38c..ed5a3547104 100644 --- a/libs/openFrameworks/app/ofWindowSettings.h +++ b/libs/openFrameworks/app/ofWindowSettings.h @@ -63,22 +63,29 @@ class ofGLWindowSettings: public ofWindowSettings{ class ofGLESWindowSettings: public ofWindowSettings{ public: - ofGLESWindowSettings() - :glesVersion(1){} - - ofGLESWindowSettings(const ofWindowSettings & settings) - :ofWindowSettings(settings), glesVersion(1) { + ofGLESWindowSettings() + :mGlesVersionMajor(1), mGlesVersionMinor(0){} + + ofGLESWindowSettings(const ofWindowSettings & settings) + :ofWindowSettings(settings), mGlesVersionMajor(1), mGlesVersionMinor(0) { const ofGLESWindowSettings * glesSettings = dynamic_cast(&settings); if(glesSettings){ - glesVersion = glesSettings->glesVersion; + mGlesVersionMajor = glesSettings->mGlesVersionMajor; + mGlesVersionMinor = glesSettings->mGlesVersionMinor; } } + + virtual ~ofGLESWindowSettings(){}; + + void setGLESVersion(int versionMajor, int versionMinor = 0){ + mGlesVersionMajor = versionMajor; + mGlesVersionMinor = versionMinor; + } - virtual ~ofGLESWindowSettings(){}; - - void setGLESVersion(int version){ - glesVersion = version; - } + int glesVersionMajor() const { return mGlesVersionMajor; } + int glesVersionMinor() const { return mGlesVersionMinor ; } - int glesVersion; +private: + int mGlesVersionMajor; + int mGlesVersionMinor; }; diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp index 55091a66e9d..e14733c3e1f 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp @@ -466,8 +466,6 @@ void ofGLProgrammableRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint d vbo.bind(); const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); #if defined(TARGET_OPENGLES) && !defined(GL_ES_VERSION_3_0) - // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 - // unfortunately there is currently no easy way within oF to query the current OpenGL version. // https://www.khronos.org/opengles/sdk/docs/man3/xhtml/glDrawElementsInstanced.xml ofLogWarning("ofVbo") << "drawElementsInstanced(): hardware instancing is not supported on OpenGL ES < 3.0"; // glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_SHORT, nullptr, primCount); @@ -1794,19 +1792,40 @@ void ofGLProgrammableRenderer::drawString(const ofTrueTypeFont & font, string te // http://www.opengl.org/registry/doc/GLSLangSpec.1.50.09.pdf #ifdef TARGET_OPENGLES +#ifdef GL_ES_VERSION_3_0 static const string vertex_shader_header = + "#version %glsl_version% es\n" + "precision mediump float;\n" + "#define IN in\n" + "#define OUT out\n" + "#define TEXTURE texture\n" + "#define TARGET_OPENGLES\n"; +static const string fragment_shader_header = + "#version %glsl_version% es\n" + "precision mediump float;\n" + "#define IN in\n" + "#define OUT out\n" + "#define TEXTURE texture\n" + "#define FRAG_COLOR outputColor\n" + "#define TARGET_OPENGLES\n" + "out vec4 outputColor;\n"; +#else // GLSL ES 100 +static const string vertex_shader_header = + "#version %glsl_version%\n" "precision mediump float;\n" "#define IN attribute\n" "#define OUT varying\n" "#define TEXTURE texture2D\n" "#define TARGET_OPENGLES\n"; static const string fragment_shader_header = + "#version %glsl_version%\n" "precision mediump float;\n" "#define IN varying\n" "#define OUT\n" "#define TEXTURE texture2D\n" "#define FRAG_COLOR gl_FragColor\n" "#define TARGET_OPENGLES\n"; +#endif #else static const string vertex_shader_header = "#version %glsl_version%\n" diff --git a/libs/openFrameworks/gl/ofGLRenderer.cpp b/libs/openFrameworks/gl/ofGLRenderer.cpp index df7b2fdb96a..8785c9a28f2 100644 --- a/libs/openFrameworks/gl/ofGLRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLRenderer.cpp @@ -15,6 +15,7 @@ const string ofGLRenderer::TYPE="GL"; +#if !defined(TARGET_OPENGLES) || !defined(TARGET_PROGRAMMABLE_GL) //---------------------------------------------------------- ofGLRenderer::ofGLRenderer(const ofAppBaseWindow * _window) :matrixStack(_window) @@ -129,7 +130,8 @@ void ofGLRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode renderType, glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); -#else +#else // note: basically, you can't use the standard ofGLRenderer with GLES and TARGET_PROGRAMMABLE_GL (and why should you?) + #ifndef TARGET_PROGRAMMABLE_GL if(vertexData.getNumVertices()){ glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), vertexData.getVerticesPointer()); @@ -190,6 +192,7 @@ void ofGLRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode renderType, if(vertexData.getNumTexCoords() && useTextures){ glDisableClientState(GL_TEXTURE_COORD_ARRAY); } + #endif #endif if (currentStyle.smoothing) const_cast(this)->endSmoothing(); } @@ -1943,3 +1946,5 @@ const of3dGraphics & ofGLRenderer::get3dGraphics() const{ of3dGraphics & ofGLRenderer::get3dGraphics(){ return graphics3d; } + +#endif \ No newline at end of file diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp index 2ce901e6ca4..e11116425d4 100644 --- a/libs/openFrameworks/gl/ofGLUtils.cpp +++ b/libs/openFrameworks/gl/ofGLUtils.cpp @@ -495,7 +495,7 @@ int ofGetGLInternalFormatFromPixelFormat(ofPixelFormat pixelFormat){ return GL_RGB; #endif case OF_PIXELS_RGB565: - #if defined(TARGET_ANDROID) || defined(TARGET_RASPBERRY_PI) + #if (defined(TARGET_ANDROID) || defined(TARGET_RASPBERRY_PI)) && defined(GL_RGB565_OES) return GL_RGB565_OES; #elif defined(GL_RGB565) return GL_RGB565; @@ -730,7 +730,14 @@ bool ofGLSupportsNPOTTextures(){ string ofGLSLVersionFromGL(int major, int minor){ #ifdef TARGET_OPENGLES - return "ES1"; + if(major == 1) { + return "ES1"; // ??? + } + else if(major == 2) { + return "100"; // yes + }else { // if(major == 3){ + return ofToString(major*100+minor*10); + } #else switch(major){ case 3: diff --git a/libs/openFrameworks/gl/ofMaterial.cpp b/libs/openFrameworks/gl/ofMaterial.cpp index ef3be0dccff..8eb3cfabb26 100644 --- a/libs/openFrameworks/gl/ofMaterial.cpp +++ b/libs/openFrameworks/gl/ofMaterial.cpp @@ -102,6 +102,7 @@ void ofMaterial::initShaders(ofGLProgrammableRenderer & renderer) const{ string vertex2DHeader = renderer.defaultVertexShaderHeader(GL_TEXTURE_2D); string fragment2DHeader = renderer.defaultFragmentShaderHeader(GL_TEXTURE_2D); shaderLights = ofLightsData().size(); +#ifdef TARGET_PROGRAMMABLE_GL shaderNoTexture.setupShaderFromSource(GL_VERTEX_SHADER,vertexSource(vertex2DHeader,shaderLights,false)); shaderNoTexture.setupShaderFromSource(GL_FRAGMENT_SHADER,fragmentSource(fragment2DHeader,shaderLights,false)); shaderNoTexture.bindDefaults(); @@ -111,6 +112,7 @@ void ofMaterial::initShaders(ofGLProgrammableRenderer & renderer) const{ shaderTexture2D.setupShaderFromSource(GL_FRAGMENT_SHADER,fragmentSource(fragment2DHeader,shaderLights,true)); shaderTexture2D.bindDefaults(); shaderTexture2D.linkProgram(); +#endif #ifndef TARGET_OPENGLES shaderTextureRect.setupShaderFromSource(GL_VERTEX_SHADER,vertexSource(vertexRectHeader,shaderLights,true)); diff --git a/libs/openFrameworks/gl/ofTexture.cpp b/libs/openFrameworks/gl/ofTexture.cpp index 54c00a31248..922064d2b65 100644 --- a/libs/openFrameworks/gl/ofTexture.cpp +++ b/libs/openFrameworks/gl/ofTexture.cpp @@ -599,12 +599,16 @@ void ofTexture::generateMipmap(){ switch (texData.textureTarget) { /// OpenGL ES only supports mipmap for the following two texture targets: case GL_TEXTURE_2D: +#if defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) case GL_TEXTURE_CUBE_MAP: +#endif #ifndef TARGET_OPENGLES /// OpenGL supports mipmaps for additional texture targets: case GL_TEXTURE_1D: - case GL_TEXTURE_3D: case GL_TEXTURE_1D_ARRAY: +#endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) + case GL_TEXTURE_3D: case GL_TEXTURE_2D_ARRAY: #endif { diff --git a/libs/openFrameworks/graphics/ofGraphics.cpp b/libs/openFrameworks/graphics/ofGraphics.cpp index 5173782567f..fe2ba68a8cb 100644 --- a/libs/openFrameworks/graphics/ofGraphics.cpp +++ b/libs/openFrameworks/graphics/ofGraphics.cpp @@ -394,10 +394,12 @@ void ofBackgroundGradient(const ofColor& start, const ofColor& end, ofGradientMo gradientMesh.clear(); gradientMesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN); #ifndef TARGET_EMSCRIPTEN - #ifdef TARGET_OPENGLES - if(ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW); - #else - gradientMesh.setUsage(GL_STREAM_DRAW); + #ifdef GL_STREAM_DRAW + #ifdef TARGET_OPENGLES + if(ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW); + #else + gradientMesh.setUsage(GL_STREAM_DRAW); + #endif #endif #endif if(mode == OF_GRADIENT_CIRCULAR) { diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index c607750d634..de2df53413b 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -1,5 +1,8 @@ #pragma once #include +#if defined(__ANDROID__) +#include +#endif //------------------------------- #define OF_VERSION_MAJOR 0 @@ -211,20 +214,24 @@ enum ofTargetPlatform{ #include #include - #define GL_GLEXT_PROTOTYPES + #define GL_GLEXT_PROTOTYPES #include - // we have to include the GLES 3 headers first since gl2.h and gl3.h are incompatible due to glShaderSource - #if __ANDROID_API__ >= 21 + #if __ANDROID_API__ >= 21 #include "GLES3/gl3.h" #include "GLES3/gl31.h" // only works on Android-21+ #include "GLES3/gl3ext.h" + #include // gl2ext is supposed to be compatible with GLES3 + #define TARGET_PROGRAMMABLE_GL + #endif + // we have to include the GLES 3 headers first since gl2.h and gl3.h are incompatible due to glShaderSource + #ifndef __gl3_h_ + #include + #include // gl2ext is supposed to be compatible with GLES3 + #ifdef __gl2_h_ + #define TARGET_PROGRAMMABLE_GL + #endif #endif -#ifndef __gl3_h_ - #include - #include -#endif - #define TARGET_LITTLE_ENDIAN #endif diff --git a/libs/openFrameworksCompiled/project/android/config.android.default.mk b/libs/openFrameworksCompiled/project/android/config.android.default.mk index 842558c6664..a3e4867c29a 100644 --- a/libs/openFrameworksCompiled/project/android/config.android.default.mk +++ b/libs/openFrameworksCompiled/project/android/config.android.default.mk @@ -60,7 +60,7 @@ PLATFORM_DEFINES = PLATFORM_DEFINES = ANDROID ifndef $(NDK_PLATFORM) - NDK_PLATFORM = android-19 + NDK_PLATFORM = android-21 endif ifndef $(SDK_TARGET) @@ -347,6 +347,7 @@ PLATFORM_LIBRARIES += supc++ PLATFORM_LIBRARIES += z PLATFORM_LIBRARIES += GLESv1_CM PLATFORM_LIBRARIES += GLESv2 +PLATFORM_LIBRARIES += GLESv3 PLATFORM_LIBRARIES += log PLATFORM_LIBRARIES += dl PLATFORM_LIBRARIES += m From c469dc5a27c9adb06066fa78b7316d84deb2fa68 Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Tue, 8 Sep 2015 23:44:14 +0200 Subject: [PATCH 04/12] Fixes. --- libs/openFrameworks/gl/ofGLUtils.cpp | 107 +++++++++++++++++++-------- 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp index e11116425d4..5235e0dbe33 100644 --- a/libs/openFrameworks/gl/ofGLUtils.cpp +++ b/libs/openFrameworks/gl/ofGLUtils.cpp @@ -46,25 +46,33 @@ int ofGetGlInternalFormat(const ofShortPixels& pix) { //--------------------------------- int ofGetGlInternalFormat(const ofFloatPixels& pix) { -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) switch(pix.getNumChannels()) { case 3: return GL_RGB32F; case 4: return GL_RGBA32F; case 2: + #ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ + #endif return GL_RG32F; + #ifndef TARGET_OPENGLES }else{ return GL_LUMINANCE_ALPHA32F_ARB; } + #endif default: + #ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ + #endif return GL_R32F; + #ifndef TARGET_OPENGLES }else{ return GL_LUMINANCE32F_ARB; } + #endif } #else - ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES"; + ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES < 3.0"; switch(pix.getNumChannels()) { case 3: return GL_RGB; case 4: return GL_RGBA; @@ -81,11 +89,11 @@ int ofGetGlInternalFormat(const ofFloatPixels& pix) { string ofGetGlInternalFormatName(int glInternalFormat) { switch(glInternalFormat) { case GL_RGBA: return "GL_RGBA"; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGBA8: return "GL_RGBA8"; #endif case GL_RGB: return "GL_RGB"; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGB8: return "GL_RGB8"; #endif case GL_LUMINANCE: return "GL_LUMINANCE"; @@ -109,20 +117,24 @@ string ofGetGlInternalFormatName(int glInternalFormat) { int ofGetGLFormatFromInternal(int glInternalFormat){ switch(glInternalFormat) { case GL_RGBA: - #ifndef TARGET_OPENGLES + #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGBA8: - case GL_RGBA16: case GL_RGBA16F: + #ifndef TARGET_OPENGLES + case GL_RGBA16: case GL_RGBA32F_ARB: + #endif #endif return GL_RGBA; case GL_RGB: - #ifndef TARGET_OPENGLES + #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGB8: + #ifndef TARGET_OPENGLES case GL_RGB16: case GL_RGB32F_ARB: + #endif #endif return GL_RGB; @@ -131,7 +143,9 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_LUMINANCE8: case GL_LUMINANCE16: + #ifndef TARGET_OPENGLES case GL_LUMINANCE32F_ARB: + #endif #endif return GL_LUMINANCE; @@ -139,7 +153,9 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_LUMINANCE8_ALPHA8: case GL_LUMINANCE16_ALPHA16: + #ifndef TARGET_OPENGLES case GL_LUMINANCE_ALPHA32F_ARB: + #endif #endif return GL_LUMINANCE_ALPHA; @@ -148,27 +164,40 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ return GL_DEPTH_STENCIL; case GL_DEPTH_COMPONENT: -#ifndef TARGET_OPENGLES + #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) case GL_DEPTH_COMPONENT16: + #endif + #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_DEPTH_COMPONENT24: + #endif + #if defined(TARGET_OPENGLES) && defined(GL_ES_VERSION_3_0) + case GL_DEPTH_COMPONENT32F: + #endif + #ifndef TARGET_OPENGLES case GL_DEPTH_COMPONENT32: -#endif + #endif return GL_DEPTH_COMPONENT; case GL_STENCIL_INDEX: return GL_STENCIL_INDEX; -#ifndef TARGET_OPENGLES + #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_R8: - case GL_R16: case GL_R16F: case GL_R32F: + #endif +#ifndef TARGET_OPENGLES + case GL_R16: +#endif return GL_RED; +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RG8: - case GL_RG16: case GL_RG16F: case GL_RG32F: + #ifndef TARGET_OPENGLES + case GL_RG16: + #endif return GL_RG; #endif @@ -193,14 +222,16 @@ int ofGetGlTypeFromInternal(int glInternalFormat){ case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_ALPHA: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) + #ifndef TARGET_OPENGLES case GL_LUMINANCE8: case GL_LUMINANCE8_ALPHA8: + case GL_ALPHA8: + #endif case GL_R8: case GL_RG8: case GL_RGB8: case GL_RGBA8: - case GL_ALPHA8: #endif return GL_UNSIGNED_BYTE; @@ -288,11 +319,13 @@ int ofGetGlType(const ofFloatPixels & pixels) { ofImageType ofGetImageTypeFromGLType(int glType){ switch(glType){ case GL_LUMINANCE: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) + #ifndef TARGET_OPENGLES case GL_LUMINANCE8: case GL_LUMINANCE16: case GL_LUMINANCE32F_ARB: case GL_R16: + #endif case GL_R16F: case GL_R16I: case GL_R16UI: @@ -300,7 +333,9 @@ ofImageType ofGetImageTypeFromGLType(int glType){ case GL_R32I: case GL_R32UI: case GL_DEPTH_COMPONENT32F: + #ifndef TARGET_OPENGLES case GL_DEPTH_COMPONENT32: + #endif case GL_DEPTH_COMPONENT16: case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT: @@ -309,9 +344,11 @@ ofImageType ofGetImageTypeFromGLType(int glType){ case GL_RGB: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGB8: + #ifndef TARGET_OPENGLES case GL_RGB16: + #endif case GL_RGB16F: case GL_RGB16I: case GL_RGB16UI: @@ -323,9 +360,11 @@ ofImageType ofGetImageTypeFromGLType(int glType){ case GL_RGBA: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGBA8: + #ifndef TARGET_OPENGLES case GL_RGBA16: + #endif case GL_RGBA16F: case GL_RGBA16I: case GL_RGBA16UI: @@ -482,14 +521,14 @@ int ofGetGLInternalFormatFromPixelFormat(ofPixelFormat pixelFormat){ switch(pixelFormat){ case OF_PIXELS_BGRA: case OF_PIXELS_RGBA: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) return GL_RGBA8; #else return GL_RGBA; #endif case OF_PIXELS_RGB: case OF_PIXELS_BGR: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) return GL_RGB8; #else return GL_RGB; @@ -510,26 +549,26 @@ int ofGetGLInternalFormatFromPixelFormat(ofPixelFormat pixelFormat){ case OF_PIXELS_Y: case OF_PIXELS_U: case OF_PIXELS_V: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) if(ofIsGLProgrammableRenderer()){ return GL_R8; }else{ #endif return GL_LUMINANCE; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) } #endif case OF_PIXELS_GRAY_ALPHA: case OF_PIXELS_YUY2: case OF_PIXELS_UV: case OF_PIXELS_VU: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) if(ofIsGLProgrammableRenderer()){ return GL_RG8; }else{ #endif return GL_LUMINANCE_ALPHA; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) } #endif default: @@ -566,37 +605,37 @@ int ofGetGLFormatFromPixelFormat(ofPixelFormat pixelFormat){ case OF_PIXELS_Y: case OF_PIXELS_U: case OF_PIXELS_V: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) if(ofIsGLProgrammableRenderer()){ return GL_RED; }else{ #endif return GL_LUMINANCE; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) } #endif case OF_PIXELS_GRAY_ALPHA: case OF_PIXELS_YUY2: case OF_PIXELS_UV: case OF_PIXELS_VU: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) if(ofIsGLProgrammableRenderer()){ return GL_RG; }else{ #endif return GL_LUMINANCE_ALPHA; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) } #endif default: ofLogError("ofGLUtils") << "ofGetGLFormatFromPixelFormat(): unknown OF pixel format" << pixelFormat << ", returning GL_LUMINANCE"; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) if(ofIsGLProgrammableRenderer()){ return GL_RED; }else{ #endif return GL_LUMINANCE; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) } #endif } @@ -613,7 +652,7 @@ int ofGetNumChannelsFromGLFormat(int glFormat){ return 1; case GL_LUMINANCE_ALPHA: return 2; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RED: return 1; case GL_RG: @@ -636,20 +675,24 @@ int ofGetBytesPerChannelFromGLType(int glType){ return 2; #endif -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) case GL_FLOAT: return 4; #endif +#ifndef TARGET_OPENGLES case GL_UNSIGNED_INT_24_8: return 4; +#endif -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) case GL_UNSIGNED_INT: return 4; #endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_HALF_FLOAT: return 2; +#endif default: ofLogError("ofGetBytesPerChannelFromGLType") << "unknown type returning 1"; From 031795bccafe84ba9ff5c16c1c6dabe703c27eea Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Sat, 12 Sep 2015 23:49:27 +0200 Subject: [PATCH 05/12] Misc fixes --- addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp | 2 ++ addons/ofxAndroid/src/ofxAndroidVideoPlayer.cpp | 2 ++ libs/openFrameworks/gl/ofFbo.cpp | 9 +++++---- libs/openFrameworks/gl/ofGLUtils.cpp | 2 ++ libs/openFrameworks/gl/ofTexture.h | 9 +++++---- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp b/addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp index e41764dcdec..52c8baaa661 100644 --- a/addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp +++ b/addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp @@ -116,7 +116,9 @@ void ofxAndroidVideoGrabber::Data::loadTexture(){ glTexParameterf(texture.texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(texture.texData.textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(texture.texData.textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +#ifndef TARGET_PROGRAMMABLE_GL glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#endif glDisable(texture.texData.textureTarget); diff --git a/addons/ofxAndroid/src/ofxAndroidVideoPlayer.cpp b/addons/ofxAndroid/src/ofxAndroidVideoPlayer.cpp index cb390846b27..1d0b487ffbe 100644 --- a/addons/ofxAndroid/src/ofxAndroidVideoPlayer.cpp +++ b/addons/ofxAndroid/src/ofxAndroidVideoPlayer.cpp @@ -24,7 +24,9 @@ void ofxAndroidVideoPlayer::reloadTexture(){ glTexParameterf(texture.texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(texture.texData.textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(texture.texData.textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +#ifndef TARGET_PROGRAMMABLE_GL glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#endif glDisable(texture.texData.textureTarget); diff --git a/libs/openFrameworks/gl/ofFbo.cpp b/libs/openFrameworks/gl/ofFbo.cpp index acf89f8951e..0068191798a 100644 --- a/libs/openFrameworks/gl/ofFbo.cpp +++ b/libs/openFrameworks/gl/ofFbo.cpp @@ -394,7 +394,7 @@ void ofFbo::destroy() { //-------------------------------------------------------------- bool ofFbo::checkGLSupport() { -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) if (!ofIsGLProgrammableRenderer()){ if(ofGLCheckExtension("GL_EXT_framebuffer_object")){ @@ -562,6 +562,7 @@ void ofFbo::allocate(Settings _settings) { settings.minFilter = _settings.minFilter; // if we want MSAA, create a new fbo for textures + // FIXME: it is in fact possible to do multisampling with newer OpenGL ES (2.0+ ?) #ifndef TARGET_OPENGLES if(_settings.numSamples){ glGenFramebuffers(1, &fboTextures); @@ -786,7 +787,7 @@ int ofFbo::getNumTextures() const { //---------------------------------------------------------- void ofFbo::setActiveDrawBuffer(int i){ if(!bIsAllocated) return; -#ifndef TARGET_OPENGLES +#ifndef TARGET_OPENGLES || defined(GL_ES_VERSION_3_0) vector activebuffers(1, i); setActiveDrawBuffers(activebuffers); #endif @@ -795,7 +796,7 @@ void ofFbo::setActiveDrawBuffer(int i){ //---------------------------------------------------------- void ofFbo::setActiveDrawBuffers(const vector& ids){ if(!bIsAllocated) return; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) int numBuffers = activeDrawBuffers.size(); activeDrawBuffers.clear(); activeDrawBuffers.resize(numBuffers, GL_NONE); // we initialise the vector with GL_NONE, so a buffer will not be written to unless activated. @@ -816,7 +817,7 @@ void ofFbo::setActiveDrawBuffers(const vector& ids){ //---------------------------------------------------------- void ofFbo::activateAllDrawBuffers(){ if(!bIsAllocated) return; -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) vector activeBuffers(getNumTextures(),0); for(int i=0; i < getNumTextures(); i++){ activeBuffers[i] = i; diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp index 5235e0dbe33..a8d1baa1575 100644 --- a/libs/openFrameworks/gl/ofGLUtils.cpp +++ b/libs/openFrameworks/gl/ofGLUtils.cpp @@ -255,6 +255,8 @@ int ofGetGlTypeFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_LUMINANCE32F_ARB: case GL_LUMINANCE_ALPHA32F_ARB: +#endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_R16F: case GL_RG16F: case GL_RGB16F: diff --git a/libs/openFrameworks/gl/ofTexture.h b/libs/openFrameworks/gl/ofTexture.h index afad06ca794..411d2aac01d 100644 --- a/libs/openFrameworks/gl/ofTexture.h +++ b/libs/openFrameworks/gl/ofTexture.h @@ -529,7 +529,7 @@ class ofTexture : public ofBaseDraws { /// \param glFormat GL pixel type: GL_RGBA, GL_LUMINANCE, etc. void loadData(const ofFloatPixels & pix, int glFormat); -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) /// \brief Load pixels from an ofBufferObject /// /// This is different to allocate(ofBufferObject,internal). That @@ -681,9 +681,10 @@ class ofTexture : public ofBaseDraws { /// void unbind(int textureLocation=0) const; - // note: defined(someMethod) doesn't actually always work - // there is no reliable way to check for a function being defined just with the preprocessor -#if (!defined(TARGET_OPENGLES) && defined(glBindImageTexture)) || defined(GL_ES_VERSION_3_1) +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_1) +// TODO: check for availability of glBindImageTexture in a valid way +// defined(glBindImageTexture) does not actually work! +// there is no reliable way to check for a function being defined just with the preprocessor /// Calls glBindImageTexture on the texture /// /// Binds the texture as an read or write image, only available since OpenGL 4.2 From e7cc56563ab9a55f6c0d193922e268b718d18138 Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Thu, 17 Sep 2015 16:05:44 +0200 Subject: [PATCH 06/12] Minor fixes when using GLES1. --- libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp | 1 + libs/openFrameworks/gl/ofGLRenderer.cpp | 2 -- libs/openFrameworks/gl/ofGLUtils.cpp | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp index e14733c3e1f..8e564ab0243 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp @@ -2298,6 +2298,7 @@ string ofGLProgrammableRenderer::defaultFragmentShaderHeader(GLenum textureTarge } void ofGLProgrammableRenderer::setup(int _major, int _minor){ + ofLogNotice("ofGLProgrammableRenderer") << " setup."; glGetError(); #ifdef TARGET_OPENGLES // OpenGL ES might have set a default frame buffer for diff --git a/libs/openFrameworks/gl/ofGLRenderer.cpp b/libs/openFrameworks/gl/ofGLRenderer.cpp index 8785c9a28f2..88af0edd446 100644 --- a/libs/openFrameworks/gl/ofGLRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLRenderer.cpp @@ -15,7 +15,6 @@ const string ofGLRenderer::TYPE="GL"; -#if !defined(TARGET_OPENGLES) || !defined(TARGET_PROGRAMMABLE_GL) //---------------------------------------------------------- ofGLRenderer::ofGLRenderer(const ofAppBaseWindow * _window) :matrixStack(_window) @@ -1947,4 +1946,3 @@ of3dGraphics & ofGLRenderer::get3dGraphics(){ return graphics3d; } -#endif \ No newline at end of file diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp index a8d1baa1575..e83243a2b54 100644 --- a/libs/openFrameworks/gl/ofGLUtils.cpp +++ b/libs/openFrameworks/gl/ofGLUtils.cpp @@ -185,11 +185,11 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ case GL_R8: case GL_R16F: case GL_R32F: - #endif #ifndef TARGET_OPENGLES case GL_R16: #endif return GL_RED; + #endif #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RG8: From 4f34a507305195b63905fc9ef2dda7008d884aaa Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Thu, 17 Sep 2015 16:06:46 +0200 Subject: [PATCH 07/12] More consistent API. --- .../src/cc/openframeworks/OFAndroid.java | 7 ++-- .../cc/openframeworks/OFAndroidWindow.java | 33 ++++++++++------ addons/ofxAndroid/src/ofAppAndroidWindow.cpp | 38 ++++++++++--------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java index 0ff94d52c0d..eb68dfffa99 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java @@ -1077,14 +1077,15 @@ public static void initView(){ } } - public static void setupGL(int version){ - final int finalversion = version; + public static void setupGL(int versionMajor, int versionMinor){ + final int finalVersionMajor = versionMajor; + final int finalVersionMinor = versionMinor; ofActivity.runOnUiThread(new Runnable() { @Override public void run() { gestureListener = new OFGestureListener(ofActivity); - OFEGLConfigChooser.setGLESVersion(finalversion); + OFEGLConfigChooser.setGLESVersion(finalVersionMajor, finalVersionMinor); initView(); instance.resume(); diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java index 2f891d1f5f9..704d46cf42b 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java @@ -22,19 +22,29 @@ public OFEGLConfigChooser(int r, int g, int b, int a, int depth, int stencil) { mAlphaSize = a; mDepthSize = depth; mStencilSize = stencil; - mGLESVersion = 0; + mGLESVersionMajor = 0; + mGLESVersionMinor = 0; } - public static void setGLESVersion(int version){ - if(version==1) EGL_OPENGL_ES_BIT=1; - else EGL_OPENGL_ES_BIT=4; // == EGL_OPENGL_ES2_BIT - mGLESVersion = version; + public static void setGLESVersion(int versionMajor, int versionMinor){ // versionMinor not needed, just here for consistency + if(versionMajor==1) EGL_OPENGL_ES_BIT=1; + else { + EGL_OPENGL_ES_BIT=4; // == EGL_OPENGL_ES2_BIT + s_configAttribs2[7] = 4; // might not be needed + } + mGLESVersionMajor = versionMajor; + mGLESVersionMinor = versionMinor; } - public static int getGLESVersion(){ - if(mGLESVersion == 0) + public static int getGLESVersionMajor(){ + if(mGLESVersionMajor == 0) + throw new IllegalStateException("You need to set the GLES version!"); + return mGLESVersionMajor; + } + public static int getGLESVersionMinor(){ + if(mGLESVersionMajor == 0) // yes throw new IllegalStateException("You need to set the GLES version!"); - return mGLESVersion; + return mGLESVersionMinor; } /* This EGL config specification is used to specify 1.x rendering. @@ -217,7 +227,8 @@ private void printConfig(EGL10 egl, EGLDisplay display, protected int mAlphaSize; protected int mDepthSize; protected int mStencilSize; - protected static int mGLESVersion; + protected static int mGLESVersionMajor; + protected static int mGLESVersionMinor; private int[] mValue = new int[1]; } @@ -225,7 +236,7 @@ class OFGLSurfaceView extends GLSurfaceView{ public OFGLSurfaceView(Context context) { super(context); mRenderer = new OFAndroidWindow(getWidth(),getHeight()); - setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersion()); + setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersionMajor()); getHolder().setFormat( PixelFormat.OPAQUE ); OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0); setEGLConfigChooser(configChooser); @@ -235,7 +246,7 @@ public OFGLSurfaceView(Context context) { public OFGLSurfaceView(Context context,AttributeSet attributes) { super(context,attributes); mRenderer = new OFAndroidWindow(getWidth(),getHeight()); - setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersion()); + setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersionMajor()); getHolder().setFormat( PixelFormat.OPAQUE ); OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0); setEGLConfigChooser(configChooser); diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index 0c827b44538..d17a220ebe0 100644 --- a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp +++ b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp @@ -143,18 +143,21 @@ void ofAppAndroidWindow::setup(const ofGLESWindowSettings & settings){ return; } - jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"setupGL","(I)V"); + jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"setupGL","(II)V"); // (II)V = void(int,int) if(!method){ ofLogError("ofAppAndroidWindow") << "setupOpenGL(): couldn't find OFAndroid setupGL method"; return; } - ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,sGLESVersionMajor); + // note: setup is called in onSurfaceCreated and we most likely don't yet have a working OpenGL ES context here + // so it might be both wrong and unnecessary to call setup() here - // note: we used to call renderer->setup here, but this is both wrong - // (because we most likely don't yet have a working GLES context) - // and superfluous, because we call setup in onSurfaceCreated - // (where the context exists, by definition) + ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,sGLESVersionMajor,sGLESVersionMinor); + if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){ + static_cast(currentRenderer.get())->setup(settings.glesVersionMajor(),settings.glesVersionMinor()); + }else{ + static_cast(currentRenderer.get())->setup(); + } } void ofAppAndroidWindow::update(){ @@ -321,18 +324,19 @@ Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv* env, jclass thiz ){ window->renderer()->setupGraphicDefaults(); ofPopStyle(); surfaceDestroyed = false; - }else{ -#ifndef TARGET_PROGRAMMABLE_GL - if(window->renderer()->getType()==ofGLProgrammableRenderer::TYPE){ -#endif - static_cast(window->renderer().get())->setup(sGLESVersionMajor,sGLESVersionMinor); -#ifndef TARGET_PROGRAMMABLE_GL - }else{ - static_cast(window->renderer().get())->setup(); - } -#endif - ofLogNotice() << "renderer created"; } + + // with programmable renderers, we need to (re)create all shaders e.g after pause() was called + // which is why we call setup() here. + if(window->renderer()->getType()==ofGLProgrammableRenderer::TYPE){ + static_cast(window->renderer().get())->setup(sGLESVersionMajor,sGLESVersionMinor); + ofLogNotice() << "programmable renderer created"; + }else{ + if(! appSetup) { + static_cast(window->renderer().get())->setup(); + ofLogNotice() << "renderer created"; + } + } } void From 6d4f44b28ce9c60c1f62d90573b4d191095ff10a Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Thu, 17 Sep 2015 16:16:09 +0200 Subject: [PATCH 08/12] Update EGL window class to use new GLES settings class. TODO: iOS --- libs/openFrameworks/app/ofAppEGLWindow.cpp | 27 ++++++++++++---------- libs/openFrameworks/app/ofAppEGLWindow.h | 3 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/libs/openFrameworks/app/ofAppEGLWindow.cpp b/libs/openFrameworks/app/ofAppEGLWindow.cpp index 96617297ea6..7662a0da111 100644 --- a/libs/openFrameworks/app/ofAppEGLWindow.cpp +++ b/libs/openFrameworks/app/ofAppEGLWindow.cpp @@ -273,7 +273,8 @@ ofAppEGLWindow::ofAppEGLWindow() { x11Display = NULL; x11Screen = NULL; x11ScreenNum = 0l; - glesVersion = 1; + glesVersionMajor = 1; + glesVersionMinor = 0; if(instance!=NULL){ ofLogError("ofAppEGLWindow") << "trying to create more than one instance"; @@ -415,7 +416,8 @@ void ofAppEGLWindow::setup(const Settings & _settings) { eglConfig = NULL; eglVersionMinor = -1; eglVersionMinor = -1; - glesVersion = 1; + glesVersionMajor = 1; + glesVersionMinor = 0; // X11 check // char * pDisplay; @@ -452,7 +454,8 @@ void ofAppEGLWindow::setup(const Settings & _settings) { initNative(); - glesVersion = settings.glesVersion; + glesVersionMajor = settings.glesVersionMajor(); + glesVersionMinor = settings.glesVersionMinor(); // we set this here, and if we need to make a fullscreen // app, we do it during the first loop. windowMode = settings.windowMode; @@ -482,7 +485,7 @@ void ofAppEGLWindow::setup(const Settings & _settings) { nFramesSinceWindowResized = 0; - if(settings.glesVersion>1){ + if(settings.glesVersionMajor()>1){ currentRenderer = make_shared(this); }else{ currentRenderer = make_shared(this); @@ -490,7 +493,7 @@ void ofAppEGLWindow::setup(const Settings & _settings) { makeCurrent(); if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){ - static_cast(currentRenderer.get())->setup(settings.glesVersion,0); + static_cast(currentRenderer.get())->setup(settings.glesVersionMajor(),settings.glesVersionMinor()); }else{ static_cast(currentRenderer.get())->setup(); } @@ -560,7 +563,7 @@ bool ofAppEGLWindow::createSurface() { // success! } - EGLint glesVersion; + EGLint glesVersionBit; int glesVersionForContext; if(ofGetCurrentRenderer()) { @@ -569,12 +572,12 @@ bool ofAppEGLWindow::createSurface() { ofLogNotice("ofAppEGLWindow") << "createSurface(): no current renderer selected"; } - if(this->glesVersion==2){ - glesVersion = EGL_OPENGL_ES2_BIT; - glesVersionForContext = 2; - ofLogNotice("ofAppEGLWindow") << "createSurface(): GLES2 renderer detected"; + if(this->glesVersionMajor>=2){ + glesVersionBit = EGL_OPENGL_ES2_BIT; + glesVersionForContext = this->glesVersionMajor; + ofLogNotice("ofAppEGLWindow") << "createSurface(): GLES" << glesVersionForContext << " renderer detected"; }else{ - glesVersion = EGL_OPENGL_ES_BIT; + glesVersionBit = EGL_OPENGL_ES_BIT; glesVersionForContext = 1; ofLogNotice("ofAppEGLWindow") << "createSurface(): default renderer detected"; } @@ -593,7 +596,7 @@ bool ofAppEGLWindow::createSurface() { attribute_list_framebuffer_config[i++] = iter->second; } attribute_list_framebuffer_config[i++] = EGL_RENDERABLE_TYPE; - attribute_list_framebuffer_config[i++] = glesVersion; //openGL ES version + attribute_list_framebuffer_config[i++] = glesVersionBit; //openGL ES version attribute_list_framebuffer_config[i] = EGL_NONE; // add the terminator EGLint num_configs; diff --git a/libs/openFrameworks/app/ofAppEGLWindow.h b/libs/openFrameworks/app/ofAppEGLWindow.h index 99331c9eaf9..4f9617d6f2e 100644 --- a/libs/openFrameworks/app/ofAppEGLWindow.h +++ b/libs/openFrameworks/app/ofAppEGLWindow.h @@ -299,7 +299,8 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread { private: Settings settings; - int glesVersion; ///< \brief Indicate the version of OpenGL for Embedded Systems. + int glesVersionMajor; ///< \brief Indicate the version of OpenGL for Embedded Systems. + int glesVersionMinor; bool keyboardDetected; bool mouseDetected; long threadTimeout; From dde8537f42cd78fa125ecf4cf6b3d51c6d9628fa Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Thu, 17 Sep 2015 16:17:38 +0200 Subject: [PATCH 09/12] Remove redundant Android target info from manifest files. It is overwritten by build.gradle. --- addons/ofxAndroid/ofAndroidLib/AndroidManifest.xml | 3 --- examples/android/androidEmptyExample/AndroidManifest.xml | 4 ---- examples/android/androidPolygonExample/AndroidManifest.xml | 4 ---- examples/android/androidShaderExample/AndroidManifest.xml | 1 + 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/addons/ofxAndroid/ofAndroidLib/AndroidManifest.xml b/addons/ofxAndroid/ofAndroidLib/AndroidManifest.xml index 2b2f55ab869..f1c26a60ed3 100644 --- a/addons/ofxAndroid/ofAndroidLib/AndroidManifest.xml +++ b/addons/ofxAndroid/ofAndroidLib/AndroidManifest.xml @@ -1,7 +1,4 @@ - \ No newline at end of file diff --git a/examples/android/androidEmptyExample/AndroidManifest.xml b/examples/android/androidEmptyExample/AndroidManifest.xml index 89ccc6ae814..829ac5e63e7 100644 --- a/examples/android/androidEmptyExample/AndroidManifest.xml +++ b/examples/android/androidEmptyExample/AndroidManifest.xml @@ -5,10 +5,6 @@ android:versionName="1.0" android:installLocation="preferExternal"> - - - - + Date: Fri, 18 Sep 2015 12:27:20 +0200 Subject: [PATCH 10/12] Fixed problem with broken textures. --- libs/openFrameworks/gl/ofGLUtils.cpp | 117 +++++++++++++-------------- 1 file changed, 56 insertions(+), 61 deletions(-) diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp index e83243a2b54..94373561c52 100644 --- a/libs/openFrameworks/gl/ofGLUtils.cpp +++ b/libs/openFrameworks/gl/ofGLUtils.cpp @@ -51,28 +51,28 @@ int ofGetGlInternalFormat(const ofFloatPixels& pix) { case 3: return GL_RGB32F; case 4: return GL_RGBA32F; case 2: - #ifndef TARGET_OPENGLES +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ - #endif return GL_RG32F; - #ifndef TARGET_OPENGLES }else{ return GL_LUMINANCE_ALPHA32F_ARB; } - #endif +#else + return GL_RG32F; +#endif default: - #ifndef TARGET_OPENGLES +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ - #endif return GL_R32F; - #ifndef TARGET_OPENGLES }else{ return GL_LUMINANCE32F_ARB; } - #endif +#else + return GL_R32F; +#endif } #else - ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES < 3.0"; + ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES"; switch(pix.getNumChannels()) { case 3: return GL_RGB; case 4: return GL_RGBA; @@ -120,7 +120,7 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGBA8: case GL_RGBA16F: - #ifndef TARGET_OPENGLES + #ifndef TARGET_OPENGLES case GL_RGBA16: case GL_RGBA32F_ARB: #endif @@ -143,9 +143,7 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_LUMINANCE8: case GL_LUMINANCE16: - #ifndef TARGET_OPENGLES case GL_LUMINANCE32F_ARB: - #endif #endif return GL_LUMINANCE; @@ -153,9 +151,7 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_LUMINANCE8_ALPHA8: case GL_LUMINANCE16_ALPHA16: - #ifndef TARGET_OPENGLES case GL_LUMINANCE_ALPHA32F_ARB: - #endif #endif return GL_LUMINANCE_ALPHA; @@ -164,40 +160,35 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ return GL_DEPTH_STENCIL; case GL_DEPTH_COMPONENT: - #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_2_0) || defined(GL_ES_VERSION_3_0) +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_DEPTH_COMPONENT16: - #endif - #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_DEPTH_COMPONENT24: - #endif - #if defined(TARGET_OPENGLES) && defined(GL_ES_VERSION_3_0) + #ifdef TARGET_OPENGLES case GL_DEPTH_COMPONENT32F: - #endif - #ifndef TARGET_OPENGLES + #else case GL_DEPTH_COMPONENT32: #endif +#endif return GL_DEPTH_COMPONENT; case GL_STENCIL_INDEX: return GL_STENCIL_INDEX; - #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_R8: + #ifndef TARGET_OPENGLES + case GL_R16: + #endif case GL_R16F: case GL_R32F: -#ifndef TARGET_OPENGLES - case GL_R16: -#endif return GL_RED; - #endif -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RG8: + #ifndef TARGET_OPENGLES + case GL_RG16: + #endif case GL_RG16F: case GL_RG32F: - #ifndef TARGET_OPENGLES - case GL_RG16: - #endif return GL_RG; #endif @@ -223,11 +214,11 @@ int ofGetGlTypeFromInternal(int glInternalFormat){ case GL_LUMINANCE_ALPHA: case GL_ALPHA: #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) - #ifndef TARGET_OPENGLES + #ifndef TARGET_OPENGLES case GL_LUMINANCE8: case GL_LUMINANCE8_ALPHA8: case GL_ALPHA8: - #endif + #endif case GL_R8: case GL_RG8: case GL_RGB8: @@ -252,11 +243,11 @@ int ofGetGlTypeFromInternal(int glInternalFormat){ break; #endif -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) + #ifndef TARGET_OPENGLES case GL_LUMINANCE32F_ARB: case GL_LUMINANCE_ALPHA32F_ARB: -#endif -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) + #endif case GL_R16F: case GL_RG16F: case GL_RGB16F: @@ -273,7 +264,7 @@ int ofGetGlTypeFromInternal(int glInternalFormat){ return GL_UNSIGNED_INT_24_8; case GL_DEPTH_COMPONENT: -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_DEPTH_COMPONENT16: #endif return GL_UNSIGNED_SHORT; @@ -282,6 +273,13 @@ int ofGetGlTypeFromInternal(int glInternalFormat){ case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT32: return GL_UNSIGNED_INT; +#else + #if defined(GL_ES_VERSION_3_0) + case GL_DEPTH_COMPONENT24: + return GL_UNSIGNED_INT; + case GL_DEPTH_COMPONENT32F: + return GL_FLOAT; + #endif #endif case GL_STENCIL_INDEX: @@ -321,13 +319,14 @@ int ofGetGlType(const ofFloatPixels & pixels) { ofImageType ofGetImageTypeFromGLType(int glType){ switch(glType){ case GL_LUMINANCE: -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) - #ifndef TARGET_OPENGLES +#ifndef TARGET_OPENGLES case GL_LUMINANCE8: case GL_LUMINANCE16: case GL_LUMINANCE32F_ARB: case GL_R16: - #endif + case GL_DEPTH_COMPONENT32: +#endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_R16F: case GL_R16I: case GL_R16UI: @@ -335,9 +334,6 @@ ofImageType ofGetImageTypeFromGLType(int glType){ case GL_R32I: case GL_R32UI: case GL_DEPTH_COMPONENT32F: - #ifndef TARGET_OPENGLES - case GL_DEPTH_COMPONENT32: - #endif case GL_DEPTH_COMPONENT16: case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT: @@ -346,11 +342,11 @@ ofImageType ofGetImageTypeFromGLType(int glType){ case GL_RGB: -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES + case GL_RGB16: +#endif +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGB8: - #ifndef TARGET_OPENGLES - case GL_RGB16: - #endif case GL_RGB16F: case GL_RGB16I: case GL_RGB16UI: @@ -362,11 +358,11 @@ ofImageType ofGetImageTypeFromGLType(int glType){ case GL_RGBA: +#ifndef TARGET_OPENGLES + case GL_RGBA16: +#endif #if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_RGBA8: - #ifndef TARGET_OPENGLES - case GL_RGBA16: - #endif case GL_RGBA16F: case GL_RGBA16I: case GL_RGBA16UI: @@ -551,26 +547,26 @@ int ofGetGLInternalFormatFromPixelFormat(ofPixelFormat pixelFormat){ case OF_PIXELS_Y: case OF_PIXELS_U: case OF_PIXELS_V: -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_R8; }else{ #endif return GL_LUMINANCE; -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES } #endif case OF_PIXELS_GRAY_ALPHA: case OF_PIXELS_YUY2: case OF_PIXELS_UV: case OF_PIXELS_VU: -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_RG8; }else{ #endif return GL_LUMINANCE_ALPHA; -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES } #endif default: @@ -607,37 +603,37 @@ int ofGetGLFormatFromPixelFormat(ofPixelFormat pixelFormat){ case OF_PIXELS_Y: case OF_PIXELS_U: case OF_PIXELS_V: -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_RED; }else{ #endif return GL_LUMINANCE; -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES } #endif case OF_PIXELS_GRAY_ALPHA: case OF_PIXELS_YUY2: case OF_PIXELS_UV: case OF_PIXELS_VU: -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_RG; }else{ #endif return GL_LUMINANCE_ALPHA; -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES } #endif default: ofLogError("ofGLUtils") << "ofGetGLFormatFromPixelFormat(): unknown OF pixel format" << pixelFormat << ", returning GL_LUMINANCE"; -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_RED; }else{ #endif return GL_LUMINANCE; -#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) +#ifndef TARGET_OPENGLES } #endif } @@ -681,7 +677,7 @@ int ofGetBytesPerChannelFromGLType(int glType){ case GL_FLOAT: return 4; #endif -#ifndef TARGET_OPENGLES +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) case GL_UNSIGNED_INT_24_8: return 4; #endif @@ -695,7 +691,6 @@ int ofGetBytesPerChannelFromGLType(int glType){ case GL_HALF_FLOAT: return 2; #endif - default: ofLogError("ofGetBytesPerChannelFromGLType") << "unknown type returning 1"; return 1; From b2409bdb77d86d8deff236739d4e51147a9c3b7b Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Thu, 1 Oct 2015 00:27:41 +0200 Subject: [PATCH 11/12] Smaller fixes --- .../src/cc/openframeworks/OFAndroid.java | 1 + .../src/cc/openframeworks/OFAndroidWindow.java | 14 ++++++++------ libs/openFrameworks/gl/ofFbo.cpp | 2 +- libs/openFrameworks/gl/ofGLUtils.cpp | 7 +++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java index eb68dfffa99..1e3bebde707 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java @@ -262,6 +262,7 @@ public void run() { while ((entry = resourceszip.getNextEntry()) != null){ String name = entry.getName(); + Log.i("OF","handling " + name); if( entry.isDirectory() ) { OFZipUtil.mkdirs(outdir,name); diff --git a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java index 704d46cf42b..c7b1d31dc9d 100644 --- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java +++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java @@ -22,8 +22,8 @@ public OFEGLConfigChooser(int r, int g, int b, int a, int depth, int stencil) { mAlphaSize = a; mDepthSize = depth; mStencilSize = stencil; - mGLESVersionMajor = 0; - mGLESVersionMinor = 0; + mGLESVersionMajor = 3; + mGLESVersionMinor = 1; } public static void setGLESVersion(int versionMajor, int versionMinor){ // versionMinor not needed, just here for consistency @@ -37,13 +37,13 @@ public static void setGLESVersion(int versionMajor, int versionMinor){ // versio } public static int getGLESVersionMajor(){ - if(mGLESVersionMajor == 0) - throw new IllegalStateException("You need to set the GLES version!"); + // if(mGLESVersionMajor == 0) + // throw new IllegalStateException("You need to set the GLES version!"); return mGLESVersionMajor; } public static int getGLESVersionMinor(){ - if(mGLESVersionMajor == 0) // yes - throw new IllegalStateException("You need to set the GLES version!"); + // if(mGLESVersionMajor == 0) // yes + // throw new IllegalStateException("You need to set the GLES version!"); return mGLESVersionMinor; } @@ -236,6 +236,7 @@ class OFGLSurfaceView extends GLSurfaceView{ public OFGLSurfaceView(Context context) { super(context); mRenderer = new OFAndroidWindow(getWidth(),getHeight()); + Log.i("OF"," setting context version " + OFEGLConfigChooser.getGLESVersionMajor()); setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersionMajor()); getHolder().setFormat( PixelFormat.OPAQUE ); OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0); @@ -246,6 +247,7 @@ public OFGLSurfaceView(Context context) { public OFGLSurfaceView(Context context,AttributeSet attributes) { super(context,attributes); mRenderer = new OFAndroidWindow(getWidth(),getHeight()); + Log.i("OF"," setting context version " + OFEGLConfigChooser.getGLESVersionMajor()); setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersionMajor()); getHolder().setFormat( PixelFormat.OPAQUE ); OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0); diff --git a/libs/openFrameworks/gl/ofFbo.cpp b/libs/openFrameworks/gl/ofFbo.cpp index 0068191798a..adecc25e37e 100644 --- a/libs/openFrameworks/gl/ofFbo.cpp +++ b/libs/openFrameworks/gl/ofFbo.cpp @@ -787,7 +787,7 @@ int ofFbo::getNumTextures() const { //---------------------------------------------------------- void ofFbo::setActiveDrawBuffer(int i){ if(!bIsAllocated) return; -#ifndef TARGET_OPENGLES || defined(GL_ES_VERSION_3_0) +#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0) vector activebuffers(1, i); setActiveDrawBuffers(activebuffers); #endif diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp index 94373561c52..a49673bc149 100644 --- a/libs/openFrameworks/gl/ofGLUtils.cpp +++ b/libs/openFrameworks/gl/ofGLUtils.cpp @@ -123,6 +123,8 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_RGBA16: case GL_RGBA32F_ARB: + #else + case GL_RGBA32F: #endif #endif return GL_RGBA; @@ -134,6 +136,8 @@ int ofGetGLFormatFromInternal(int glInternalFormat){ #ifndef TARGET_OPENGLES case GL_RGB16: case GL_RGB32F_ARB: + #else + case GL_RGB32F: #endif #endif return GL_RGB; @@ -372,6 +376,7 @@ ofImageType ofGetImageTypeFromGLType(int glType){ #endif return OF_IMAGE_COLOR_ALPHA; } + ofLogError("ofGLUtils") << "ofGetImageTypeFromGLType(): unknown type " << glType << ", returning OF_IMAGE_UNDEFINED"; return OF_IMAGE_UNDEFINED; } @@ -393,6 +398,7 @@ GLuint ofGetGLPolyMode(ofPolyRenderMode m){ break; } #else + ofLogError("ofGLUtils") << "ofGetGLPolyMode(): poly modes not supported in GLES"; return 0; #endif } @@ -415,6 +421,7 @@ ofPolyRenderMode ofGetOFPolyMode(GLuint m){ break; } #else + ofLogError("ofGLUtils") << "ofGetOFPolyMode(): poly modes not supported in GLES. Returning OF_MESH_FILL"; return OF_MESH_FILL; #endif } From 74cea6b9a1be1ec1068ad23415a153dc718c5074 Mon Sep 17 00:00:00 2001 From: Marcel Ruegenberg Date: Thu, 1 Oct 2015 00:27:54 +0200 Subject: [PATCH 12/12] . --- addons/ofxAndroid/src/ofAppAndroidWindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp index d17a220ebe0..5ea8f6f5a9b 100644 --- a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp +++ b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp @@ -153,11 +153,13 @@ void ofAppAndroidWindow::setup(const ofGLESWindowSettings & settings){ // so it might be both wrong and unnecessary to call setup() here ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,sGLESVersionMajor,sGLESVersionMinor); + /* if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){ static_cast(currentRenderer.get())->setup(settings.glesVersionMajor(),settings.glesVersionMinor()); }else{ static_cast(currentRenderer.get())->setup(); } + */ } void ofAppAndroidWindow::update(){ @@ -314,7 +316,7 @@ Java_cc_openframeworks_OFAndroid_onSurfaceDestroyed( JNIEnv* env, jclass thiz void Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv* env, jclass thiz ){ - if(appSetup){ + if(true){ ofLogNotice("ofAppAndroidWindow") << "onSurfaceCreated"; if(!surfaceDestroyed){ ofNotifyEvent(ofxAndroidEvents().unloadGL);