Project

General

Profile

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

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

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 98904e45 Leszek Koltunski
import org.distorted.library.effect.VertexEffectQuaternion;
28 27e6c301 Leszek Koltunski
import org.distorted.library.effect.VertexEffectRotate;
29 e1111500 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
30 0c52af30 Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
31
32
import javax.microedition.khronos.egl.EGLConfig;
33
import javax.microedition.khronos.opengles.GL10;
34
35 31911113 Leszek Koltunski
import com.google.firebase.crashlytics.FirebaseCrashlytics;
36
37 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 c1df2105 Leszek Koltunski
public class RubikRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
40 0c52af30 Leszek Koltunski
{
41 8becce57 Leszek Koltunski
   private RubikSurfaceView mView;
42
   private DistortedScreen mScreen;
43 47ba5ddc Leszek Koltunski
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46 8becce57 Leszek Koltunski
   RubikRenderer(RubikSurfaceView v)
47 47ba5ddc Leszek Koltunski
     {
48 14bd7976 Leszek Koltunski
     final float BRIGHTNESS = 0.1f;
49
50 8becce57 Leszek Koltunski
     mView = v;
51
     mScreen = new DistortedScreen();
52 14bd7976 Leszek Koltunski
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
53 47ba5ddc Leszek Koltunski
     }
54
55 0c52af30 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
56
// various things are done here delayed, 'after the next render' as not to be done mid-render and
57
// cause artifacts.
58
59 a7a7cc9c Leszek Koltunski
   @Override
60
   public void onDrawFrame(GL10 glUnused)
61
     {
62 5a4d4fba Leszek Koltunski
     mView.getPreRender().preRender();
63 a7a7cc9c Leszek Koltunski
     mScreen.render( System.currentTimeMillis() );
64
     }
65 0c52af30 Leszek Koltunski
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67 aa8b36aa Leszek Koltunski
68
   @Override
69
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
70
      {
71 8becce57 Leszek Koltunski
      mScreen.resize(width,height);
72 123d6172 Leszek Koltunski
      mView.setScreenSize(width,height);
73 5a4d4fba Leszek Koltunski
      mView.getPreRender().setScreenSize(width,height);
74 aa8b36aa Leszek Koltunski
      }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
78
   @Override
79
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
80
      {
81 10585385 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX,25);    // 24 Cube Quats + Rotate
82 27e6c301 Leszek Koltunski
      VertexEffectRotate.enable();
83 98904e45 Leszek Koltunski
      VertexEffectQuaternion.enable();
84 64975793 Leszek Koltunski
      BaseEffect.Type.enableEffects();
85 aa8b36aa Leszek Koltunski
86 c1df2105 Leszek Koltunski
      DistortedLibrary.onCreate(mView.getContext(),this,1);
87 aa8b36aa Leszek Koltunski
      }
88
89 c1df2105 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
90
91
   public void distortedException(Exception ex)
92
     {
93
     String message = ex.getMessage();
94
     String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
95
     String version = GLES30.glGetString(GLES30.GL_VERSION);
96
     String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
97
     String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
98
99
     if( message==null ) message = "exception NULL";
100
101
     if( BuildConfig.DEBUG )
102
       {
103
       android.util.Log.e("DISTORTED", message );
104
       android.util.Log.e("DISTORTED", "GLSL Version "+shading);
105
       android.util.Log.e("DISTORTED", "GL Version "  +version);
106
       android.util.Log.e("DISTORTED", "GL Vendor "   +vendor);
107
       android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
108
       }
109
     else
110
       {
111
       FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
112
       crashlytics.setCustomKey("DistortedError", message );
113
       crashlytics.setCustomKey("GLSL Version"  , shading );
114
       crashlytics.setCustomKey("GLversion"     , version );
115
       crashlytics.setCustomKey("GL Vendor "    , vendor  );
116
       crashlytics.setCustomKey("GLSLrenderer"  , renderer);
117
       crashlytics.recordException(ex);
118
       }
119
120
     int glsl = DistortedLibrary.getGLSL();
121
122
     if( glsl< 300 )
123
       {
124
       RubikActivity act = (RubikActivity)mView.getContext();
125
       act.OpenGLError(message);
126
       }
127
     }
128
129 aa8b36aa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
130 0c52af30 Leszek Koltunski
131 8becce57 Leszek Koltunski
   DistortedScreen getScreen()
132 434f2f5a Leszek Koltunski
     {
133 64975793 Leszek Koltunski
     return mScreen;
134 434f2f5a Leszek Koltunski
     }
135 0c52af30 Leszek Koltunski
}