Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikRenderer.java @ 31911113

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.opengl.GLES30;
23
import android.opengl.GLSurfaceView;
24

    
25
import org.distorted.effects.BaseEffect;
26
import org.distorted.library.effect.VertexEffectSink;
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedScreen;
29

    
30
import javax.microedition.khronos.egl.EGLConfig;
31
import javax.microedition.khronos.opengles.GL10;
32

    
33
import com.google.firebase.crashlytics.FirebaseCrashlytics;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class RubikRenderer implements GLSurfaceView.Renderer
38
{
39
   private RubikSurfaceView mView;
40
   private DistortedScreen mScreen;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
   RubikRenderer(RubikSurfaceView v)
45
     {
46
     mView = v;
47
     mScreen = new DistortedScreen();
48
     }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
// various things are done here delayed, 'after the next render' as not to be done mid-render and
52
// cause artifacts.
53

    
54
   @Override
55
   public void onDrawFrame(GL10 glUnused)
56
     {
57
     mScreen.render( System.currentTimeMillis() );
58
     mView.getPostRender().postRender();
59
     }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
   @Override
64
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
65
      {
66
      mScreen.resize(width,height);
67
      mView.setScreenSize(width,height);
68
      mView.getPostRender().setScreenSize(width,height);
69
      }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
   @Override
74
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
75
      {
76
      VertexEffectSink.enable();
77
      BaseEffect.Type.enableEffects();
78

    
79
      try
80
        {
81
        DistortedLibrary.onCreate(mView.getContext());
82
        }
83
      catch(Exception ex)
84
        {
85
        String message = ex.getMessage();
86
        String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
87
        String version = GLES30.glGetString(GLES30.GL_VERSION);
88
        String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
89
        String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
90

    
91
        if( message==null ) message = "exception NULL";
92

    
93
        if( BuildConfig.DEBUG )
94
          {
95
          android.util.Log.e("DISTORTED", message );
96
          android.util.Log.e("DISTORTED", "GLSL Version "+shading);
97
          android.util.Log.e("DISTORTED", "GL Version "  +version);
98
          android.util.Log.e("DISTORTED", "GL Vendor "   +vendor);
99
          android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
100
          }
101
        else
102
          {
103
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
104
          crashlytics.setCustomKey("DistortedError", message );
105
          crashlytics.setCustomKey("GLSLversion"   , shading );
106
          crashlytics.setCustomKey("GLversion"     , version );
107
          crashlytics.setCustomKey("GLSLvendor"    , vendor  );
108
          crashlytics.setCustomKey("GLSLrenderer"  , renderer);
109
          }
110
        }
111
      }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
   DistortedScreen getScreen()
116
     {
117
     return mScreen;
118
     }
119
}
(3-3/4)