| 1 |
1237d25d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Magic Cube. //
|
| 5 |
|
|
// //
|
| 6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
| 7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
| 8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
| 9 |
|
|
// (at your option) any later version. //
|
| 10 |
|
|
// //
|
| 11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
| 12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
| 13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
| 14 |
|
|
// GNU General Public License for more details. //
|
| 15 |
|
|
// //
|
| 16 |
|
|
// You should have received a copy of the GNU General Public License //
|
| 17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
| 18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 19 |
|
|
|
| 20 |
|
|
package org.distorted.config;
|
| 21 |
|
|
|
| 22 |
|
|
import android.app.ActivityManager;
|
| 23 |
|
|
import android.content.Context;
|
| 24 |
|
|
import android.content.pm.ConfigurationInfo;
|
| 25 |
|
|
import android.opengl.GLES30;
|
| 26 |
|
|
import android.opengl.GLSurfaceView;
|
| 27 |
|
|
import android.util.AttributeSet;
|
| 28 |
|
|
|
| 29 |
|
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
| 30 |
|
|
|
| 31 |
|
|
import org.distorted.objectlib.main.ObjectControl;
|
| 32 |
|
|
import org.distorted.objectlib.main.TwistyObjectNode;
|
| 33 |
|
|
|
| 34 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 35 |
|
|
|
| 36 |
|
|
public class ConfigSurfaceView extends GLSurfaceView
|
| 37 |
|
|
{
|
| 38 |
|
|
private ObjectControl mObjectController;
|
| 39 |
|
|
private ConfigRenderer mRenderer;
|
| 40 |
|
|
private int mScreenWidth, mScreenHeight;
|
| 41 |
|
|
private boolean mCreated;
|
| 42 |
|
|
|
| 43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 44 |
|
|
|
| 45 |
|
|
void setScreenSize(int width, int height)
|
| 46 |
|
|
{
|
| 47 |
|
|
mScreenWidth = width;
|
| 48 |
|
|
mScreenHeight= height;
|
| 49 |
|
|
mObjectController.setScreenSize(width,height);
|
| 50 |
97a4ae23
|
Leszek Koltunski
|
mObjectController.setObjectScale(1.00f);
|
| 51 |
1237d25d
|
Leszek Koltunski
|
|
| 52 |
|
|
if( !mCreated )
|
| 53 |
|
|
{
|
| 54 |
|
|
mCreated = true;
|
| 55 |
|
|
mObjectController.createNode(width,height);
|
| 56 |
|
|
TwistyObjectNode objectNode = mObjectController.getNode();
|
| 57 |
|
|
mRenderer.getScreen().attach(objectNode);
|
| 58 |
|
|
}
|
| 59 |
|
|
}
|
| 60 |
|
|
|
| 61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 62 |
|
|
|
| 63 |
|
|
boolean isVertical()
|
| 64 |
|
|
{
|
| 65 |
|
|
return mScreenHeight>mScreenWidth;
|
| 66 |
|
|
}
|
| 67 |
|
|
|
| 68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 69 |
|
|
|
| 70 |
|
|
ObjectControl getObjectControl()
|
| 71 |
|
|
{
|
| 72 |
|
|
return mObjectController;
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 76 |
|
|
// PUBLIC API
|
| 77 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 78 |
|
|
|
| 79 |
|
|
public ConfigSurfaceView(Context context, AttributeSet attrs)
|
| 80 |
|
|
{
|
| 81 |
|
|
super(context,attrs);
|
| 82 |
|
|
|
| 83 |
|
|
mCreated = false;
|
| 84 |
|
|
|
| 85 |
|
|
if(!isInEditMode())
|
| 86 |
|
|
{
|
| 87 |
|
|
ConfigActivity act = (ConfigActivity)context;
|
| 88 |
|
|
ConfigObjectLibInterface ref = new ConfigObjectLibInterface();
|
| 89 |
|
|
mObjectController = new ObjectControl(act,ref);
|
| 90 |
45516ed2
|
Leszek Koltunski
|
mObjectController.setRotateOnCreation(true);
|
| 91 |
1237d25d
|
Leszek Koltunski
|
mRenderer = new ConfigRenderer(this);
|
| 92 |
|
|
|
| 93 |
|
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| 94 |
|
|
|
| 95 |
|
|
try
|
| 96 |
|
|
{
|
| 97 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
| 98 |
|
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
| 99 |
|
|
setEGLContextClientVersion(esVersion);
|
| 100 |
|
|
setRenderer(mRenderer);
|
| 101 |
|
|
}
|
| 102 |
|
|
catch(Exception ex)
|
| 103 |
|
|
{
|
| 104 |
|
|
act.OpenGLError();
|
| 105 |
|
|
|
| 106 |
|
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
| 107 |
|
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
| 108 |
|
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
| 109 |
|
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
| 110 |
|
|
|
| 111 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
| 112 |
|
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
| 113 |
|
|
crashlytics.setCustomKey("GL version" , version );
|
| 114 |
|
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
| 115 |
|
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
| 116 |
|
|
crashlytics.recordException(ex);
|
| 117 |
|
|
}
|
| 118 |
|
|
}
|
| 119 |
|
|
}
|
| 120 |
|
|
|
| 121 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 122 |
|
|
|
| 123 |
|
|
@Override
|
| 124 |
|
|
public void onPause()
|
| 125 |
|
|
{
|
| 126 |
|
|
super.onPause();
|
| 127 |
|
|
mObjectController.onPause();
|
| 128 |
|
|
}
|
| 129 |
|
|
|
| 130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 131 |
|
|
|
| 132 |
|
|
@Override
|
| 133 |
|
|
public void onResume()
|
| 134 |
|
|
{
|
| 135 |
|
|
super.onResume();
|
| 136 |
|
|
mObjectController.onResume();
|
| 137 |
|
|
}
|
| 138 |
|
|
}
|