Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikRenderer.java @ fb6a40c8

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
   private RubikSurfaceView mView;
36
   private DistortedScreen mScreen;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

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

    
50
   @Override
51
   public void onDrawFrame(GL10 glUnused)
52
     {
53
     mScreen.render( System.currentTimeMillis() );
54
     mView.getPostRender().postRender();
55
     }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

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

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

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