Revision d0ad3964
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/config/ConfigRenderer.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.config; |
11 | 11 |
|
12 |
import android.app.ActivityManager; |
|
13 |
import android.content.Context; |
|
14 |
import android.content.pm.ConfigurationInfo; |
|
15 |
import android.content.res.Resources; |
|
12 | 16 |
import android.opengl.GLSurfaceView; |
13 | 17 |
|
14 | 18 |
import org.distorted.library.effect.EffectType; |
... | ... | |
19 | 23 |
import org.distorted.objectlib.effects.BaseEffect; |
20 | 24 |
import org.distorted.objectlib.main.ObjectControl; |
21 | 25 |
|
26 |
import java.io.InputStream; |
|
27 |
|
|
22 | 28 |
import javax.microedition.khronos.egl.EGLConfig; |
23 | 29 |
import javax.microedition.khronos.opengles.GL10; |
24 | 30 |
|
25 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
26 | 32 |
|
27 |
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
33 |
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
28 | 34 |
{ |
29 | 35 |
private final ConfigSurfaceView mView; |
36 |
private final Resources mResources; |
|
30 | 37 |
private final DistortedScreen mScreen; |
31 | 38 |
|
32 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
36 | 43 |
final float BRIGHTNESS = 0.333f; |
37 | 44 |
|
38 | 45 |
mView = v; |
46 |
mResources = v.getResources(); |
|
39 | 47 |
mScreen = new DistortedScreen(); |
40 | 48 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
41 | 49 |
} |
... | ... | |
59 | 67 |
mView.setScreenSize(width,height); |
60 | 68 |
} |
61 | 69 |
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
DistortedScreen getScreen() |
|
73 |
{ |
|
74 |
return mScreen; |
|
75 |
} |
|
76 |
|
|
62 | 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 78 |
|
64 | 79 |
@Override |
... | ... | |
69 | 84 |
VertexEffectQuaternion.enable(); |
70 | 85 |
BaseEffect.Type.enableEffects(); |
71 | 86 |
|
72 |
DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
|
|
87 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
73 | 88 |
DistortedLibrary.setCull(true); |
74 | 89 |
} |
75 | 90 |
|
... | ... | |
77 | 92 |
|
78 | 93 |
public void distortedException(Exception ex) |
79 | 94 |
{ |
80 |
android.util.Log.e("CONFIG", "unexpected exception: "+ex.getMessage() );
|
|
95 |
android.util.Log.e("Config", "unexpected exception: "+ex.getMessage() );
|
|
81 | 96 |
} |
82 | 97 |
|
83 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
84 | 99 |
|
85 |
DistortedScreen getScreen() |
|
86 |
{ |
|
87 |
return mScreen; |
|
88 |
} |
|
100 |
public int openGlVersion() |
|
101 |
{ |
|
102 |
Context context = mView.getContext(); |
|
103 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
104 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
105 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
106 |
int major = glESversion >> 16; |
|
107 |
int minor = glESversion & 0xff; |
|
108 |
|
|
109 |
return 100*major + 10*minor; |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
|
|
114 |
public InputStream localFile(int fileID) |
|
115 |
{ |
|
116 |
return mResources.openRawResource(fileID); |
|
117 |
} |
|
118 |
|
|
119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
|
|
121 |
public void logMessage(String message) |
|
122 |
{ |
|
123 |
android.util.Log.e("Config", message ); |
|
124 |
} |
|
89 | 125 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.