Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ 338babe8

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 338babe8 Leszek Koltunski
import org.distorted.library.main.DistortedNode;
33 dd1a65c1 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
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 338babe8 Leszek Koltunski
    private boolean mCreated;
45 af88bf2e Leszek Koltunski
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48
    void setScreenSize(int width, int height)
49
      {
50
      mScreenWidth = width;
51
      mScreenHeight= height;
52 dd1a65c1 Leszek Koltunski
      mObjectController.setScreenSize(width,height);
53 eb49fa90 Leszek Koltunski
      mObjectController.setMove( (int)(-0.5f*width*TutorialActivity.BAR_RATIO), 0);
54 338babe8 Leszek Koltunski
55
      if( !mCreated )
56
        {
57
        mCreated = true;
58
        mObjectController.createNode(width,height);
59
        DistortedNode objectNode = mObjectController.getNode();
60
        mRenderer.getScreen().attach(objectNode);
61
        }
62 af88bf2e Leszek Koltunski
      }
63
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
    boolean isVertical()
67
      {
68
      return mScreenHeight>mScreenWidth;
69
      }
70
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73 2afc6754 Leszek Koltunski
    ObjectControl getObjectControl()
74 af88bf2e Leszek Koltunski
      {
75 2afc6754 Leszek Koltunski
      return mObjectController;
76 af88bf2e Leszek Koltunski
      }
77
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
// PUBLIC API
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
82
    public TutorialSurfaceView(Context context, AttributeSet attrs)
83
      {
84
      super(context,attrs);
85
86 338babe8 Leszek Koltunski
      mCreated = false;
87
88 af88bf2e Leszek Koltunski
      if(!isInEditMode())
89
        {
90
        TutorialActivity act = (TutorialActivity)context;
91 e019c70b Leszek Koltunski
        TutorialObjectLibInterface ref = new TutorialObjectLibInterface(act);
92
        mObjectController = new ObjectControl(act,ref);
93 2afc6754 Leszek Koltunski
        mRenderer = new TutorialRenderer(this);
94 af88bf2e Leszek Koltunski
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 dd1a65c1 Leszek Koltunski
          crashlytics.setCustomKey("GL version"    , version );
116 af88bf2e Leszek Koltunski
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
117 dd1a65c1 Leszek Koltunski
          crashlytics.setCustomKey("GLSL renderer" , renderer);
118 af88bf2e Leszek Koltunski
          crashlytics.recordException(ex);
119
          }
120
        }
121
      }
122
123 c65a5efe Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
    @Override
126
    public void onPause()
127
      {
128
      super.onPause();
129
      mObjectController.onPause();
130
      }
131
132 eaf46415 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134 05c20dad Leszek Koltunski
    @Override
135
    public void onResume()
136 dd1a65c1 Leszek Koltunski
      {
137 05c20dad Leszek Koltunski
      super.onResume();
138 c65a5efe Leszek Koltunski
      mObjectController.onResume();
139 dd1a65c1 Leszek Koltunski
      }
140
141 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
142
143
    @Override
144
    public boolean onTouchEvent(MotionEvent event)
145
      {
146 dd1a65c1 Leszek Koltunski
      return mObjectController.onTouchEvent(event,MODE_ROTATE);
147 af88bf2e Leszek Koltunski
      }
148
}