Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit c89378d

Browse files
committed
[[ TileCache ]] Update Android and iOS engines to use OpenGLES3.x tilecache
1 parent 4d7c732 commit c89378d

File tree

8 files changed

+130
-107
lines changed

8 files changed

+130
-107
lines changed

engine/kernel.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
{
237237
'libraries':
238238
[
239-
'-lGLESv1_CM',
239+
'-lGLESv3',
240240
'-lEGL',
241241
'-ljnigraphics',
242242
'-llog',

engine/rsrc/android-manifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
${INSTALL_LOCATION}>
77
${PUSH_PERMISSIONS}
88
${USES_PERMISSION}${USES_FEATURE}
9+
<uses-feature android:glEsVersion="0x00030000"/>
910
<uses-sdk android:minSdkVersion="${MIN_SDK_VERSION}" android:targetSdkVersion="${TARGET_SDK_VERSION}"/>
1011
<supports-screens
1112
android:largeScreens="true"

engine/src/java/com/runrev/android/OpenGLView.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class OpenGLView extends SurfaceView implements SurfaceHolder.Callback
3434
{
3535
// Instance variables
3636

37+
private static final int EGL_CONTEXT_CLIENT_VERSION = 0x00003098;
38+
3739
private EGL10 m_egl;
3840
private EGLDisplay m_egl_display;
3941
private EGLSurface m_egl_surface;
@@ -127,8 +129,13 @@ public void start()
127129
// For debugging.
128130
dumpConfig("Using EGLConfig", m_egl, m_egl_display, m_egl_config);
129131

132+
int[] t_attr = new int[] {
133+
EGL_CONTEXT_CLIENT_VERSION, 3,
134+
EGL10.EGL_NONE,
135+
};
136+
130137
// Now create the OpenGL ES context.
131-
m_egl_context = m_egl . eglCreateContext(m_egl_display, m_egl_config, EGL10 . EGL_NO_CONTEXT, null);
138+
m_egl_context = m_egl . eglCreateContext(m_egl_display, m_egl_config, EGL10 . EGL_NO_CONTEXT, t_attr);
132139

133140
// We don't have a surface (just yet).
134141
m_egl_surface = null;

engine/src/mblandroiddc.cpp

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5252
#include "mcmanagedpthread.h"
5353
#include <android/log.h>
5454
#include <android/bitmap.h>
55-
#include <GLES/gl.h>
55+
#include <GLES3/gl3.h>
5656
#include <unistd.h>
5757

5858
#include "libscript/script.h"
5959

60+
#include "glcontext.h"
61+
6062
////////////////////////////////////////////////////////////////////////////////
6163

6264
// Various globals depended on by other parts of the engine.
@@ -128,6 +130,7 @@ static MCRectangle s_android_bitmap_dirty;
128130
static bool s_android_opengl_enabled = false;
129131
static bool s_android_opengl_visible = false;
130132
static jobject s_android_opengl_view = nullptr;
133+
static MCGLContextRef s_android_opengl_context = nil;
131134

132135
// This is the JNI reference to our display/view instance.
133136
static jobject s_android_activity = nullptr;
@@ -1042,8 +1045,9 @@ class MCOpenGLStackSurface: public MCStackSurface
10421045
}
10431046

10441047
protected:
1045-
static void FlushBits(void *p_bits, uint32_t p_stride)
1048+
void FlushBits(void *p_bits, uint32_t p_stride)
10461049
{
1050+
MCAssert(s_android_opengl_context != nil);
10471051
GLuint t_texture;
10481052
glGenTextures(1, &t_texture);
10491053
glBindTexture(GL_TEXTURE_2D, t_texture);
@@ -1056,27 +1060,17 @@ class MCOpenGLStackSurface: public MCStackSurface
10561060
// TexImage2D and TexSubImage2D.
10571061
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
10581062

1059-
glMatrixMode(GL_MODELVIEW);
1060-
glLoadIdentity();
1061-
glMatrixMode(GL_TEXTURE);
1062-
glLoadIdentity();
1063+
MCGLContextSelectProgram(s_android_opengl_context, kMCGLProgramTypeTexture);
1064+
MCGLContextSetWorldTransform(s_android_opengl_context, MCGAffineTransformMakeIdentity());
1065+
MCGLContextSetTextureTransform(s_android_opengl_context, MCGAffineTransformMakeIdentity());
10631066

1064-
glEnable(GL_TEXTURE_2D);
10651067
glDisable(GL_BLEND);
1066-
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
1067-
1068-
GLfloat t_vertices[8];
1069-
1070-
GLfloat t_coords[8] =
1071-
{
1072-
0, 0,
1073-
1.0, 0.0,
1074-
0.0, 1.0,
1075-
1.0, 1.0
1076-
};
10771068

1078-
glVertexPointer(2, GL_FLOAT, 0, t_vertices);
1079-
glTexCoordPointer(2, GL_FLOAT, 0, t_coords);
1069+
MCGLTextureVertex t_vertices[4];
1070+
t_vertices[0].texture_position[0] = 0.0; t_vertices[0].texture_position[1] = 0.0;
1071+
t_vertices[1].texture_position[0] = 1.0; t_vertices[1].texture_position[1] = 0.0;
1072+
t_vertices[2].texture_position[0] = 0.0; t_vertices[2].texture_position[1] = 1.0;
1073+
t_vertices[3].texture_position[0] = 1.0; t_vertices[3].texture_position[1] = 1.0;
10801074

10811075
for(int32_t y = 0; y < (s_android_bitmap_height + 255) / 256; y++)
10821076
for(int32_t x = 0; x < (s_android_bitmap_width + 255) / 256; x++)
@@ -1094,11 +1088,12 @@ class MCOpenGLStackSurface: public MCStackSurface
10941088
t_py = s_android_bitmap_height - y * 256 - 256;
10951089

10961090
// Setup co-ords.
1097-
t_vertices[0] = t_px, t_vertices[1] = t_py + 256;
1098-
t_vertices[2] = t_px + 256, t_vertices[3] = t_py + 256;
1099-
t_vertices[4] = t_px, t_vertices[5] = t_py;
1100-
t_vertices[6] = t_px + 256, t_vertices[7] = t_py;
1091+
t_vertices[0].position[0] = t_px; t_vertices[0].position[1] = t_py + 256;
1092+
t_vertices[1].position[0] = t_px + 256; t_vertices[1].position[1] = t_py + 256;
1093+
t_vertices[2].position[0] = t_px; t_vertices[2].position[1] = t_py;
1094+
t_vertices[3].position[0] = t_px + 256; t_vertices[3].position[1] = t_py;
11011095

1096+
glBufferData(GL_ARRAY_BUFFER, sizeof(MCGLTextureVertex) * 4, t_vertices, GL_STREAM_DRAW);
11021097
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
11031098
}
11041099

@@ -1142,17 +1137,14 @@ void MCStack::view_device_updatewindow(MCRegionRef p_region)
11421137
glClear(GL_COLOR_BUFFER_BIT);
11431138

11441139
glViewport(0, 0, s_android_bitmap_width, s_android_bitmap_height);
1145-
glMatrixMode(GL_PROJECTION);
1146-
glLoadIdentity();
1147-
glOrthof(0, (GLfloat)s_android_bitmap_width, 0, (GLfloat)s_android_bitmap_height, 0, 1);
1148-
glMatrixMode(GL_MODELVIEW);
1149-
glLoadIdentity();
1140+
// create transform from {0, 0, surface_width, surface_height} to GL normaized coords
1141+
MCGAffineTransform t_projection;
1142+
t_projection = MCGAffineTransformFromRectangles(MCGRectangleMake(0, 0, s_android_bitmap_width, s_android_bitmap_height), MCGRectangleMake(-1,-1,2,2));
1143+
MCGLContextSetProjectionTransform(s_android_opengl_context, t_projection);
1144+
MCGLContextSetWorldTransform(s_android_opengl_context, MCGAffineTransformMakeIdentity());
1145+
MCGLContextSetTextureTransform(s_android_opengl_context, MCGAffineTransformMakeIdentity());
11501146

11511147
glDisable(GL_DEPTH_TEST);
1152-
glDisableClientState(GL_COLOR_ARRAY);
1153-
glEnable(GL_TEXTURE_2D);
1154-
glEnableClientState(GL_VERTEX_ARRAY);
1155-
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
11561148

11571149
MCGRegionRef t_dirty_rgn;
11581150
MCGRegionCreate(t_dirty_rgn);
@@ -2812,6 +2804,10 @@ static void doSurfaceDestroyedCallback(void *)
28122804
if (s_android_opengl_enabled)
28132805
MCRedrawDirtyScreen();
28142806

2807+
// Reset OpenGL context
2808+
if (s_android_opengl_context != nil)
2809+
MCGLContextReset(s_android_opengl_context);
2810+
28152811
// Discard all the OpenGL state.
28162812
s_java_env -> CallVoidMethod(s_android_opengl_view, s_openglview_finish_method);
28172813

@@ -2845,6 +2841,13 @@ static void doSurfaceChangedCallback(void *p_is_init)
28452841
// We can now re-enable screen updates.
28462842
MCRedrawEnableScreenUpdates();
28472843

2844+
if (s_android_opengl_context != nil)
2845+
{
2846+
// Reset & re-initialize the OpenGL context
2847+
MCGLContextReset(s_android_opengl_context);
2848+
/* UNCHECKED */ MCGLContextInit(s_android_opengl_context);
2849+
}
2850+
28482851
// Force a redraw of the current window. If this is an initializing change,
28492852
// re-render the whole screen.
28502853
if (t_is_init)
@@ -2869,20 +2872,23 @@ JNIEXPORT void JNICALL Java_com_runrev_android_OpenGLView_doSurfaceChanged(JNIEn
28692872
co_yield_to_engine_and_call(doSurfaceChangedCallback, (void *)t_is_init);
28702873
}
28712874

2872-
void MCAndroidEnableOpenGLMode(void)
2875+
void MCPlatformEnableOpenGLMode(void)
28732876
{
28742877
if (s_android_opengl_enabled)
28752878
return;
28762879

28772880
MCRedrawDisableScreenUpdates();
28782881

2882+
// Create new OpenGL context to manage shader setup, etc.
2883+
/* UNCHECKED */ MCGLContextCreate(s_android_opengl_context);
2884+
28792885
MCAndroidEngineRemoteCall("enableOpenGLView", "v", nil);
28802886

28812887
s_android_opengl_enabled = true;
28822888
s_android_opengl_visible = false;
28832889
}
28842890

2885-
void MCAndroidDisableOpenGLMode(void)
2891+
void MCPlatformDisableOpenGLMode(void)
28862892
{
28872893
if (!s_android_opengl_enabled)
28882894
return;
@@ -2892,9 +2898,18 @@ void MCAndroidDisableOpenGLMode(void)
28922898

28932899
MCAndroidEngineRemoteCall("disableOpenGLView", "v", nil);
28942900

2901+
// Release OpenGL context
2902+
MCGLContextDestroy(s_android_opengl_context);
2903+
s_android_opengl_context = nil;
2904+
28952905
MCRedrawEnableScreenUpdates();
28962906
}
28972907

2908+
MCGLContextRef MCPlatformGetOpenGLContext(void)
2909+
{
2910+
return s_android_opengl_context;
2911+
}
2912+
28982913
////////////////////////////////////////////////////////////////////////////////
28992914

29002915
static bool s_in_permission_dialog = false;

engine/src/mbliphonedc.mm

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
#import <UIKit/UIKit.h>
4747
#import <QuartzCore/QuartzCore.h>
4848
#import <AudioToolbox/AudioToolbox.h>
49-
#import <OpenGLES/ES1/gl.h>
50-
#import <OpenGLES/ES1/glext.h>
5149
#import <MediaPlayer/MPMoviePlayerViewController.h>
5250

5351
#include "mbliphoneapp.h"
@@ -57,6 +55,10 @@
5755

5856
#include <objc/message.h>
5957

58+
#import <OpenGLES/ES3/gl.h>
59+
#import <OpenGLES/ES3/glext.h>
60+
#include "glcontext.h"
61+
6062
////////////////////////////////////////////////////////////////////////////////
6163

6264
extern void X_main_loop(void);
@@ -1132,17 +1134,25 @@ bool iphone_run_on_main_thread(void *p_callback, void *p_callback_state, int p_o
11321134

11331135
static bool s_ensure_opengl = false;
11341136
static bool s_is_opengl_display = false;
1137+
static MCGLContextRef s_opengl_context = nil;
11351138

1136-
void MCIPhoneSwitchToOpenGL(void)
1139+
void MCPlatformEnableOpenGLMode(void)
11371140
{
1141+
if (s_opengl_context == nil)
1142+
MCGLContextCreate(s_opengl_context);
11381143
s_ensure_opengl = true;
11391144
}
11401145

1141-
void MCIPhoneSwitchToUIKit(void)
1146+
void MCPlatformDisableOpenGLMode(void)
11421147
{
11431148
s_ensure_opengl = false;
11441149
}
11451150

1151+
MCGLContextRef MCPlatformGetOpenGLContext(void)
1152+
{
1153+
return s_opengl_context;
1154+
}
1155+
11461156
void MCIPhoneSyncDisplayClass(void)
11471157
{
11481158
if (s_ensure_opengl && !s_is_opengl_display)
@@ -1159,6 +1169,8 @@ void MCIPhoneSyncDisplayClass(void)
11591169
s_is_opengl_display = false;
11601170
// MW-2012-08-06: [[ Fibers ]] Execute the system code on the main fiber.
11611171
MCIPhoneRunBlockOnMainFiber(^(void) {
1172+
MCGLContextDestroy(s_opengl_context);
1173+
s_opengl_context = nil;
11621174
MCIPhoneSwitchViewToUIKit();
11631175
});
11641176
}

0 commit comments

Comments
 (0)