Project

General

Profile

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

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

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.EffectType;
27
import org.distorted.library.effect.VertexEffectQuaternion;
28
import org.distorted.library.effect.VertexEffectRotate;
29
import org.distorted.library.main.DistortedLibrary;
30
import org.distorted.library.main.DistortedScreen;
31

    
32
import javax.microedition.khronos.egl.EGLConfig;
33
import javax.microedition.khronos.opengles.GL10;
34

    
35
import com.google.firebase.crashlytics.FirebaseCrashlytics;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
   RubikRenderer(RubikSurfaceView v)
47
     {
48
     final float BRIGHTNESS = 0.1f;
49

    
50
     mView = v;
51
     mScreen = new DistortedScreen();
52
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
53
     }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
// various things are done here delayed, 'after the next render' as not to be done mid-render and
57
// cause artifacts.
58

    
59
   @Override
60
   public void onDrawFrame(GL10 glUnused)
61
     {
62
     mView.getPreRender().preRender();
63
     mScreen.render( System.currentTimeMillis() );
64
     }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
   @Override
69
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
70
      {
71
      mScreen.resize(width,height);
72
      mView.setScreenSize(width,height);
73
      mView.getPreRender().setScreenSize(width,height);
74
      }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
   @Override
79
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
80
      {
81
      DistortedLibrary.setMax(EffectType.VERTEX,25);    // 24 Cube Quats + Rotate
82
      VertexEffectRotate.enable();
83
      VertexEffectQuaternion.enable();
84
      BaseEffect.Type.enableEffects();
85

    
86
      try
87
        {
88
        DistortedLibrary.onCreate(mView.getContext(),1);
89
        }
90
      catch(Exception ex)
91
        {
92
        String message = ex.getMessage();
93
        String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
94
        String version = GLES30.glGetString(GLES30.GL_VERSION);
95
        String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
96
        String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
97

    
98
        if( message==null ) message = "exception NULL";
99

    
100
        if( BuildConfig.DEBUG )
101
          {
102
          android.util.Log.e("DISTORTED", message );
103
          android.util.Log.e("DISTORTED", "GLSL Version "+shading);
104
          android.util.Log.e("DISTORTED", "GL Version "  +version);
105
          android.util.Log.e("DISTORTED", "GL Vendor "   +vendor);
106
          android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
107
          }
108
        else
109
          {
110
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
111
          crashlytics.setCustomKey("DistortedError", message );
112
          crashlytics.setCustomKey("GLSL Version"  , shading );
113
          crashlytics.setCustomKey("GLversion"     , version );
114
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
115
          crashlytics.setCustomKey("GLSLrenderer"  , renderer);
116
          crashlytics.recordException(ex);
117
          }
118

    
119
        int glsl = DistortedLibrary.getGLSL();
120

    
121
        if( glsl< 300 )
122
          {
123
          RubikActivity act = (RubikActivity)mView.getContext();
124
          act.OpenGLError(message);
125
          }
126
        }
127
      }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
   DistortedScreen getScreen()
132
     {
133
     return mScreen;
134
     }
135
}
(3-3/4)