Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/dynamic/DynamicRenderer.java | ||
---|---|---|
22 | 22 |
import javax.microedition.khronos.egl.EGLConfig; |
23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
24 | 24 |
|
25 |
import android.app.ActivityManager; |
|
26 |
import android.content.Context; |
|
27 |
import android.content.pm.ConfigurationInfo; |
|
28 |
import android.content.res.Resources; |
|
25 | 29 |
import android.graphics.Bitmap; |
26 | 30 |
import android.graphics.Canvas; |
27 | 31 |
import android.graphics.Paint; |
... | ... | |
36 | 40 |
import org.distorted.library.main.DistortedLibrary; |
37 | 41 |
import org.distorted.library.type.Static3D; |
38 | 42 |
|
43 |
import java.io.InputStream; |
|
44 |
|
|
39 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 46 |
|
41 |
class DynamicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
47 |
class DynamicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
42 | 48 |
{ |
43 |
private DynamicSurfaceView mView; |
|
44 |
private DistortedTexture mTexture; |
|
45 |
private DistortedEffects mEffects; |
|
46 |
private DistortedScreen mScreen; |
|
47 |
private MeshSquare mMesh; |
|
49 |
private final DynamicSurfaceView mView; |
|
50 |
private final Resources mResources; |
|
51 |
private final DistortedTexture mTexture; |
|
52 |
private final DistortedEffects mEffects; |
|
53 |
private final DistortedScreen mScreen; |
|
54 |
private final MeshSquare mMesh; |
|
55 |
private final Paint mPaint; |
|
56 |
private final Static3D mScale; |
|
57 |
|
|
48 | 58 |
private Canvas mCanvas; |
49 | 59 |
private Bitmap mBitmap; |
50 |
private Paint mPaint; |
|
51 |
private Static3D mScale; |
|
60 |
|
|
52 | 61 |
private static int texW, texH; |
53 | 62 |
|
54 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 64 |
|
56 | 65 |
DynamicRenderer(DynamicSurfaceView v) |
57 |
{ |
|
66 |
{ |
|
67 |
mView = v; |
|
68 |
mResources = v.getResources(); |
|
69 |
|
|
58 | 70 |
mPaint = new Paint(); |
59 | 71 |
mPaint.setAntiAlias(true); |
60 | 72 |
mPaint.setFakeBoldText(true); |
61 | 73 |
mPaint.setColor(0xff447da7); |
62 | 74 |
mPaint.setStyle(Style.FILL); |
63 |
|
|
64 |
mView = v; |
|
75 |
|
|
65 | 76 |
mMesh = new MeshSquare(1,1); |
66 | 77 |
mScreen = new DistortedScreen(); |
67 | 78 |
mEffects = new DistortedEffects(); |
... | ... | |
106 | 117 |
|
107 | 118 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
108 | 119 |
{ |
109 |
DistortedLibrary.onSurfaceCreated(mView.getContext(),this);
|
|
120 |
DistortedLibrary.onSurfaceCreated(this); |
|
110 | 121 |
} |
111 | 122 |
|
112 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
115 | 126 |
{ |
116 | 127 |
android.util.Log.e("Dynamic", ex.getMessage() ); |
117 | 128 |
} |
129 |
|
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
|
|
132 |
public int openGlVersion() |
|
133 |
{ |
|
134 |
Context context = mView.getContext(); |
|
135 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
136 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
137 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
138 |
int major = glESversion >> 16; |
|
139 |
int minor = glESversion & 0xff; |
|
140 |
|
|
141 |
return 100*major + 10*minor; |
|
142 |
} |
|
143 |
|
|
144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
145 |
|
|
146 |
public InputStream localFile(int fileID) |
|
147 |
{ |
|
148 |
return mResources.openRawResource(fileID); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
public void logMessage(String message) |
|
154 |
{ |
|
155 |
android.util.Log.e("Dynamic", message ); |
|
156 |
} |
|
118 | 157 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.