1 # This file is part of NIT (http://www.nitlanguage.org).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Gamnit display implementation for Android
17 # Generated APK files require OpenGL ES 2.0.
19 # This modules uses `android::native_app_glue` and the Android NDK.
20 module display_android
is
21 android_manifest
"""<uses-feature android:glEsVersion="0x00020000"/>"""
25 intrude import android
::load_image
27 private import gamnit
::egl
28 intrude import textures
30 redef class GamnitDisplay
34 var native_display
= egl_default_display
35 var native_window
= app
.native_app_glue
.window
37 setup_egl_display native_display
39 # We need 8 bits per color for selection by color
40 select_egl_config
(8, 8, 8, 0, 8, 0, 0)
42 var format
= egl_config
.attribs
(egl_display
).native_visual_id
43 native_window
.set_buffers_geometry
(0, 0, format
)
45 setup_egl_context native_window
48 redef fun close
do close_egl
51 redef class GamnitAssetTexture
53 redef fun load_from_platform
55 jni_env
.push_local_frame
4
57 var asset_manager
= app
.asset_manager
58 var bmp
= asset_manager
.bitmap
(path
)
59 if bmp
.is_java_null
then
60 error
= new Error("Failed to load texture at '{path}'")
61 jni_env
.pop_local_frame
65 var buf
= bmp
.copy_pixels
67 width
= bmp
.width
.to_f
68 height
= bmp
.height
.to_f
69 var pixels
= buf
.native_array
71 load_from_pixels
(pixels
, bmp
.width
, bmp
.height
, gl_RGBA
)
73 jni_env
.pop_local_frame