Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions addons/ofxAndroid/ofAndroidLib/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.openframeworks.cc">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="20" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -213,16 +227,17 @@ 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];
}

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);
Expand All @@ -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);
Expand Down
72 changes: 49 additions & 23 deletions addons/ofxAndroid/src/ofAppAndroidWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;

}

Expand All @@ -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<ofGLRenderer>(this);
}else{
}else
#endif
currentRenderer = make_shared<ofGLProgrammableRenderer>(this);
}

jclass javaClass = ofGetJNIEnv()->FindClass("cc/openframeworks/OFAndroid");

Expand All @@ -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<ofGLProgrammableRenderer*>(currentRenderer.get())->setup(settings.glesVersion,0);
}else{
static_cast<ofGLRenderer*>(currentRenderer.get())->setup();
}
ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,sGLESVersionMajor,sGLESVersionMinor);
/*
if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){
static_cast<ofGLProgrammableRenderer*>(currentRenderer.get())->setup(settings.glesVersionMajor(),settings.glesVersionMinor());
}else{
static_cast<ofGLRenderer*>(currentRenderer.get())->setup();
}
*/
}

void ofAppAndroidWindow::update(){
Expand Down Expand Up @@ -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);
Expand All @@ -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<ofGLProgrammableRenderer*>(window->renderer().get())->setup(2,0);
}else{
static_cast<ofGLRenderer*>(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<ofGLProgrammableRenderer*>(window->renderer().get())->setup(sGLESVersionMajor,sGLESVersionMinor);
ofLogNotice() << "programmable renderer created";
}else{
if(! appSetup) {
static_cast<ofGLRenderer*>(window->renderer().get())->setup();
ofLogNotice() << "renderer created";
}
}
}

void
Expand Down
2 changes: 2 additions & 0 deletions addons/ofxAndroid/src/ofxAndroidVideoGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions addons/ofxAndroid/src/ofxAndroidVideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions examples/android/androidEmptyExample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
android:versionName="1.0"
android:installLocation="preferExternal">

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

<application
Expand Down
4 changes: 0 additions & 4 deletions examples/android/androidPolygonExample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
android:versionName="1.0"
android:installLocation="preferExternal">

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

<application
Expand Down
1 change: 1 addition & 0 deletions examples/android/androidShaderExample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-feature android:glEsVersion="0x00030001"/>

<application
android:allowBackup="true"
Expand Down
27 changes: 15 additions & 12 deletions libs/openFrameworks/app/ofAppEGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -482,15 +485,15 @@ void ofAppEGLWindow::setup(const Settings & _settings) {

nFramesSinceWindowResized = 0;

if(settings.glesVersion>1){
if(settings.glesVersionMajor()>1){
currentRenderer = make_shared<ofGLProgrammableRenderer>(this);
}else{
currentRenderer = make_shared<ofGLRenderer>(this);
}

makeCurrent();
if(currentRenderer->getType()==ofGLProgrammableRenderer::TYPE){
static_cast<ofGLProgrammableRenderer*>(currentRenderer.get())->setup(settings.glesVersion,0);
static_cast<ofGLProgrammableRenderer*>(currentRenderer.get())->setup(settings.glesVersionMajor(),settings.glesVersionMinor());
}else{
static_cast<ofGLRenderer*>(currentRenderer.get())->setup();
}
Expand Down Expand Up @@ -560,7 +563,7 @@ bool ofAppEGLWindow::createSurface() {
// success!
}

EGLint glesVersion;
EGLint glesVersionBit;
int glesVersionForContext;

if(ofGetCurrentRenderer()) {
Expand All @@ -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";
}
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion libs/openFrameworks/app/ofAppEGLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion libs/openFrameworks/app/ofAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading