Project

General

Profile

Download (4.76 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / config / ConfigSurfaceView.java @ 88451205

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.config;
11

    
12
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.opengl.GLES30;
16
import android.opengl.GLSurfaceView;
17
import android.util.AttributeSet;
18

    
19
import com.google.firebase.crashlytics.FirebaseCrashlytics;
20

    
21
import org.distorted.objectlib.main.ObjectControl;
22
import org.distorted.objectlib.main.TwistyObjectNode;
23
import org.distorted.os.OSInterface;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class ConfigSurfaceView extends GLSurfaceView
28
{
29
    private ObjectControl mObjectController;
30
    private OSInterface mInterface;
31
    private ConfigRenderer mRenderer;
32
    private int mScreenWidth, mScreenHeight;
33
    private boolean mCreated;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
    void setScreenSize(int width, int height)
38
      {
39
      mScreenWidth = width;
40
      mScreenHeight= height;
41
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
42
      mObjectController.setObjectScale(1.00f);
43

    
44
      if( !mCreated )
45
        {
46
        mCreated = true;
47
        mObjectController.createNode(width,height);
48
        TwistyObjectNode objectNode = mObjectController.getNode();
49
        mRenderer.getScreen().attach(objectNode);
50
        }
51
      }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
    boolean isVertical()
56
      {
57
      return mScreenHeight>mScreenWidth;
58
      }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
    ObjectControl getObjectControl()
63
      {
64
      return mObjectController;
65
      }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
// PUBLIC API
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
    public ConfigSurfaceView(Context context, AttributeSet attrs)
72
      {
73
      super(context,attrs);
74

    
75
      mCreated = false;
76

    
77
      if(!isInEditMode())
78
        {
79
        ConfigActivity act = (ConfigActivity)context;
80
        ConfigObjectLibInterface ref = new ConfigObjectLibInterface();
81
        mInterface = new OSInterface(act,ref);
82
        mObjectController = new ObjectControl(mInterface);
83
        mObjectController.setRotateOnCreation(true);
84
        mRenderer = new ConfigRenderer(this);
85

    
86
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
87

    
88
        try
89
          {
90
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
91
          int esVersion = configurationInfo.reqGlEsVersion>>16;
92
          setEGLContextClientVersion(esVersion);
93
          setRenderer(mRenderer);
94
          }
95
        catch(Exception ex)
96
          {
97
          act.OpenGLError();
98

    
99
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
100
          String version = GLES30.glGetString(GLES30.GL_VERSION);
101
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
102
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
103

    
104
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
105
          crashlytics.setCustomKey("GLSL Version"  , shading );
106
          crashlytics.setCustomKey("GL version"    , version );
107
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
108
          crashlytics.setCustomKey("GLSL renderer" , renderer);
109
          crashlytics.recordException(ex);
110
          }
111
        }
112
      }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
    @Override
117
    public void onPause()
118
      {
119
      super.onPause();
120
      mObjectController.onPause();
121
      }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
    @Override
126
    public void onResume()
127
      {
128
      super.onResume();
129
      mObjectController.onResume();
130
      }
131
}
132

    
(6-6/6)