Revision dc10a48d
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.examples.meshfile; |
| 21 | 21 |
|
| 22 |
import android.app.ActivityManager; |
|
| 22 | 23 |
import android.content.Context; |
| 24 |
import android.content.pm.ConfigurationInfo; |
|
| 23 | 25 |
import android.content.res.Resources; |
| 24 | 26 |
import android.graphics.Bitmap; |
| 25 | 27 |
import android.graphics.Canvas; |
| ... | ... | |
| 65 | 67 |
|
| 66 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 67 | 69 |
|
| 68 |
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
| 70 |
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
| 69 | 71 |
{
|
| 70 | 72 |
private static final float SQ3 = (float)Math.sqrt(3); |
| 71 | 73 |
private final float DEFAULT_SCALE = 0.3f; |
| 72 | 74 |
|
| 73 | 75 |
private final GLSurfaceView mView; |
| 74 |
private DistortedTexture mTexture;
|
|
| 76 |
private final Resources mResources;
|
|
| 75 | 77 |
private final DistortedScreen mScreen; |
| 76 | 78 |
private final DistortedEffects mEffects; |
| 77 | 79 |
private final Static3D mScale; |
| 80 |
|
|
| 81 |
private DistortedTexture mTexture; |
|
| 82 |
private MeshBase mMesh; |
|
| 78 | 83 |
private long mTime; |
| 79 | 84 |
private float mCurrentScale; |
| 80 |
private MeshBase mMesh; |
|
| 81 | 85 |
|
| 82 | 86 |
Static4D mQuat1, mQuat2; |
| 83 | 87 |
int mScreenMin; |
| ... | ... | |
| 87 | 91 |
MeshFileRenderer(GLSurfaceView v) |
| 88 | 92 |
{
|
| 89 | 93 |
mView = v; |
| 94 |
mResources = v.getResources(); |
|
| 95 |
|
|
| 90 | 96 |
mScreen = new DistortedScreen(); |
| 91 | 97 |
mScale= new Static3D(1,1,1); |
| 92 | 98 |
Static3D center=new Static3D(0,0,0); |
| ... | ... | |
| 142 | 148 |
Effect.enableEffects(EffectType.VERTEX); |
| 143 | 149 |
DistortedLibrary.setMax(EffectType.VERTEX, 20); |
| 144 | 150 |
DistortedLibrary.needTransformFeedback(); |
| 145 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this); |
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 149 |
|
|
| 150 |
public void distortedException(Exception ex) |
|
| 151 |
{
|
|
| 152 |
android.util.Log.e("MeshFile", ex.getMessage() );
|
|
| 151 |
DistortedLibrary.onSurfaceCreated(this); |
|
| 153 | 152 |
} |
| 154 | 153 |
|
| 155 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 405 | 404 |
{
|
| 406 | 405 |
return mMesh.getNumTexComponents(); |
| 407 | 406 |
} |
| 407 |
|
|
| 408 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 409 |
|
|
| 410 |
public void distortedException(Exception ex) |
|
| 411 |
{
|
|
| 412 |
android.util.Log.e("MeshFile", ex.getMessage() );
|
|
| 413 |
} |
|
| 414 |
|
|
| 415 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 416 |
|
|
| 417 |
public int openGlVersion() |
|
| 418 |
{
|
|
| 419 |
Context context = mView.getContext(); |
|
| 420 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 421 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 422 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
| 423 |
int major = glESversion >> 16; |
|
| 424 |
int minor = glESversion & 0xff; |
|
| 425 |
|
|
| 426 |
return 100*major + 10*minor; |
|
| 427 |
} |
|
| 428 |
|
|
| 429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 430 |
|
|
| 431 |
public InputStream localFile(int fileID) |
|
| 432 |
{
|
|
| 433 |
return mResources.openRawResource(fileID); |
|
| 434 |
} |
|
| 435 |
|
|
| 436 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 437 |
|
|
| 438 |
public void logMessage(String message) |
|
| 439 |
{
|
|
| 440 |
android.util.Log.e("MeshFile", message );
|
|
| 441 |
} |
|
| 408 | 442 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.