Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ c65a5efe

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.tutorials;
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.objectlib.main.ObjectControl;
33

    
34
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class TutorialSurfaceView extends GLSurfaceView
39
{
40
    private ObjectControl mObjectController;
41
    private TutorialRenderer mRenderer;
42
    private int mScreenWidth, mScreenHeight;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
    void setScreenSize(int width, int height)
47
      {
48
      mScreenWidth = width;
49
      mScreenHeight= height;
50
      mObjectController.setScreenSize(width,height);
51
      }
52

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

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

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

    
62
    TutorialRenderer getRenderer()
63
      {
64
      return mRenderer;
65
      }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
    ObjectControl getObjectControl()
70
      {
71
      return mObjectController;
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
// PUBLIC API
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
    public TutorialSurfaceView(Context context, AttributeSet attrs)
79
      {
80
      super(context,attrs);
81

    
82
      if(!isInEditMode())
83
        {
84
        TutorialActivity act = (TutorialActivity)context;
85
        TutorialObjectLibInterface ref = new TutorialObjectLibInterface(act);
86
        mObjectController = new ObjectControl(act,ref);
87
        mRenderer = new TutorialRenderer(this);
88

    
89
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
90

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

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

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

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
    @Override
120
    public void onPause()
121
      {
122
      super.onPause();
123
      mObjectController.onPause();
124
      }
125

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

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

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

    
137
    @Override
138
    public boolean onTouchEvent(MotionEvent event)
139
      {
140
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
141
      }
142
}
143

    
(6-6/7)