Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayRenderer.java @ 306aa049

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.bandaged;
11

    
12
import android.opengl.GLSurfaceView;
13

    
14
import org.distorted.library.effect.EffectType;
15
import org.distorted.library.effect.VertexEffectQuaternion;
16
import org.distorted.library.effect.VertexEffectRotate;
17
import org.distorted.library.main.DistortedLibrary;
18
import org.distorted.library.main.DistortedScreen;
19
import org.distorted.library.mesh.MeshBase;
20
import org.distorted.objectlib.effects.BaseEffect;
21
import org.distorted.objectlib.scrambling.ScrambleStateBandagedCuboid;
22

    
23
import javax.microedition.khronos.egl.EGLConfig;
24
import javax.microedition.khronos.opengles.GL10;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

    
28
public class BandagedPlayRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
29
{
30
   private final BandagedPlayView mView;
31
   private final DistortedScreen mScreen;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
   BandagedPlayRenderer(BandagedPlayView v)
36
     {
37
     final float BRIGHTNESS = 0.333f;
38

    
39
     mView = v;
40
     mScreen = new DistortedScreen();
41
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
42
     }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
   @Override
47
   public void onDrawFrame(GL10 glUnused)
48
     {
49
     long time = System.currentTimeMillis();
50
     mView.getObjectControl().preRender();
51
     mScreen.render(time);
52
     }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
   @Override
57
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
58
      {
59
      mScreen.resize(width,height);
60
      mView.setScreenSize(width,height);
61
      }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
   @Override
66
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
67
      {
68
      int maxS = ScrambleStateBandagedCuboid.MAX_SUPPORTED_SIZE;
69
      int numComponents = maxS*maxS*maxS - (maxS-2)*(maxS-2)*(maxS-2);
70

    
71
      DistortedLibrary.setMax(EffectType.VERTEX,25); // 24 quaternions + rotation
72
      MeshBase.setMaxEffComponents(numComponents);
73
      VertexEffectRotate.enable();
74
      VertexEffectQuaternion.enable();
75
      BaseEffect.Type.enableEffects();
76

    
77
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
78
      DistortedLibrary.setCull(true);
79
      }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
   public void distortedException(Exception ex)
84
     {
85
     android.util.Log.e("BandagedPlay", "unexpected exception: "+ex.getMessage() );
86
     }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
   DistortedScreen getScreen()
91
     {
92
     return mScreen;
93
     }
94
}
(11-11/13)