Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ 1bafcba4

1 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 2971588c Leszek Koltunski
// Copyright 2020 Leszek Koltunski                                                               //
3 af88bf2e Leszek Koltunski
//                                                                                               //
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 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
21 af88bf2e Leszek Koltunski
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 dd1a65c1 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
33 eaf46415 Leszek Koltunski
import org.distorted.objectlib.main.ObjectPreRender;
34 af88bf2e Leszek Koltunski
35 dd1a65c1 Leszek Koltunski
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
36 b9d4aa3b Leszek Koltunski
37 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 1bafcba4 Leszek Koltunski
public class TutorialSurfaceView extends GLSurfaceView
40 af88bf2e Leszek Koltunski
{
41 dd1a65c1 Leszek Koltunski
    private ObjectControl mObjectController;
42 af88bf2e Leszek Koltunski
    private TutorialRenderer mRenderer;
43 dd1a65c1 Leszek Koltunski
    private int mScreenWidth, mScreenHeight;
44 af88bf2e Leszek Koltunski
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47
    void setScreenSize(int width, int height)
48
      {
49
      mScreenWidth = width;
50
      mScreenHeight= height;
51 dd1a65c1 Leszek Koltunski
      mObjectController.setScreenSize(width,height);
52 af88bf2e Leszek Koltunski
      }
53
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56
    boolean isVertical()
57
      {
58
      return mScreenHeight>mScreenWidth;
59
      }
60
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
63 dd1a65c1 Leszek Koltunski
    TutorialRenderer getRenderer()
64 af88bf2e Leszek Koltunski
      {
65 dd1a65c1 Leszek Koltunski
      return mRenderer;
66 af88bf2e Leszek Koltunski
      }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70 dd1a65c1 Leszek Koltunski
    ObjectPreRender getPreRender()
71 af88bf2e Leszek Koltunski
      {
72 dd1a65c1 Leszek Koltunski
      return mObjectController.getPreRender();
73 af88bf2e Leszek Koltunski
      }
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// PUBLIC API
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
    public TutorialSurfaceView(Context context, AttributeSet attrs)
80
      {
81
      super(context,attrs);
82
83
      if(!isInEditMode())
84
        {
85
        TutorialActivity act = (TutorialActivity)context;
86 dd1a65c1 Leszek Koltunski
        mRenderer = new TutorialRenderer(this);
87 1bafcba4 Leszek Koltunski
        mObjectController = new ObjectControl(act,new TutorialObjectStateActioner());
88 af88bf2e Leszek Koltunski
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 dd1a65c1 Leszek Koltunski
          crashlytics.setCustomKey("GL version"    , version );
110 af88bf2e Leszek Koltunski
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
111 dd1a65c1 Leszek Koltunski
          crashlytics.setCustomKey("GLSL renderer" , renderer);
112 af88bf2e Leszek Koltunski
          crashlytics.recordException(ex);
113
          }
114
        }
115
      }
116
117 eaf46415 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119 05c20dad Leszek Koltunski
    @Override
120
    public void onResume()
121 dd1a65c1 Leszek Koltunski
      {
122 05c20dad Leszek Koltunski
      super.onResume();
123 dd1a65c1 Leszek Koltunski
      mObjectController.initialize();
124
      }
125
126 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
127
128
    @Override
129
    public boolean onTouchEvent(MotionEvent event)
130
      {
131 dd1a65c1 Leszek Koltunski
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
132 af88bf2e Leszek Koltunski
      }
133
}