Project

General

Profile

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

magiccube / src / main / java / org / distorted / solverui / SolverRenderer.java @ c1d09246

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.solverui;
11

    
12
import android.content.res.Resources;
13
import android.opengl.GLES30;
14
import android.opengl.GLSurfaceView;
15

    
16
import com.google.firebase.crashlytics.FirebaseCrashlytics;
17

    
18
import org.distorted.library.effect.EffectType;
19
import org.distorted.library.effect.VertexEffectQuaternion;
20
import org.distorted.library.effect.VertexEffectRotate;
21
import org.distorted.library.main.DistortedLibrary;
22
import org.distorted.library.main.DistortedScreen;
23
import org.distorted.library.main.InternalOutputSurface;
24
import org.distorted.library.mesh.MeshBase;
25
import org.distorted.main.BuildConfig;
26
import org.distorted.objectlib.effects.BaseEffect;
27
import org.distorted.objectlib.main.ObjectControl;
28

    
29
import java.io.InputStream;
30

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

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class SolverRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
37
{
38
   public static final float BRIGHTNESS = 0.30f;
39

    
40
   private final SolverSurfaceView mView;
41
   private final Resources mResources;
42
   private final DistortedScreen mScreen;
43
   private final ObjectControl mControl;
44
   private boolean mErrorShown;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
   SolverRenderer(SolverSurfaceView v)
49
     {
50
     mView = v;
51
     mResources = v.getResources();
52

    
53
     mErrorShown = false;
54
     mControl = v.getObjectControl();
55
     mScreen = new DistortedScreen();
56
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
57
     mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL);
58
     }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
   DistortedScreen getScreen()
63
     {
64
     return mScreen;
65
     }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
// various things are done here delayed, 'after the next render' as not to be done mid-render and
69
// cause artifacts.
70

    
71
   @Override
72
   public void onDrawFrame(GL10 glUnused)
73
     {
74
     long time = System.currentTimeMillis();
75
     mControl.preRender();
76
     mScreen.render(time);
77
     }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
   @Override
82
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
83
      {
84
      mScreen.resize(width,height);
85
      mView.setScreenSize(width,height);
86
      }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
   @Override
91
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
92
      {
93
      DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1);
94
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
95

    
96
      VertexEffectRotate.enable();
97
      VertexEffectQuaternion.enable();
98
      BaseEffect.Type.enableEffects();
99

    
100
      DistortedLibrary.onSurfaceCreated(this,1);
101
      DistortedLibrary.setCull(true);
102
      }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
   public void distortedException(Exception ex)
107
     {
108
     String message = ex.getMessage();
109
     String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
110
     String version = GLES30.glGetString(GLES30.GL_VERSION);
111
     String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
112
     String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
113

    
114
     if( message==null ) message = "exception NULL";
115

    
116
     if( BuildConfig.DEBUG )
117
       {
118
       android.util.Log.e("DISTORTED", message );
119
       android.util.Log.e("DISTORTED", "GLSL Version "+shading);
120
       android.util.Log.e("DISTORTED", "GL Version "  +version);
121
       android.util.Log.e("DISTORTED", "GL Vendor "   +vendor);
122
       android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
123
       }
124
     else
125
       {
126
       FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
127
       crashlytics.setCustomKey("DistortedError", message );
128
       crashlytics.setCustomKey("GLSL Version"  , shading );
129
       crashlytics.setCustomKey("GLversion"     , version );
130
       crashlytics.setCustomKey("GL Vendor "    , vendor  );
131
       crashlytics.setCustomKey("GLSLrenderer"  , renderer);
132
       crashlytics.recordException(ex);
133
       }
134

    
135
     int glsl = DistortedLibrary.getGLSL();
136

    
137
     if( glsl< 300 && !mErrorShown )
138
       {
139
       mErrorShown = true;
140
       SolverActivity act = (SolverActivity)mView.getContext();
141
       act.OpenGLError();
142
       }
143
     }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
   public InputStream localFile(int fileID)
148
     {
149
     return mResources.openRawResource(fileID);
150
     }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
   public void logMessage(String message)
155
     {
156
     android.util.Log.e("Rubik", message );
157
     }
158
}
(7-7/8)