Skip to content

Commit

Permalink
Fixed selection of GLES version on android. (#6088)
Browse files Browse the repository at this point in the history
Fixes #6086 
Fixes #6047
  • Loading branch information
ivorne authored and arturoc committed Jul 31, 2018
1 parent b3a250a commit 432b122
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public void onUnpackingResourcesDone(){}
//gesture handler member
private ViewGroup mOFGlSurfaceContainer;

public ViewGroup getSurfaceContainer(){
return mOFGlSurfaceContainer;
}

public void initView(){
String packageName = this.getPackageName();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.concurrent.Semaphore;

public class OFAndroid {

Expand Down Expand Up @@ -822,13 +823,22 @@ public static void disableOrientationChangeEvents(){

public static void setupGL(int version){
final int finalversion = version;
final Semaphore mutex = new Semaphore( 0 );

runOnMainThread(new Runnable() {

@Override
public void run() {
OFEGLConfigChooser.setGLESVersion(finalversion);
OFAndroidLifeCycle.glCreateSurface();
mutex.release();
}
});

try{
mutex.acquire();
} catch( Exception ex ){
Log.w( "OF", "setupGL mutex acquire failed" );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,51 +262,63 @@ public static void init()
}

static String TAG = "OF";

public static void glCreate()
{
{
Log.d(TAG, "glCreate");

if(m_countActivities == 0)
pushState(State.create);
m_countActivities++;
}

public static void glCreateSurface()
{
if(mGLView == null)
{
Log.d(TAG, "Create surface");
mGLView = new OFGLSurfaceView(m_activity);

glResume( getActivity().getSurfaceContainer() );
}
if(m_countActivities == 0)
pushState(State.create);
m_countActivities++;
}

public static void glResume(ViewGroup glContainer)
{
Log.d(TAG, "glResume");

OFGLSurfaceView glView = getGLView();
glView.setVisibility(View.INVISIBLE);
if( glView != null )
{
glView.setVisibility(View.INVISIBLE);

glContainer.addView(glView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Log.d(TAG, "addView surface");

glContainer.addView(glView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Log.d(TAG, "addView surface");

glView.onResume();

pushState(State.resume);
glView.onResume();

pushState(State.resume);
}
}

public static void glPause()
{
Log.d(TAG, "glPause");

OFGLSurfaceView glView = getGLView();

glView.onPause();

ViewGroup parent = (ViewGroup)glView.getParent();

if(parent != null){
Log.d(TAG, "remove surface");
parent.removeView(glView);
if( glView != null )
{
glView.onPause();

ViewGroup parent = (ViewGroup)glView.getParent();

if(parent != null){
Log.d(TAG, "remove surface");
parent.removeView(glView);
}

pushState(State.pause);
}

pushState(State.pause);
}

public static void glDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public OFEGLConfigChooser(int r, int g, int b, int a, int depth, int stencil) {
}

public static void setGLESVersion(int version){
GLES_VERSION = version;

if(version==1) EGL_OPENGL_ES_BIT=1;
else EGL_OPENGL_ES_BIT=4;
}

public static int getGLESVersion(){
return EGL_OPENGL_ES_BIT==1?1:2;
return GLES_VERSION;
}

/* This EGL config specification is used to specify 1.x rendering.
Expand All @@ -39,6 +41,7 @@ public static int getGLESVersion(){
*/
private static boolean DEBUG = false;
private static int EGL_OPENGL_ES_BIT = 1;
private static int GLES_VERSION = 1;
private static int[] s_configAttribs2 =
{
EGL10.EGL_RED_SIZE, 4,
Expand Down Expand Up @@ -220,8 +223,8 @@ class OFGLSurfaceView extends GLSurfaceView{
public OFGLSurfaceView(Context context) {
super(context);
mRenderer = new OFAndroidWindow(getWidth(),getHeight());
if(OFEGLConfigChooser.getGLESVersion()==2){
setEGLContextClientVersion(2);
if(OFEGLConfigChooser.getGLESVersion()>=2){
setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersion());
}
getHolder().setFormat( PixelFormat.OPAQUE );
OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0);
Expand All @@ -233,8 +236,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);
if(OFEGLConfigChooser.getGLESVersion()>=2){
setEGLContextClientVersion(OFEGLConfigChooser.getGLESVersion());
}
getHolder().setFormat( PixelFormat.OPAQUE );
OFEGLConfigChooser configChooser = new OFEGLConfigChooser(8,8,8,0,16,0);
Expand Down
23 changes: 14 additions & 9 deletions addons/ofxAndroid/src/ofAppAndroidWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ shared_ptr<ofBaseRenderer> & ofAppAndroidWindow::renderer(){
return currentRenderer;
}

int ofAppAndroidWindow::getGlesVersion()
{
return glesVersion;
}

extern "C"{

jint JNI_OnLoad(JavaVM* vm, void* reserved)
Expand Down Expand Up @@ -323,15 +328,15 @@ Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv* env, jclass thiz ){
window->renderer()->popStyle();

}else{

if(window->renderer()->getType()==ofGLProgrammableRenderer::TYPE)
{
static_cast<ofGLProgrammableRenderer*>(window->renderer().get())->setup(2,0);
}
else
{
static_cast<ofGLRenderer*>(window->renderer().get())->setup();
}
int glesVersion = window->getGlesVersion();
if( glesVersion < 2 )
{
static_cast<ofGLRenderer*>(window->renderer().get())->setup();
}
else
{
static_cast<ofGLProgrammableRenderer*>(window->renderer().get())->setup(glesVersion,0);
}
}

surfaceDestroyed = false;
Expand Down
2 changes: 2 additions & 0 deletions addons/ofxAndroid/src/ofAppAndroidWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class ofAppAndroidWindow: public ofAppBaseGLESWindow {
void setThreadedEvents(bool threadedEvents);
void setAccumulateTouchEvents(bool accumEvents);

int getGlesVersion();

private:
ofCoreEvents coreEvents;
std::shared_ptr<ofBaseRenderer> currentRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,4 @@ ext {
javaDependencies = this.&javaDependencies


}
}

0 comments on commit 432b122

Please sign in to comment.