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 |
296219b4
|
Leszek Koltunski
|
// 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 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
1c04d054
|
leszek
|
package org.distorted.main_old;
|
11 |
0c52af30
|
Leszek Koltunski
|
|
12 |
e4854e54
|
Leszek Koltunski
|
import android.app.Activity;
|
13 |
d0ad3964
|
Leszek Koltunski
|
import android.content.res.Resources;
|
14 |
31911113
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
15 |
0c52af30
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
16 |
31911113
|
Leszek Koltunski
|
|
17 |
b4cbe056
|
Leszek Koltunski
|
import org.distorted.library.main.InternalOutputSurface;
|
18 |
1c04d054
|
leszek
|
import org.distorted.main.BuildConfig;
|
19 |
d2556e79
|
Leszek Koltunski
|
import org.distorted.objectlib.effects.BaseEffect;
|
20 |
40ab026e
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectType;
|
21 |
98904e45
|
Leszek Koltunski
|
import org.distorted.library.effect.VertexEffectQuaternion;
|
22 |
27e6c301
|
Leszek Koltunski
|
import org.distorted.library.effect.VertexEffectRotate;
|
23 |
e1111500
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
24 |
0c52af30
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedScreen;
|
25 |
42661133
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
26 |
acabdd83
|
Leszek Koltunski
|
import org.distorted.external.RubikNetwork;
|
27 |
2afc6754
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
28 |
0c52af30
|
Leszek Koltunski
|
|
29 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
30 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
31 |
|
|
|
32 |
31911113
|
Leszek Koltunski
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
33 |
|
|
|
34 |
d0ad3964
|
Leszek Koltunski
|
import java.io.InputStream;
|
35 |
|
|
|
36 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
d0ad3964
|
Leszek Koltunski
|
public class RubikRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
39 |
0c52af30
|
Leszek Koltunski
|
{
|
40 |
2e0258fe
|
Leszek Koltunski
|
public static final float BRIGHTNESS = 0.30f;
|
41 |
|
|
|
42 |
4b4c217e
|
Leszek Koltunski
|
private final RubikSurfaceView mView;
|
43 |
d0ad3964
|
Leszek Koltunski
|
private final Resources mResources;
|
44 |
4b4c217e
|
Leszek Koltunski
|
private final DistortedScreen mScreen;
|
45 |
2afc6754
|
Leszek Koltunski
|
private final ObjectControl mControl;
|
46 |
4b4c217e
|
Leszek Koltunski
|
private final Fps mFPS;
|
47 |
e7e0a94d
|
Leszek Koltunski
|
private boolean mErrorShown;
|
48 |
6a083c6a
|
Leszek Koltunski
|
private boolean mDebugSent;
|
49 |
7eae2d49
|
Leszek Koltunski
|
|
50 |
|
|
private static class Fps
|
51 |
|
|
{
|
52 |
|
|
private static final int NUM_FRAMES = 100;
|
53 |
|
|
|
54 |
|
|
private long lastTime=0;
|
55 |
42661133
|
Leszek Koltunski
|
private final long[] durations;
|
56 |
7eae2d49
|
Leszek Koltunski
|
private int currDuration;
|
57 |
|
|
private float currFPS;
|
58 |
|
|
|
59 |
|
|
Fps()
|
60 |
|
|
{
|
61 |
|
|
durations = new long[NUM_FRAMES+1];
|
62 |
|
|
currDuration = 0;
|
63 |
|
|
|
64 |
|
|
for (int i=0; i<NUM_FRAMES+1; i++) durations[i] = 16;
|
65 |
|
|
durations[NUM_FRAMES] = NUM_FRAMES * 16;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
void onRender(long time)
|
69 |
|
|
{
|
70 |
|
|
if( lastTime==0 ) lastTime = time;
|
71 |
|
|
|
72 |
|
|
currDuration++;
|
73 |
|
|
if (currDuration >= NUM_FRAMES) currDuration = 0;
|
74 |
|
|
durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
|
75 |
|
|
durations[currDuration] = time - lastTime;
|
76 |
|
|
|
77 |
|
|
currFPS = ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
|
78 |
|
|
|
79 |
|
|
lastTime = time;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
float getFPS()
|
83 |
|
|
{
|
84 |
|
|
return currFPS;
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
47ba5ddc
|
Leszek Koltunski
|
|
88 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
8becce57
|
Leszek Koltunski
|
RubikRenderer(RubikSurfaceView v)
|
91 |
47ba5ddc
|
Leszek Koltunski
|
{
|
92 |
8becce57
|
Leszek Koltunski
|
mView = v;
|
93 |
d0ad3964
|
Leszek Koltunski
|
mResources = v.getResources();
|
94 |
|
|
|
95 |
|
|
mErrorShown = false;
|
96 |
2afc6754
|
Leszek Koltunski
|
mControl = v.getObjectControl();
|
97 |
7eae2d49
|
Leszek Koltunski
|
mFPS = new Fps();
|
98 |
8becce57
|
Leszek Koltunski
|
mScreen = new DistortedScreen();
|
99 |
14bd7976
|
Leszek Koltunski
|
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
|
100 |
b4cbe056
|
Leszek Koltunski
|
mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL);
|
101 |
47ba5ddc
|
Leszek Koltunski
|
}
|
102 |
|
|
|
103 |
d0ad3964
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
|
|
float getFPS()
|
106 |
|
|
{
|
107 |
|
|
return mFPS.getFPS();
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111 |
|
|
|
112 |
|
|
DistortedScreen getScreen()
|
113 |
|
|
{
|
114 |
|
|
return mScreen;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
0c52af30
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118 |
|
|
// various things are done here delayed, 'after the next render' as not to be done mid-render and
|
119 |
|
|
// cause artifacts.
|
120 |
|
|
|
121 |
a7a7cc9c
|
Leszek Koltunski
|
@Override
|
122 |
|
|
public void onDrawFrame(GL10 glUnused)
|
123 |
|
|
{
|
124 |
7eae2d49
|
Leszek Koltunski
|
long time = System.currentTimeMillis();
|
125 |
|
|
mFPS.onRender(time);
|
126 |
2afc6754
|
Leszek Koltunski
|
mControl.preRender();
|
127 |
7eae2d49
|
Leszek Koltunski
|
mScreen.render(time);
|
128 |
a7a7cc9c
|
Leszek Koltunski
|
}
|
129 |
0c52af30
|
Leszek Koltunski
|
|
130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
aa8b36aa
|
Leszek Koltunski
|
|
132 |
|
|
@Override
|
133 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
134 |
|
|
{
|
135 |
8becce57
|
Leszek Koltunski
|
mScreen.resize(width,height);
|
136 |
123d6172
|
Leszek Koltunski
|
mView.setScreenSize(width,height);
|
137 |
aa8b36aa
|
Leszek Koltunski
|
}
|
138 |
|
|
|
139 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
|
|
141 |
|
|
@Override
|
142 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
143 |
|
|
{
|
144 |
34bc9f31
|
Leszek Koltunski
|
DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1);
|
145 |
|
|
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
|
146 |
b4a9a34f
|
Leszek Koltunski
|
|
147 |
27e6c301
|
Leszek Koltunski
|
VertexEffectRotate.enable();
|
148 |
98904e45
|
Leszek Koltunski
|
VertexEffectQuaternion.enable();
|
149 |
64975793
|
Leszek Koltunski
|
BaseEffect.Type.enableEffects();
|
150 |
f410c595
|
leszek
|
//OverlayGeneric.enableEffects();
|
151 |
aa8b36aa
|
Leszek Koltunski
|
|
152 |
d0ad3964
|
Leszek Koltunski
|
DistortedLibrary.onSurfaceCreated(this,1);
|
153 |
6b1998e0
|
Leszek Koltunski
|
DistortedLibrary.setCull(true);
|
154 |
6a083c6a
|
Leszek Koltunski
|
|
155 |
e4854e54
|
Leszek Koltunski
|
if( !mDebugSent )
|
156 |
6a083c6a
|
Leszek Koltunski
|
{
|
157 |
|
|
mDebugSent= true;
|
158 |
e4854e54
|
Leszek Koltunski
|
Activity act = (Activity)mView.getContext();
|
159 |
6a083c6a
|
Leszek Koltunski
|
RubikNetwork network = RubikNetwork.getInstance();
|
160 |
1c04d054
|
leszek
|
network.downloadUpdates(act);
|
161 |
6a083c6a
|
Leszek Koltunski
|
}
|
162 |
aa8b36aa
|
Leszek Koltunski
|
}
|
163 |
|
|
|
164 |
c1df2105
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
|
166 |
|
|
public void distortedException(Exception ex)
|
167 |
|
|
{
|
168 |
|
|
String message = ex.getMessage();
|
169 |
|
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
170 |
|
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
171 |
|
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
172 |
|
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
173 |
|
|
|
174 |
|
|
if( message==null ) message = "exception NULL";
|
175 |
|
|
|
176 |
|
|
if( BuildConfig.DEBUG )
|
177 |
|
|
{
|
178 |
|
|
android.util.Log.e("DISTORTED", message );
|
179 |
|
|
android.util.Log.e("DISTORTED", "GLSL Version "+shading);
|
180 |
|
|
android.util.Log.e("DISTORTED", "GL Version " +version);
|
181 |
|
|
android.util.Log.e("DISTORTED", "GL Vendor " +vendor);
|
182 |
|
|
android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
|
183 |
|
|
}
|
184 |
|
|
else
|
185 |
|
|
{
|
186 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
187 |
|
|
crashlytics.setCustomKey("DistortedError", message );
|
188 |
|
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
189 |
|
|
crashlytics.setCustomKey("GLversion" , version );
|
190 |
|
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
191 |
|
|
crashlytics.setCustomKey("GLSLrenderer" , renderer);
|
192 |
|
|
crashlytics.recordException(ex);
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
int glsl = DistortedLibrary.getGLSL();
|
196 |
|
|
|
197 |
e7e0a94d
|
Leszek Koltunski
|
if( glsl< 300 && !mErrorShown )
|
198 |
c1df2105
|
Leszek Koltunski
|
{
|
199 |
e7e0a94d
|
Leszek Koltunski
|
mErrorShown = true;
|
200 |
c1df2105
|
Leszek Koltunski
|
RubikActivity act = (RubikActivity)mView.getContext();
|
201 |
e7e0a94d
|
Leszek Koltunski
|
act.OpenGLError();
|
202 |
c1df2105
|
Leszek Koltunski
|
}
|
203 |
|
|
}
|
204 |
|
|
|
205 |
aa8b36aa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206 |
0c52af30
|
Leszek Koltunski
|
|
207 |
d0ad3964
|
Leszek Koltunski
|
public InputStream localFile(int fileID)
|
208 |
434f2f5a
|
Leszek Koltunski
|
{
|
209 |
d0ad3964
|
Leszek Koltunski
|
return mResources.openRawResource(fileID);
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213 |
|
|
|
214 |
|
|
public void logMessage(String message)
|
215 |
|
|
{
|
216 |
|
|
android.util.Log.e("Rubik", message );
|
217 |
434f2f5a
|
Leszek Koltunski
|
}
|
218 |
0c52af30
|
Leszek Koltunski
|
}
|