Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ b4cbe056

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.main;
11

    
12
import android.annotation.SuppressLint;
13
import android.app.ActivityManager;
14
import android.content.Context;
15
import android.content.pm.ConfigurationInfo;
16
import android.opengl.GLES30;
17
import android.opengl.GLSurfaceView;
18
import android.util.AttributeSet;
19
import android.view.MotionEvent;
20

    
21
import com.google.firebase.crashlytics.FirebaseCrashlytics;
22

    
23
import org.distorted.objectlib.main.ObjectControl;
24
import org.distorted.objectlib.main.TwistyObjectNode;
25

    
26
import org.distorted.screens.ScreenList;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class RubikSurfaceView extends GLSurfaceView
31
{
32
    private ObjectControl mObjectController;
33
    private RubikRenderer mRenderer;
34
    private int mScreenWidth, mScreenHeight;
35
    private boolean mCreated;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
    void setScreenSize(int width, int height)
40
      {
41
      mScreenWidth = width;
42
      mScreenHeight= height;
43
      mObjectController.setScreenSize(width,height);
44

    
45
      if( !mCreated )
46
        {
47
        mCreated = true;
48
        mObjectController.createNode(width,height);
49
        TwistyObjectNode objectNode = mObjectController.getNode();
50
        objectNode.glDepthMask(false);
51
        objectNode.glStencilMask(0);
52
        mRenderer.getScreen().attach(objectNode);
53
        }
54
      }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
    boolean isVertical()
59
      {
60
      return mScreenHeight>mScreenWidth;
61
      }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
    RubikRenderer getRenderer()
66
      {
67
      return mRenderer;
68
      }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
    ObjectControl getObjectControl()
73
      {
74
      return mObjectController;
75
      }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// PUBLIC API
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
    public RubikSurfaceView(Context context, AttributeSet attrs)
82
      {
83
      super(context,attrs);
84

    
85
      mCreated = false;
86

    
87
      if(!isInEditMode())
88
        {
89
        RubikActivity act = (RubikActivity)context;
90
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
91
        mObjectController = new ObjectControl(act,ref);
92
        mRenderer = new RubikRenderer(this);
93

    
94
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
95

    
96
        try
97
          {
98
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
99
          int esVersion = configurationInfo.reqGlEsVersion>>16;
100
          setEGLContextClientVersion(esVersion);
101
          setRenderer(mRenderer);
102
          }
103
        catch(Exception ex)
104
          {
105
          act.OpenGLError();
106

    
107
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
108
          String version = GLES30.glGetString(GLES30.GL_VERSION);
109
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
110
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
111

    
112
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
113
          crashlytics.setCustomKey("GLSL Version"  , shading );
114
          crashlytics.setCustomKey("GL version"    , version );
115
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
116
          crashlytics.setCustomKey("GLSL renderer" , renderer);
117
          crashlytics.recordException(ex);
118
          }
119
        }
120
      }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
    @Override
125
    public void onPause()
126
      {
127
      super.onPause();
128
      mObjectController.onPause();
129
      }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
    @Override
134
    public void onResume()
135
      {
136
      super.onResume();
137
      mObjectController.onResume();
138
      }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
    @SuppressLint("ClickableViewAccessibility")
143
    @Override
144
    public boolean onTouchEvent(MotionEvent event)
145
      {
146
      int mode = ScreenList.getMode();
147
      return mObjectController.onTouchEvent(event,mode);
148
      }
149
}
150

    
(4-4/4)