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.patternui;
|
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 PatternRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
37
|
{
|
38
|
private final PatternSurfaceView mView;
|
39
|
private final Resources mResources;
|
40
|
private final DistortedScreen mScreen;
|
41
|
private final ObjectControl mControl;
|
42
|
private boolean mErrorShown;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
PatternRenderer(PatternSurfaceView v)
|
47
|
{
|
48
|
mView = v;
|
49
|
mResources = v.getResources();
|
50
|
|
51
|
mErrorShown = false;
|
52
|
mControl = v.getObjectControl();
|
53
|
mScreen = new DistortedScreen();
|
54
|
|
55
|
PatternActivity act = (PatternActivity)v.getContext();
|
56
|
act.setUpBackgroundColor(mScreen);
|
57
|
|
58
|
mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL);
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
DistortedScreen getScreen()
|
64
|
{
|
65
|
return mScreen;
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
// various things are done here delayed, 'after the next render' as not to be done mid-render and
|
70
|
// cause artifacts.
|
71
|
|
72
|
@Override
|
73
|
public void onDrawFrame(GL10 glUnused)
|
74
|
{
|
75
|
long time = System.currentTimeMillis();
|
76
|
mControl.preRender();
|
77
|
mScreen.render(time);
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
@Override
|
83
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
84
|
{
|
85
|
mScreen.resize(width,height);
|
86
|
mView.setScreenSize(width,height);
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
@Override
|
92
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
93
|
{
|
94
|
DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1);
|
95
|
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
|
96
|
|
97
|
VertexEffectRotate.enable();
|
98
|
VertexEffectQuaternion.enable();
|
99
|
BaseEffect.Type.enableEffects();
|
100
|
|
101
|
DistortedLibrary.onSurfaceCreated(this,1);
|
102
|
DistortedLibrary.setCull(true);
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
public void distortedException(Exception ex)
|
108
|
{
|
109
|
String message = ex.getMessage();
|
110
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
111
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
112
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
113
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
114
|
|
115
|
if( message==null ) message = "exception NULL";
|
116
|
|
117
|
if( BuildConfig.DEBUG )
|
118
|
{
|
119
|
android.util.Log.e("DISTORTED", message );
|
120
|
android.util.Log.e("DISTORTED", "GLSL Version "+shading);
|
121
|
android.util.Log.e("DISTORTED", "GL Version " +version);
|
122
|
android.util.Log.e("DISTORTED", "GL Vendor " +vendor);
|
123
|
android.util.Log.e("DISTORTED", "GL Renderer " +renderer);
|
124
|
}
|
125
|
else
|
126
|
{
|
127
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
128
|
crashlytics.setCustomKey("DistortedError", message );
|
129
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
130
|
crashlytics.setCustomKey("GLversion" , version );
|
131
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
132
|
crashlytics.setCustomKey("GLSLrenderer" , renderer);
|
133
|
crashlytics.recordException(ex);
|
134
|
}
|
135
|
|
136
|
int glsl = DistortedLibrary.getGLSL();
|
137
|
|
138
|
if( glsl< 300 && !mErrorShown )
|
139
|
{
|
140
|
mErrorShown = true;
|
141
|
PatternActivity act = (PatternActivity)mView.getContext();
|
142
|
act.OpenGLError();
|
143
|
}
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
public InputStream localFile(int fileID)
|
149
|
{
|
150
|
return mResources.openRawResource(fileID);
|
151
|
}
|
152
|
|
153
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154
|
|
155
|
public void logMessage(String message)
|
156
|
{
|
157
|
android.util.Log.e("Rubik", message );
|
158
|
}
|
159
|
}
|