Project

General

Profile

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

magiccube / src / main / java / org / distorted / purchase / PurchaseSurfaceView.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.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
import org.distorted.os.OSInterface;
24

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

    
27
public class PurchaseSurfaceView extends GLSurfaceView
28
{
29
    private ObjectControl mObjectController;
30
    private OSInterface mInterface;
31
    private PurchaseRenderer mRenderer;
32
    private boolean mCreated;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
    void setScreenSize(int width, int height)
37
      {
38
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height));
39
      mObjectController.setObjectScale(1.00f);
40

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

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
    ObjectControl getObjectControl()
53
      {
54
      return mObjectController;
55
      }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
    PurchaseRenderer getRenderer()
60
      {
61
      return mRenderer;
62
      }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
// PUBLIC API
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
    public PurchaseSurfaceView(Context context, AttributeSet attrs)
69
      {
70
      super(context,attrs);
71

    
72
      mCreated = false;
73

    
74
      if(!isInEditMode())
75
        {
76
        PurchaseActivity act = (PurchaseActivity)context;
77
        PurchaseObjectLibInterface ref = new PurchaseObjectLibInterface();
78
        mInterface = new OSInterface(act,ref);
79
        mObjectController = new ObjectControl(mInterface);
80
        mObjectController.setRotateOnCreation(true);
81
        mRenderer = new PurchaseRenderer(this);
82

    
83
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
84

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

    
96
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
97
          String version = GLES30.glGetString(GLES30.GL_VERSION);
98
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
99
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
100

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

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
    @Override
114
    public void onPause()
115
      {
116
      super.onPause();
117
      mObjectController.onPause();
118
      }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
    @Override
123
    public void onResume()
124
      {
125
      super.onResume();
126
      mObjectController.onResume();
127
      }
128
}
129

    
(6-6/6)