Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikSurfaceView.java @ 1bafcba4

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.main;
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
import android.view.MotionEvent;
29

    
30
import com.google.firebase.crashlytics.FirebaseCrashlytics;
31

    
32
import org.distorted.library.type.Static4D;
33

    
34
import org.distorted.objectlib.main.ObjectControl;
35
import org.distorted.objectlib.main.ObjectPreRender;
36

    
37
import org.distorted.screens.ScreenList;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
public class RubikSurfaceView extends GLSurfaceView
42
{
43
    private ObjectControl mObjectController;
44
    private RubikRenderer mRenderer;
45
    private int mScreenWidth, mScreenHeight;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
    void setScreenSize(int width, int height)
50
      {
51
      mScreenWidth = width;
52
      mScreenHeight= height;
53
      mObjectController.setScreenSize(width,height);
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
    ObjectPreRender getPreRender()
73
      {
74
      return mObjectController.getPreRender();
75
      }
76

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

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

    
85
      if(!isInEditMode())
86
        {
87
        RubikActivity act = (RubikActivity)context;
88
        mRenderer = new RubikRenderer(this);
89
        mObjectController = new ObjectControl(act,new RubikObjectStateActioner());
90

    
91
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
92

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

    
104
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
105
          String version = GLES30.glGetString(GLES30.GL_VERSION);
106
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
107
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
108

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
    public Static4D getQuat()
122
      {
123
      return mObjectController.getQuat();
124
      }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
    @Override
129
    public void onResume()
130
      {
131
      super.onResume();
132
      mObjectController.initialize();
133
      }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
    @Override
138
    public boolean onTouchEvent(MotionEvent event)
139
      {
140
      int mode = ScreenList.getMode();
141
      return mObjectController.onTouchEvent(event,mode);
142
      }
143
}
144

    
(4-4/4)