Project

General

Profile

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

magiccube / src / main / java / org / distorted / purchase / PurchaseSurfaceView.java @ 9a39aabf

1 c7238c67 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.purchase;
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
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
26
public class PurchaseSurfaceView extends GLSurfaceView
27
{
28
    private ObjectControl mObjectController;
29
    private PurchaseRenderer mRenderer;
30
    private boolean mCreated;
31
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34
    void setScreenSize(int width, int height)
35
      {
36 b1178f5f Leszek Koltunski
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
37 c7238c67 Leszek Koltunski
      mObjectController.setObjectScale(1.00f);
38
39
      if( !mCreated )
40
        {
41
        mCreated = true;
42
        mObjectController.createNode(width,height);
43
        TwistyObjectNode objectNode = mObjectController.getNode();
44
        mRenderer.getScreen().attach(objectNode);
45
        }
46
      }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50 f8e8a08e Leszek Koltunski
    ObjectControl getObjectControl()
51 c7238c67 Leszek Koltunski
      {
52 f8e8a08e Leszek Koltunski
      return mObjectController;
53 c7238c67 Leszek Koltunski
      }
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57 f8e8a08e Leszek Koltunski
    PurchaseRenderer getRenderer()
58 c7238c67 Leszek Koltunski
      {
59 f8e8a08e Leszek Koltunski
      return mRenderer;
60 c7238c67 Leszek Koltunski
      }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
// PUBLIC API
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
    public PurchaseSurfaceView(Context context, AttributeSet attrs)
67
      {
68
      super(context,attrs);
69
70
      mCreated = false;
71
72
      if(!isInEditMode())
73
        {
74
        PurchaseActivity act = (PurchaseActivity)context;
75
        PurchaseObjectLibInterface ref = new PurchaseObjectLibInterface();
76
        mObjectController = new ObjectControl(act,ref);
77
        mObjectController.setRotateOnCreation(true);
78
        mRenderer = new PurchaseRenderer(this);
79
80
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
81
82
        try
83
          {
84
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
85
          int esVersion = configurationInfo.reqGlEsVersion>>16;
86
          setEGLContextClientVersion(esVersion);
87
          setRenderer(mRenderer);
88
          }
89
        catch(Exception ex)
90
          {
91
          act.OpenGLError();
92
93
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
94
          String version = GLES30.glGetString(GLES30.GL_VERSION);
95
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
96
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
97
98
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
99
          crashlytics.setCustomKey("GLSL Version"  , shading );
100
          crashlytics.setCustomKey("GL version"    , version );
101
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
102
          crashlytics.setCustomKey("GLSL renderer" , renderer);
103
          crashlytics.recordException(ex);
104
          }
105
        }
106
      }
107
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110
    @Override
111
    public void onPause()
112
      {
113
      super.onPause();
114
      mObjectController.onPause();
115
      }
116
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119
    @Override
120
    public void onResume()
121
      {
122
      super.onResume();
123
      mObjectController.onResume();
124
      }
125
}