Revision dc10a48d
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/examples/stencil/StencilRenderer.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.examples.stencil; |
| 21 | 21 |
|
| 22 |
import android.app.ActivityManager; |
|
| 23 |
import android.content.Context; |
|
| 24 |
import android.content.pm.ConfigurationInfo; |
|
| 25 |
import android.content.res.Resources; |
|
| 22 | 26 |
import android.graphics.Bitmap; |
| 23 | 27 |
import android.graphics.BitmapFactory; |
| 24 | 28 |
import android.opengl.GLES31; |
| ... | ... | |
| 50 | 54 |
|
| 51 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 52 | 56 |
|
| 53 |
class StencilRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
| 57 |
class StencilRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
| 54 | 58 |
{
|
| 55 |
private GLSurfaceView mView; |
|
| 56 |
private DistortedScreen mScreen; |
|
| 57 |
private DistortedTexture mCubeTex, mFloorTex, mFBOTex; |
|
| 58 |
private DistortedNode mCube1Node, mCube2Node, mFloorNode, mFBONode; |
|
| 59 |
private Static3D mScale, mFBOScale; |
|
| 59 |
private final GLSurfaceView mView; |
|
| 60 |
private final Resources mResources; |
|
| 61 |
private final DistortedScreen mScreen; |
|
| 62 |
private final DistortedTexture mCubeTex, mFloorTex, mFBOTex; |
|
| 63 |
private final DistortedNode mCube1Node, mCube2Node, mFloorNode, mFBONode; |
|
| 64 |
private final Static3D mScale, mFBOScale; |
|
| 60 | 65 |
|
| 61 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 62 | 67 |
|
| ... | ... | |
| 85 | 90 |
StencilRenderer(GLSurfaceView v) |
| 86 | 91 |
{
|
| 87 | 92 |
mView = v; |
| 93 |
mResources = v.getResources(); |
|
| 88 | 94 |
|
| 89 | 95 |
MeshCubes cube = new MeshCubes(1,1,1); |
| 90 | 96 |
MeshQuad quaFlo = new MeshQuad(); |
| ... | ... | |
| 218 | 224 |
{
|
| 219 | 225 |
is.close(); |
| 220 | 226 |
} |
| 221 |
catch(IOException e) { }
|
|
| 227 |
catch(IOException ignored) { }
|
|
| 222 | 228 |
} |
| 223 | 229 |
|
| 224 | 230 |
mCubeTex.setTexture(bitmap); |
| ... | ... | |
| 226 | 232 |
|
| 227 | 233 |
VertexEffectScale.enable(); |
| 228 | 234 |
FragmentEffectBrightness.enable(); |
| 229 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
|
|
| 235 |
DistortedLibrary.onSurfaceCreated(this); |
|
| 230 | 236 |
} |
| 231 | 237 |
|
| 232 | 238 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 235 | 241 |
{
|
| 236 | 242 |
android.util.Log.e("Stencil", ex.getMessage() );
|
| 237 | 243 |
} |
| 244 |
|
|
| 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 |
|
|
| 247 |
public int openGlVersion() |
|
| 248 |
{
|
|
| 249 |
Context context = mView.getContext(); |
|
| 250 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 251 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 252 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
| 253 |
int major = glESversion >> 16; |
|
| 254 |
int minor = glESversion & 0xff; |
|
| 255 |
|
|
| 256 |
return 100*major + 10*minor; |
|
| 257 |
} |
|
| 258 |
|
|
| 259 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 260 |
|
|
| 261 |
public InputStream localFile(int fileID) |
|
| 262 |
{
|
|
| 263 |
return mResources.openRawResource(fileID); |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
|
|
| 268 |
public void logMessage(String message) |
|
| 269 |
{
|
|
| 270 |
android.util.Log.e("Stencil", message );
|
|
| 271 |
} |
|
| 238 | 272 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.