Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigRenderer.java @ d0ad3964

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.config;
11

    
12
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.content.res.Resources;
16
import android.opengl.GLSurfaceView;
17

    
18
import org.distorted.library.effect.EffectType;
19
import org.distorted.library.effect.VertexEffectQuaternion;
20
import org.distorted.library.effect.VertexEffectRotate;
21
import org.distorted.library.main.DistortedLibrary;
22
import org.distorted.library.main.DistortedScreen;
23
import org.distorted.objectlib.effects.BaseEffect;
24
import org.distorted.objectlib.main.ObjectControl;
25

    
26
import java.io.InputStream;
27

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

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

    
33
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
34
{
35
   private final ConfigSurfaceView mView;
36
   private final Resources mResources;
37
   private final DistortedScreen mScreen;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
   ConfigRenderer(ConfigSurfaceView v)
42
     {
43
     final float BRIGHTNESS = 0.333f;
44

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
   DistortedScreen getScreen()
73
     {
74
     return mScreen;
75
     }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
   @Override
80
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
81
      {
82
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
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("Config", "unexpected exception: "+ex.getMessage() );
96
     }
97

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

    
100
   public int openGlVersion()
101
      {
102
      Context context = mView.getContext();
103
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
104
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
105
      int glESversion = configurationInfo.reqGlEsVersion;
106
      int major = glESversion >> 16;
107
      int minor = glESversion & 0xff;
108

    
109
      return 100*major + 10*minor;
110
      }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
   public InputStream localFile(int fileID)
115
      {
116
      return mResources.openRawResource(fileID);
117
      }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
   public void logMessage(String message)
122
      {
123
      android.util.Log.e("Config", message );
124
      }
125
}
(3-3/6)