Revision d0ad3964
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/main/RubikRenderer.java | ||
---|---|---|
10 | 10 |
package org.distorted.main; |
11 | 11 |
|
12 | 12 |
import android.app.Activity; |
13 |
import android.app.ActivityManager; |
|
14 |
import android.content.Context; |
|
15 |
import android.content.pm.ConfigurationInfo; |
|
16 |
import android.content.res.Resources; |
|
13 | 17 |
import android.opengl.GLES30; |
14 | 18 |
import android.opengl.GLSurfaceView; |
15 | 19 |
|
... | ... | |
30 | 34 |
|
31 | 35 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
32 | 36 |
|
37 |
import java.io.InputStream; |
|
38 |
|
|
33 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 40 |
|
35 |
public class RubikRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
41 |
public class RubikRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
36 | 42 |
{ |
37 | 43 |
public static final float BRIGHTNESS = 0.30f; |
38 | 44 |
|
39 | 45 |
private final RubikSurfaceView mView; |
46 |
private final Resources mResources; |
|
40 | 47 |
private final DistortedScreen mScreen; |
41 | 48 |
private final ObjectControl mControl; |
42 | 49 |
private final Fps mFPS; |
... | ... | |
85 | 92 |
|
86 | 93 |
RubikRenderer(RubikSurfaceView v) |
87 | 94 |
{ |
88 |
mErrorShown = false; |
|
89 | 95 |
mView = v; |
96 |
mResources = v.getResources(); |
|
97 |
|
|
98 |
mErrorShown = false; |
|
90 | 99 |
mControl = v.getObjectControl(); |
91 | 100 |
mFPS = new Fps(); |
92 | 101 |
mScreen = new DistortedScreen(); |
... | ... | |
94 | 103 |
mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL); |
95 | 104 |
} |
96 | 105 |
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
float getFPS() |
|
109 |
{ |
|
110 |
return mFPS.getFPS(); |
|
111 |
} |
|
112 |
|
|
113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
114 |
|
|
115 |
DistortedScreen getScreen() |
|
116 |
{ |
|
117 |
return mScreen; |
|
118 |
} |
|
119 |
|
|
97 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
98 | 121 |
// various things are done here delayed, 'after the next render' as not to be done mid-render and |
99 | 122 |
// cause artifacts. |
... | ... | |
129 | 152 |
BaseEffect.Type.enableEffects(); |
130 | 153 |
OverlayGeneric.enableEffects(); |
131 | 154 |
|
132 |
DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
|
|
155 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
133 | 156 |
DistortedLibrary.setCull(true); |
134 | 157 |
|
135 | 158 |
if( !mDebugSent ) |
... | ... | |
184 | 207 |
|
185 | 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
186 | 209 |
|
187 |
float getFPS()
|
|
210 |
public int openGlVersion()
|
|
188 | 211 |
{ |
189 |
return mFPS.getFPS(); |
|
212 |
Context context = mView.getContext(); |
|
213 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
214 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
215 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
216 |
int major = glESversion >> 16; |
|
217 |
int minor = glESversion & 0xff; |
|
218 |
|
|
219 |
return 100*major + 10*minor; |
|
190 | 220 |
} |
191 | 221 |
|
192 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
193 | 223 |
|
194 |
DistortedScreen getScreen()
|
|
224 |
public InputStream localFile(int fileID)
|
|
195 | 225 |
{ |
196 |
return mScreen; |
|
226 |
return mResources.openRawResource(fileID); |
|
227 |
} |
|
228 |
|
|
229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
230 |
|
|
231 |
public void logMessage(String message) |
|
232 |
{ |
|
233 |
android.util.Log.e("Rubik", message ); |
|
197 | 234 |
} |
198 | 235 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.