Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikRenderer.java @ 8becce57

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.magic;
21

    
22
import android.opengl.GLSurfaceView;
23
import org.distorted.effect.BaseEffect;
24
import org.distorted.library.effect.VertexEffectSink;
25
import org.distorted.library.main.DistortedLibrary;
26
import org.distorted.library.main.DistortedScreen;
27

    
28
import javax.microedition.khronos.egl.EGLConfig;
29
import javax.microedition.khronos.opengles.GL10;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class RubikRenderer implements GLSurfaceView.Renderer
34
{
35
   public static final int NODE_FBO_SIZE = 600;
36

    
37
   private RubikSurfaceView mView;
38
   private DistortedScreen mScreen;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
   RubikRenderer(RubikSurfaceView v)
43
     {
44
     mView = v;
45
     mScreen = new DistortedScreen();
46
     }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
// various things are done here delayed, 'after the next render' as not to be done mid-render and
50
// cause artifacts.
51

    
52
   @Override
53
   public void onDrawFrame(GL10 glUnused)
54
     {
55
     mScreen.render( System.currentTimeMillis() );
56
     mView.getPostRender().postRender();
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
      mView.getPostRender().setScreenSize(width,height);
67
      }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
   @Override
72
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
73
      {
74
      VertexEffectSink.enable();
75
      BaseEffect.Type.enableEffects();
76

    
77
      try
78
        {
79
        DistortedLibrary.onCreate(mView.getContext());
80
        }
81
      catch(Exception ex)
82
        {
83
        android.util.Log.e("Rubik", ex.getMessage() );
84
        }
85
      }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
   DistortedScreen getScreen()
90
     {
91
     return mScreen;
92
     }
93
}
(3-3/4)