Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikRenderer.java @ 13ce05cc

1 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4 fdec60a3 Leszek Koltunski
// This file is part of Magic Cube.                                                              //
5 0c52af30 Leszek Koltunski
//                                                                                               //
6 fdec60a3 Leszek Koltunski
// Magic Cube is free software: you can redistribute it and/or modify                            //
7 0c52af30 Leszek Koltunski
// 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 fdec60a3 Leszek Koltunski
// Magic Cube is distributed in the hope that it will be useful,                                 //
12 0c52af30 Leszek Koltunski
// 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 fdec60a3 Leszek Koltunski
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 1f9772f3 Leszek Koltunski
package org.distorted.main;
21 0c52af30 Leszek Koltunski
22 31911113 Leszek Koltunski
import android.opengl.GLES30;
23 0c52af30 Leszek Koltunski
import android.opengl.GLSurfaceView;
24 31911113 Leszek Koltunski
25 1f9772f3 Leszek Koltunski
import org.distorted.effects.BaseEffect;
26 40ab026e Leszek Koltunski
import org.distorted.library.effect.EffectType;
27 e1111500 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
28 0c52af30 Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
29
30
import javax.microedition.khronos.egl.EGLConfig;
31
import javax.microedition.khronos.opengles.GL10;
32
33 31911113 Leszek Koltunski
import com.google.firebase.crashlytics.FirebaseCrashlytics;
34
35 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 8becce57 Leszek Koltunski
public class RubikRenderer implements GLSurfaceView.Renderer
38 0c52af30 Leszek Koltunski
{
39 8becce57 Leszek Koltunski
   private RubikSurfaceView mView;
40
   private DistortedScreen mScreen;
41 47ba5ddc Leszek Koltunski
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44 8becce57 Leszek Koltunski
   RubikRenderer(RubikSurfaceView v)
45 47ba5ddc Leszek Koltunski
     {
46 14bd7976 Leszek Koltunski
     final float BRIGHTNESS = 0.1f;
47
48 8becce57 Leszek Koltunski
     mView = v;
49
     mScreen = new DistortedScreen();
50 14bd7976 Leszek Koltunski
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
51 47ba5ddc Leszek Koltunski
     }
52
53 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
54
// various things are done here delayed, 'after the next render' as not to be done mid-render and
55
// cause artifacts.
56
57 a7a7cc9c Leszek Koltunski
   @Override
58
   public void onDrawFrame(GL10 glUnused)
59
     {
60
     mScreen.render( System.currentTimeMillis() );
61 8becce57 Leszek Koltunski
     mView.getPostRender().postRender();
62 a7a7cc9c Leszek Koltunski
     }
63 0c52af30 Leszek Koltunski
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65 aa8b36aa Leszek Koltunski
66
   @Override
67
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
68
      {
69 8becce57 Leszek Koltunski
      mScreen.resize(width,height);
70 123d6172 Leszek Koltunski
      mView.setScreenSize(width,height);
71 8becce57 Leszek Koltunski
      mView.getPostRender().setScreenSize(width,height);
72 aa8b36aa Leszek Koltunski
      }
73
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76
   @Override
77
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
78
      {
79 14bd7976 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX,15);
80 64975793 Leszek Koltunski
      BaseEffect.Type.enableEffects();
81 aa8b36aa Leszek Koltunski
82
      try
83
        {
84
        DistortedLibrary.onCreate(mView.getContext());
85
        }
86
      catch(Exception ex)
87
        {
88 31911113 Leszek Koltunski
        String message = ex.getMessage();
89
        String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
90
        String version = GLES30.glGetString(GLES30.GL_VERSION);
91
        String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
92
        String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
93
94
        if( message==null ) message = "exception NULL";
95
96
        if( BuildConfig.DEBUG )
97
          {
98
          android.util.Log.e("DISTORTED", message );
99
          android.util.Log.e("DISTORTED", "GLSL Version "+shading);
100
          android.util.Log.e("DISTORTED", "GL Version "  +version);
101
          android.util.Log.e("DISTORTED", "GL Vendor "   +vendor);
102
          android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
103
          }
104
        else
105
          {
106
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
107 1ef09d49 Leszek Koltunski
          crashlytics.setCustomKey("DistortedError", message );
108
          crashlytics.setCustomKey("GLSL Version"  , shading );
109
          crashlytics.setCustomKey("GLversion"     , version );
110
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
111
          crashlytics.setCustomKey("GLSLrenderer"  , renderer);
112
          crashlytics.recordException(ex);
113 31911113 Leszek Koltunski
          }
114 aa8b36aa Leszek Koltunski
        }
115
      }
116
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118 0c52af30 Leszek Koltunski
119 8becce57 Leszek Koltunski
   DistortedScreen getScreen()
120 434f2f5a Leszek Koltunski
     {
121 64975793 Leszek Koltunski
     return mScreen;
122 434f2f5a Leszek Koltunski
     }
123 0c52af30 Leszek Koltunski
}