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/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroid.java
index 0ff94d52c0d..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);
@@ -1077,14 +1078,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 21fc1e6a4c5..c7b1d31dc9d 100644
--- a/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java
+++ b/addons/ofxAndroid/ofAndroidLib/src/cc/openframeworks/OFAndroidWindow.java
@@ -22,15 +22,29 @@ public OFEGLConfigChooser(int r, int g, int b, int a, int depth, int stencil) {
mAlphaSize = a;
mDepthSize = depth;
mStencilSize = stencil;
+ mGLESVersionMajor = 3;
+ mGLESVersionMinor = 1;
}
- public static void setGLESVersion(int version){
- if(version==1) EGL_OPENGL_ES_BIT=1;
- else EGL_OPENGL_ES_BIT=4;
+ 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(){
- return EGL_OPENGL_ES_BIT==1?1:2;
+ 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 mGLESVersionMinor;
}
/* This EGL config specification is used to specify 1.x rendering.
@@ -213,6 +227,8 @@ private void printConfig(EGL10 egl, EGLDisplay display,
protected int mAlphaSize;
protected int mDepthSize;
protected int mStencilSize;
+ protected static int mGLESVersionMajor;
+ protected static int mGLESVersionMinor;
private int[] mValue = new int[1];
}
@@ -220,9 +236,8 @@ class OFGLSurfaceView extends GLSurfaceView{
public OFGLSurfaceView(Context context) {
super(context);
mRenderer = new OFAndroidWindow(getWidth(),getHeight());
- if(OFEGLConfigChooser.getGLESVersion()==2){
- setEGLContextClientVersion(2);
- }
+ 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);
setEGLConfigChooser(configChooser);
@@ -232,9 +247,8 @@ public OFGLSurfaceView(Context context) {
public OFGLSurfaceView(Context context,AttributeSet attributes) {
super(context,attributes);
mRenderer = new OFAndroidWindow(getWidth(),getHeight());
- if(OFEGLConfigChooser.getGLESVersion()==2){
- setEGLContextClientVersion(2);
- }
+ 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);
setEGLConfigChooser(configChooser);
diff --git a/addons/ofxAndroid/src/ofAppAndroidWindow.cpp b/addons/ofxAndroid/src/ofAppAndroidWindow.cpp
index c734fe6aa3d..5ea8f6f5a9b 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");
@@ -126,19 +143,23 @@ 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,glesVersion);
+ // 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
- if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){
- static_cast(currentRenderer.get())->setup(settings.glesVersion,0);
- }else{
- static_cast(currentRenderer.get())->setup();
- }
+ 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(){
@@ -295,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);
@@ -305,14 +326,19 @@ Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv* env, jclass thiz ){
window->renderer()->setupGraphicDefaults();
ofPopStyle();
surfaceDestroyed = false;
- }else{
- if(window->renderer()->getType()==ofGLProgrammableRenderer::TYPE){
- static_cast(window->renderer().get())->setup(2,0);
- }else{
- static_cast(window->renderer().get())->setup();
- }
- 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
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/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">
-
-
-
-
+
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;
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/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/ofFbo.cpp b/libs/openFrameworks/gl/ofFbo.cpp
index acf89f8951e..adecc25e37e 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
+#if !defined(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/ofGLProgrammableRenderer.cpp b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp
index b4c1cb26b7e..8e564ab0243 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,9 +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
- // 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") << "drawElementsInstanced(): hardware instancing is not supported on OpenGL ES < 3.0";
// glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_SHORT, nullptr, primCount);
@@ -1796,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"
@@ -2281,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 df7b2fdb96a..88af0edd446 100644
--- a/libs/openFrameworks/gl/ofGLRenderer.cpp
+++ b/libs/openFrameworks/gl/ofGLRenderer.cpp
@@ -129,7 +129,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 +191,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 +1945,4 @@ const of3dGraphics & ofGLRenderer::get3dGraphics() const{
of3dGraphics & ofGLRenderer::get3dGraphics(){
return graphics3d;
}
+
diff --git a/libs/openFrameworks/gl/ofGLUtils.cpp b/libs/openFrameworks/gl/ofGLUtils.cpp
index 2ce901e6ca4..a49673bc149 100644
--- a/libs/openFrameworks/gl/ofGLUtils.cpp
+++ b/libs/openFrameworks/gl/ofGLUtils.cpp
@@ -46,22 +46,30 @@ 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()){
return GL_RG32F;
}else{
return GL_LUMINANCE_ALPHA32F_ARB;
}
+#else
+ return GL_RG32F;
+#endif
default:
+#ifndef TARGET_OPENGLES
if(ofIsGLProgrammableRenderer()){
return GL_R32F;
}else{
return GL_LUMINANCE32F_ARB;
}
+#else
+ return GL_R32F;
+#endif
}
#else
ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES";
@@ -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,28 @@ 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:
+ #else
+ case GL_RGBA32F:
+ #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:
+ #else
+ case GL_RGB32F:
+ #endif
#endif
return GL_RGB;
@@ -148,25 +164,33 @@ int ofGetGLFormatFromInternal(int glInternalFormat){
return GL_DEPTH_STENCIL;
case GL_DEPTH_COMPONENT:
-#ifndef TARGET_OPENGLES
+#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0)
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
+ #ifdef TARGET_OPENGLES
+ case GL_DEPTH_COMPONENT32F:
+ #else
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:
+ #ifndef TARGET_OPENGLES
case GL_R16:
+ #endif
case GL_R16F:
case GL_R32F:
return GL_RED;
case GL_RG8:
+ #ifndef TARGET_OPENGLES
case GL_RG16:
+ #endif
case GL_RG16F:
case GL_RG32F:
return GL_RG;
@@ -193,14 +217,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;
@@ -221,9 +247,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
case GL_R16F:
case GL_RG16F:
case GL_RGB16F:
@@ -240,7 +268,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;
@@ -249,6 +277,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:
@@ -293,6 +328,9 @@ ofImageType ofGetImageTypeFromGLType(int glType){
case GL_LUMINANCE16:
case GL_LUMINANCE32F_ARB:
case GL_R16:
+ case GL_DEPTH_COMPONENT32:
+#endif
+#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0)
case GL_R16F:
case GL_R16I:
case GL_R16UI:
@@ -300,7 +338,6 @@ ofImageType ofGetImageTypeFromGLType(int glType){
case GL_R32I:
case GL_R32UI:
case GL_DEPTH_COMPONENT32F:
- case GL_DEPTH_COMPONENT32:
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT:
@@ -310,8 +347,10 @@ ofImageType ofGetImageTypeFromGLType(int glType){
case GL_RGB:
#ifndef TARGET_OPENGLES
+ case GL_RGB16:
+#endif
+#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0)
case GL_RGB8:
- case GL_RGB16:
case GL_RGB16F:
case GL_RGB16I:
case GL_RGB16UI:
@@ -324,8 +363,10 @@ 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:
- case GL_RGBA16:
case GL_RGBA16F:
case GL_RGBA16I:
case GL_RGBA16UI:
@@ -335,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;
}
@@ -356,6 +398,7 @@ GLuint ofGetGLPolyMode(ofPolyRenderMode m){
break;
}
#else
+ ofLogError("ofGLUtils") << "ofGetGLPolyMode(): poly modes not supported in GLES";
return 0;
#endif
}
@@ -378,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
}
@@ -482,20 +526,20 @@ 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;
#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;
@@ -613,7 +657,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,21 +680,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
+#if !defined(TARGET_OPENGLES) || defined(GL_ES_VERSION_3_0)
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";
return 1;
@@ -730,7 +777,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/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/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/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..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
{
@@ -716,7 +720,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..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,7 +681,10 @@ class ofTexture : public ofBaseDraws {
///
void unbind(int textureLocation=0) const;
-#if !defined(TARGET_OPENGLES) && defined(glBindImageTexture)
+#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
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 c53e31666e8..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
@@ -209,13 +212,26 @@ enum ofTargetPlatform{
#ifdef TARGET_ANDROID
#include
#include
+
#include
- #define GL_GLEXT_PROTOTYPES
+ #define GL_GLEXT_PROTOTYPES
#include
- #include
- #include
-
+ #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
#define TARGET_LITTLE_ENDIAN
#endif
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/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
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