Project

General

Profile

Download (3.94 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / playui / PlayRenderer.java @ 5a2a7682

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.playui;
11

    
12
import java.io.InputStream;
13

    
14
import javax.microedition.khronos.egl.EGLConfig;
15
import javax.microedition.khronos.opengles.GL10;
16

    
17
import android.content.res.Resources;
18
import android.opengl.GLSurfaceView;
19

    
20
import org.distorted.library.effect.EffectType;
21
import org.distorted.library.effect.VertexEffectQuaternion;
22
import org.distorted.library.effect.VertexEffectRotate;
23
import org.distorted.library.main.DistortedLibrary;
24
import org.distorted.library.main.DistortedScreen;
25
import org.distorted.library.mesh.MeshBase;
26
import org.distorted.objectlib.effects.BaseEffect;
27
import org.distorted.objectlib.main.ObjectControl;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class PlayRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
32
{
33
   private final PlayView mView;
34
   private final Resources mResources;
35
   private final DistortedScreen mScreen;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
   PlayRenderer(PlayView v)
40
     {
41
     final float BRIGHTNESS = 0.333f;
42

    
43
     mView = v;
44
     mResources = v.getResources();
45
     mScreen = new DistortedScreen();
46
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
47
     }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
   @Override
52
   public void onDrawFrame(GL10 glUnused)
53
     {
54
     long time = System.currentTimeMillis();
55
     mView.getObjectControl().preRender();
56
     mScreen.render(time);
57
     }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
   @Override
62
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
63
      {
64
      mScreen.resize(width,height);
65
      mView.setScreenSize(width,height);
66
      }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
   DistortedScreen getScreen()
71
     {
72
     return mScreen;
73
     }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
   @Override
78
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
79
      {
80
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
81
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
82

    
83
      VertexEffectRotate.enable();
84
      VertexEffectQuaternion.enable();
85
      BaseEffect.Type.enableEffects();
86

    
87
      DistortedLibrary.onSurfaceCreated(this,1);
88
      DistortedLibrary.setCull(true);
89
      }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
   public void distortedException(Exception ex)
94
     {
95
     android.util.Log.e("Play", "unexpected exception: "+ex.getMessage() );
96
     }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
   public InputStream localFile(int fileID)
101
      {
102
      return mResources.openRawResource(fileID);
103
      }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
   public void logMessage(String message)
108
      {
109
      android.util.Log.e("Play", message );
110
      }
111
}
(3-3/12)