Project

General

Profile

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

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

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.library.main.DistortedScreen;
33
import org.distorted.library.type.Static4D;
34

    
35
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.helpers.ObjectSurfaceView;
37
import org.distorted.objectlib.helpers.TwistyActivity;
38
import org.distorted.objectlib.main.Movement;
39
import org.distorted.objectlib.main.ObjectPreRender;
40

    
41
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
public class TutorialSurfaceView extends GLSurfaceView implements ObjectSurfaceView
46
{
47
    private ObjectControl mObjectController;
48
    private TutorialRenderer mRenderer;
49
    private int mScreenWidth, mScreenHeight;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
    void setScreenSize(int width, int height)
54
      {
55
      mScreenWidth = width;
56
      mScreenHeight= height;
57
      mObjectController.setScreenSize(width,height);
58
      }
59

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

    
62
    boolean isVertical()
63
      {
64
      return mScreenHeight>mScreenWidth;
65
      }
66

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

    
69
    TutorialRenderer getRenderer()
70
      {
71
      return mRenderer;
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
    ObjectPreRender getPreRender()
77
      {
78
      return mObjectController.getPreRender();
79
      }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// PUBLIC API
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
    public TutorialSurfaceView(Context context, AttributeSet attrs)
86
      {
87
      super(context,attrs);
88

    
89
      if(!isInEditMode())
90
        {
91
        TutorialActivity act = (TutorialActivity)context;
92
        mRenderer = new TutorialRenderer(this);
93
        mObjectController = new ObjectControl(act,this,new TutorialObjectStateActioner());
94

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

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

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

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

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
    public void setMovement(Movement movement)
126
      {
127
      mObjectController.setMovement(movement);
128
      }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
    public void setQuat()
133
      {
134
      mObjectController.setQuat();
135
      }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
    public Static4D getQuat()
140
      {
141
      return mObjectController.getQuat();
142
      }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
    public TwistyActivity getActivity()
147
      {
148
      return (TwistyActivity)getContext();
149
      }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
    public DistortedScreen getScreen()
154
      {
155
      return mRenderer.getScreen();
156
      }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
    public void initialize()
161
      {
162
      mObjectController.initialize();
163
      }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
    @Override
168
    public boolean onTouchEvent(MotionEvent event)
169
      {
170
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
171
      }
172
}
173

    
(6-6/7)