Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
af424b1c
Commit
af424b1c
authored
Mar 05, 2020
by
PouleyKetchoupp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vulkan rendering for Android
parent
d9a560d7
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
499 additions
and
187 deletions
+499
-187
.gitignore
.gitignore
+1
-0
SCsub
drivers/vulkan/SCsub
+6
-1
rendering_device_vulkan.cpp
drivers/vulkan/rendering_device_vulkan.cpp
+6
-3
vulkan_context.h
drivers/vulkan/vulkan_context.h
+2
-2
SCsub
platform/android/SCsub
+1
-1
detect.py
platform/android/detect.py
+4
-4
AndroidManifest.xml
platform/android/java/lib/AndroidManifest.xml
+1
-1
build.gradle
platform/android/java/lib/build.gradle
+1
-0
Godot.java
...orm/android/java/lib/src/org/godotengine/godot/Godot.java
+33
-26
GodotGLRenderView.java
...java/lib/src/org/godotengine/godot/GodotGLRenderView.java
+30
-9
GodotLib.java
.../android/java/lib/src/org/godotengine/godot/GodotLib.java
+4
-3
GodotRenderView.java
...d/java/lib/src/org/godotengine/godot/GodotRenderView.java
+15
-14
GodotRenderer.java
...oid/java/lib/src/org/godotengine/godot/GodotRenderer.java
+1
-1
GodotVulkanRenderView.java
.../lib/src/org/godotengine/godot/GodotVulkanRenderView.java
+142
-0
GodotEditText.java
...va/lib/src/org/godotengine/godot/input/GodotEditText.java
+16
-16
GodotGestureHandler.java
.../src/org/godotengine/godot/input/GodotGestureHandler.java
+6
-6
GodotInputHandler.java
...ib/src/org/godotengine/godot/input/GodotInputHandler.java
+21
-21
GodotTextInputWrapper.java
...rc/org/godotengine/godot/input/GodotTextInputWrapper.java
+11
-11
VkRenderer.kt
...d/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt
+30
-13
VkSurfaceView.kt
...ava/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt
+3
-3
VkThread.kt
...oid/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt
+2
-2
RegularContextFactory.java
...g/godotengine/godot/xr/regular/RegularContextFactory.java
+0
-1
java_godot_lib_jni.cpp
platform/android/java_godot_lib_jni.cpp
+8
-3
java_godot_lib_jni.h
platform/android/java_godot_lib_jni.h
+1
-1
os_android.cpp
platform/android/os_android.cpp
+58
-19
os_android.h
platform/android/os_android.h
+15
-4
vulkan_context_android.cpp
platform/android/vulkan/vulkan_context_android.cpp
+68
-0
vulkan_context_android.h
platform/android/vulkan/vulkan_context_android.h
+13
-22
No files found.
.gitignore
View file @
af424b1c
...
...
@@ -21,6 +21,7 @@ project.properties
platform/android/java/lib/.cxx/
platform/android/java/libs/*
platform/android/java/app/libs/*
platform/android/java/lib/.cxx/*
# General c++ generated files
*.lib
...
...
drivers/vulkan/SCsub
View file @
af424b1c
...
...
@@ -4,7 +4,12 @@ Import("env")
env
.
add_source_files
(
env
.
drivers_sources
,
"*.cpp"
)
if
env
[
"builtin_vulkan"
]:
if
env
[
"platform"
]
==
"android"
:
# Use NDK Vulkan headers
thirdparty_dir
=
env
[
"ANDROID_NDK_ROOT"
]
+
"/sources/third_party/vulkan/src"
thirdparty_includes
=
[
thirdparty_dir
,
thirdparty_dir
+
"/include"
,
thirdparty_dir
+
"/layers"
,
thirdparty_dir
+
"/layers/generated"
]
env
.
Prepend
(
CPPPATH
=
thirdparty_includes
)
elif
env
[
"builtin_vulkan"
]:
# Use bundled Vulkan headers
thirdparty_dir
=
"#thirdparty/vulkan"
env
.
Prepend
(
CPPPATH
=
[
thirdparty_dir
,
thirdparty_dir
+
"/include"
,
thirdparty_dir
+
"/loader"
])
...
...
drivers/vulkan/rendering_device_vulkan.cpp
View file @
af424b1c
...
...
@@ -1564,15 +1564,17 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
image_create_info
.
pNext
=
nullptr
;
image_create_info
.
flags
=
0
;
VkImageFormatListCreateInfoKHR
format_list_create_info
;
Vector
<
VkFormat
>
allowed_formats
;
// TODO: vkCreateImage fails with format list on Android (VK_ERROR_OUT_OF_HOST_MEMORY)
#ifndef ANDROID_ENABLED
if
(
p_format
.
shareable_formats
.
size
())
{
image_create_info
.
flags
|=
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
;
Vector
<
VkFormat
>
allowed_formats
;
for
(
int
i
=
0
;
i
<
p_format
.
shareable_formats
.
size
();
i
++
)
{
allowed_formats
.
push_back
(
vulkan_formats
[
p_format
.
shareable_formats
[
i
]]);
}
VkImageFormatListCreateInfoKHR
format_list_create_info
;
format_list_create_info
.
sType
=
VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR
;
format_list_create_info
.
pNext
=
nullptr
;
format_list_create_info
.
viewFormatCount
=
allowed_formats
.
size
();
...
...
@@ -1584,6 +1586,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
ERR_FAIL_COND_V_MSG
(
p_view
.
format_override
!=
DATA_FORMAT_MAX
&&
p_format
.
shareable_formats
.
find
(
p_view
.
format_override
)
==
-
1
,
RID
(),
"If supplied a list of shareable formats, the current view format override must be present in the list"
);
}
#endif
if
(
p_format
.
type
==
TEXTURE_TYPE_CUBE
||
p_format
.
type
==
TEXTURE_TYPE_CUBE_ARRAY
)
{
image_create_info
.
flags
|=
VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
;
}
...
...
drivers/vulkan/vulkan_context.h
View file @
af424b1c
...
...
@@ -45,8 +45,6 @@ class VulkanContext {
FRAME_LAG
=
2
};
bool
use_validation_layers
;
VkInstance
inst
;
VkSurfaceKHR
surface
;
VkPhysicalDevice
gpu
;
...
...
@@ -181,6 +179,8 @@ protected:
bool
buffers_prepared
;
bool
use_validation_layers
;
public
:
VkDevice
get_device
();
VkPhysicalDevice
get_physical_device
();
...
...
platform/android/SCsub
View file @
af424b1c
...
...
@@ -17,8 +17,8 @@ android_files = [
"java_godot_io_wrapper.cpp"
,
"jni_utils.cpp"
,
"android_keys_utils.cpp"
,
"vulkan/vk_renderer_jni.cpp"
,
"plugin/godot_plugin_jni.cpp"
,
"vulkan/vulkan_context_android.cpp"
]
env_android
=
env
.
Clone
()
...
...
platform/android/detect.py
View file @
af424b1c
...
...
@@ -25,7 +25,7 @@ def get_opts():
return
[
(
"ANDROID_NDK_ROOT"
,
"Path to the Android NDK"
,
os
.
environ
.
get
(
"ANDROID_NDK_ROOT"
,
0
)),
(
"ndk_platform"
,
'Target platform (android-<api>, e.g. "android-
18")'
,
"android-18
"
),
(
"ndk_platform"
,
'Target platform (android-<api>, e.g. "android-
24")'
,
"android-24
"
),
EnumVariable
(
"android_arch"
,
"Target architecture"
,
"armv7"
,
(
"armv7"
,
"arm64v8"
,
"x86"
,
"x86_64"
)),
BoolVariable
(
"android_neon"
,
"Enable NEON support (armv7 only)"
,
True
),
]
...
...
@@ -102,7 +102,7 @@ def configure(env):
neon_text
=
""
if
env
[
"android_arch"
]
==
"armv7"
and
env
[
"android_neon"
]:
neon_text
=
" (with NEON)"
print
(
"Building for Android ("
+
env
[
"android_arch"
]
+
")"
+
neon_text
)
print
(
"Building for Android
, platform "
+
env
[
"ndk_platform"
]
+
"
("
+
env
[
"android_arch"
]
+
")"
+
neon_text
)
can_vectorize
=
True
if
env
[
"android_arch"
]
==
"x86"
:
...
...
@@ -314,8 +314,8 @@ def configure(env):
)
env
.
Prepend
(
CPPPATH
=
[
"#platform/android"
])
env
.
Append
(
CPPDEFINES
=
[
"ANDROID_ENABLED"
,
"UNIX_ENABLED"
,
"NO_FCNTL"
])
env
.
Append
(
LIBS
=
[
"OpenSLES"
,
"EGL"
,
"GLESv
3"
,
"GLESv2
"
,
"android"
,
"log"
,
"z"
,
"dl"
])
env
.
Append
(
CPPDEFINES
=
[
"ANDROID_ENABLED"
,
"UNIX_ENABLED"
,
"
VULKAN_ENABLED"
,
"
NO_FCNTL"
])
env
.
Append
(
LIBS
=
[
"OpenSLES"
,
"EGL"
,
"GLESv
2"
,
"vulkan
"
,
"android"
,
"log"
,
"z"
,
"dl"
])
# Return NDK version string in source.properties (adapted from the Chromium project).
...
...
platform/android/java/lib/AndroidManifest.xml
View file @
af424b1c
...
...
@@ -13,7 +13,7 @@
<instrumentation
android:icon=
"@mipmap/icon"
android:label=
"@string/godot_project_name_string"
android:name=
".GodotInstrumentation"
android:name=
"
org.godotengine.godot
.GodotInstrumentation"
android:targetPackage=
"org.godotengine.godot"
/>
</manifest>
platform/android/java/lib/build.gradle
View file @
af424b1c
apply
plugin:
'com.android.library'
apply
plugin:
'kotlin-android'
dependencies
{
implementation
libraries
.
supportCoreUtils
...
...
platform/android/java/lib/src/org/godotengine/godot/Godot.java
View file @
af424b1c
...
...
@@ -153,7 +153,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
private
String
[]
command_line
;
private
boolean
use_apk_expansion
;
public
Godot
View
m
View
;
public
Godot
RenderView
mRender
View
;
private
boolean
godot_initialized
=
false
;
private
SensorManager
mSensorManager
;
...
...
@@ -213,34 +213,41 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
setContentView
(
layout
);
// GodotEditText layout
GodotEditText
edit
t
ext
=
new
GodotEditText
(
this
);
edit
t
ext
.
setLayoutParams
(
new
ViewGroup
.
LayoutParams
(
LayoutParams
.
MATCH_PARENT
,
LayoutParams
.
WRAP_CONTENT
));
GodotEditText
edit
T
ext
=
new
GodotEditText
(
this
);
edit
T
ext
.
setLayoutParams
(
new
ViewGroup
.
LayoutParams
(
LayoutParams
.
MATCH_PARENT
,
LayoutParams
.
WRAP_CONTENT
));
// ...add to FrameLayout
layout
.
addView
(
edit
t
ext
);
layout
.
addView
(
edit
T
ext
);
mView
=
new
GodotView
(
this
,
xrMode
,
use_32_bits
,
use_debug_opengl
);
layout
.
addView
(
mView
,
new
LayoutParams
(
LayoutParams
.
MATCH_PARENT
,
LayoutParams
.
MATCH_PARENT
));
edittext
.
setView
(
mView
);
io
.
setEdit
(
edittext
);
GodotLib
.
setup
(
command_line
);
mView
.
getViewTreeObserver
().
addOnGlobalLayoutListener
(
new
ViewTreeObserver
.
OnGlobalLayoutListener
()
{
final
String
videoDriver
=
GodotLib
.
getGlobal
(
"rendering/quality/driver/driver_name"
);
if
(
videoDriver
.
equals
(
"Vulkan"
))
{
mRenderView
=
new
GodotVulkanRenderView
(
this
);
}
else
{
mRenderView
=
new
GodotGLRenderView
(
this
,
xrMode
,
use_32_bits
,
use_debug_opengl
);
}
View
view
=
mRenderView
.
getView
();
layout
.
addView
(
view
,
new
LayoutParams
(
LayoutParams
.
MATCH_PARENT
,
LayoutParams
.
MATCH_PARENT
));
editText
.
setView
(
mRenderView
);
io
.
setEdit
(
editText
);
view
.
getViewTreeObserver
().
addOnGlobalLayoutListener
(
new
ViewTreeObserver
.
OnGlobalLayoutListener
()
{
@Override
public
void
onGlobalLayout
()
{
Point
fullSize
=
new
Point
();
getWindowManager
().
getDefaultDisplay
().
getSize
(
fullSize
);
Rect
gameSize
=
new
Rect
();
m
View
.
getWindowVisibleDisplayFrame
(
gameSize
);
m
RenderView
.
getView
()
.
getWindowVisibleDisplayFrame
(
gameSize
);
final
int
keyboardHeight
=
fullSize
.
y
-
gameSize
.
bottom
;
GodotLib
.
setVirtualKeyboardHeight
(
keyboardHeight
);
}
});
final
String
[]
current_command_line
=
command_line
;
mView
.
queueEvent
(
new
Runnable
()
{
mRenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
GodotLib
.
setup
(
current_command_line
);
// Must occur after GodotLib.setup has completed.
for
(
GodotPlugin
plugin
:
pluginRegistry
.
getAllPlugins
())
{
...
...
@@ -384,7 +391,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
*/
@Keep
private
Surface
getSurface
()
{
return
m
View
.
getHolder
().
getSurface
();
return
m
RenderView
.
getView
()
.
getHolder
().
getSurface
();
}
/**
...
...
@@ -617,7 +624,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
}
return
;
}
m
View
.
onPause
();
m
RenderView
.
onActivityPaused
();
mSensorManager
.
unregisterListener
(
this
);
...
...
@@ -655,7 +662,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
return
;
}
m
View
.
onResume
();
m
RenderView
.
onActivityResumed
();
mSensorManager
.
registerListener
(
this
,
mAccelerometer
,
SensorManager
.
SENSOR_DELAY_GAME
);
mSensorManager
.
registerListener
(
this
,
mGravity
,
SensorManager
.
SENSOR_DELAY_GAME
);
...
...
@@ -721,8 +728,8 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
final
float
z
=
adjustedValues
[
2
];
final
int
typeOfSensor
=
event
.
sensor
.
getType
();
if
(
mView
!=
null
)
{
m
View
.
queueEvent
(
new
Runnable
()
{
if
(
m
Render
View
!=
null
)
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
typeOfSensor
==
Sensor
.
TYPE_ACCELEROMETER
)
{
...
...
@@ -773,8 +780,8 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
}
}
if
(
shouldQuit
&&
mView
!=
null
)
{
m
View
.
queueEvent
(
new
Runnable
()
{
if
(
shouldQuit
&&
m
Render
View
!=
null
)
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
GodotLib
.
back
();
...
...
@@ -789,8 +796,8 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
* This must be called after the render thread has started.
*/
public
final
void
runOnRenderThread
(
@NonNull
Runnable
action
)
{
if
(
mView
!=
null
)
{
m
View
.
queueEvent
(
action
);
if
(
m
Render
View
!=
null
)
{
m
RenderView
.
queueOnRenderThread
(
action
);
}
}
...
...
@@ -847,7 +854,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
if
(
evcount
==
0
)
return
true
;
if
(
mView
!=
null
)
{
if
(
m
Render
View
!=
null
)
{
final
int
[]
arr
=
new
int
[
event
.
getPointerCount
()
*
3
];
for
(
int
i
=
0
;
i
<
event
.
getPointerCount
();
i
++)
{
...
...
@@ -860,7 +867,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
//System.out.printf("gaction: %d\n",event.getAction());
final
int
action
=
event
.
getAction
()
&
MotionEvent
.
ACTION_MASK
;
m
View
.
queueEvent
(
new
Runnable
()
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
switch
(
action
)
{
...
...
@@ -911,7 +918,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
for
(
int
i
=
cc
.
length
;
--
i
>=
0
;
cnt
+=
cc
[
i
]
!=
0
?
1
:
0
)
;
if
(
cnt
==
0
)
return
super
.
onKeyMultiple
(
inKeyCode
,
repeatCount
,
event
);
m
View
.
queueEvent
(
new
Runnable
()
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
// This method will be called on the rendering thread:
public
void
run
()
{
for
(
int
i
=
0
,
n
=
cc
.
length
;
i
<
n
;
i
++)
{
...
...
@@ -1033,6 +1040,6 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
progress
.
mOverallTotal
));
}
public
void
initInputDevices
()
{
mView
.
initInputDevices
();
m
Render
View
.
initInputDevices
();
}
}
platform/android/java/lib/src/org/godotengine/godot/GodotView.java
→
platform/android/java/lib/src/org/godotengine/godot/Godot
GLRender
View.java
View file @
af424b1c
/*************************************************************************/
/* Godot
View.java
*/
/* Godot
GLRenderView.java
*/
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
...
...
@@ -35,6 +35,7 @@ import android.opengl.GLSurfaceView;
import
android.view.GestureDetector
;
import
android.view.KeyEvent
;
import
android.view.MotionEvent
;
import
android.view.SurfaceView
;
import
org.godotengine.godot.input.GodotGestureHandler
;
import
org.godotengine.godot.input.GodotInputHandler
;
import
org.godotengine.godot.utils.GLUtils
;
...
...
@@ -64,16 +65,14 @@ import org.godotengine.godot.xr.regular.RegularFallbackConfigChooser;
* that matches it exactly (with regards to red/green/blue/alpha channels
* bit depths). Failure to do so would result in an EGL_BAD_MATCH error.
*/
public
class
GodotView
extends
GLSurfaceView
{
private
static
String
TAG
=
GodotView
.
class
.
getSimpleName
();
public
class
GodotGLRenderView
extends
GLSurfaceView
implements
GodotRenderView
{
private
final
Godot
activity
;
private
final
GodotInputHandler
inputHandler
;
private
final
GestureDetector
detector
;
private
final
GodotRenderer
godotRenderer
;
public
GodotView
(
Godot
activity
,
XRMode
xrMode
,
boolean
p_use_32_bits
,
boolean
p_use_debug_opengl
)
{
public
Godot
GLRender
View
(
Godot
activity
,
XRMode
xrMode
,
boolean
p_use_32_bits
,
boolean
p_use_debug_opengl
)
{
super
(
activity
);
GLUtils
.
use_32
=
p_use_32_bits
;
GLUtils
.
use_debug_opengl
=
p_use_debug_opengl
;
...
...
@@ -85,10 +84,36 @@ public class GodotView extends GLSurfaceView {
init
(
xrMode
,
false
,
16
,
0
);
}
@Override
public
SurfaceView
getView
()
{
return
this
;
}
@Override
public
void
initInputDevices
()
{
this
.
inputHandler
.
initInputDevices
();
}
@Override
public
void
queueOnRenderThread
(
Runnable
event
)
{
queueEvent
(
event
);
}
@Override
public
void
onActivityPaused
()
{
onPause
();
}
@Override
public
void
onActivityResumed
()
{
onResume
();
}
@Override
public
void
onBackPressed
()
{
activity
.
onBackPressed
();
}
@SuppressLint
(
"ClickableViewAccessibility"
)
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
...
...
@@ -170,10 +195,6 @@ public class GodotView extends GLSurfaceView {
setRenderer
(
godotRenderer
);
}
public
void
onBackPressed
()
{
activity
.
onBackPressed
();
}
@Override
public
void
onResume
()
{
super
.
onResume
();
...
...
platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
View file @
af424b1c
...
...
@@ -32,6 +32,7 @@ package org.godotengine.godot;
import
android.app.Activity
;
import
android.hardware.SensorEvent
;
import
android.view.Surface
;
import
javax.microedition.khronos.egl.EGLConfig
;
import
javax.microedition.khronos.opengles.GL10
;
...
...
@@ -72,11 +73,11 @@ public class GodotLib {
public
static
native
void
resize
(
int
width
,
int
height
);
/**
* Invoked on the GL thread when the underlying Android surface is created or recreated.
* Invoked on the render thread when the underlying Android surface is created or recreated.
* @param p_surface
* @param p_32_bits
* @see android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)
*/
public
static
native
void
newcontext
(
boolean
p_32_bits
);
public
static
native
void
newcontext
(
Surface
p_surface
,
boolean
p_32_bits
);
/**
* Forward {@link Activity#onBackPressed()} event from the main thread to the GL thread.
...
...
platform/android/
vulkan/vk_renderer_jni.h
→
platform/android/
java/lib/src/org/godotengine/godot/GodotRenderView.java
View file @
af424b1c
/*************************************************************************/
/*
vk_renderer_jni.h
*/
/*
GodotRenderView.java
*/
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
...
...
@@ -28,19 +28,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef VK_RENDERER_JNI_H
#define VK_RENDERER_JNI_H
package
org
.
godotengine
.
godot
;
#include <android/log.h>
#include <jni.h>
import
android.view.SurfaceView
;
extern
"C"
{
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceCreated
(
JNIEnv
*
env
,
jobject
obj
,
jobject
j_surface
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceChanged
(
JNIEnv
*
env
,
jobject
object
,
jobject
j_surface
,
jint
width
,
jint
height
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkResume
(
JNIEnv
*
env
,
jobject
obj
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDrawFrame
(
JNIEnv
*
env
,
jobject
obj
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkPause
(
JNIEnv
*
env
,
jobject
obj
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDestroy
(
JNIEnv
*
env
,
jobject
obj
);
}
public
interface
GodotRenderView
{
abstract
public
SurfaceView
getView
();
abstract
public
void
initInputDevices
();
#endif // VK_RENDERER_JNI_H
abstract
public
void
queueOnRenderThread
(
Runnable
event
);
abstract
public
void
onActivityPaused
();
abstract
public
void
onActivityResumed
();
abstract
public
void
onBackPressed
();
}
platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
View file @
af424b1c
...
...
@@ -70,7 +70,7 @@ class GodotRenderer implements GLSurfaceView.Renderer {
}
public
void
onSurfaceCreated
(
GL10
gl
,
EGLConfig
config
)
{
GodotLib
.
newcontext
(
GLUtils
.
use_32
);
GodotLib
.
newcontext
(
null
,
GLUtils
.
use_32
);
for
(
GodotPlugin
plugin
:
pluginRegistry
.
getAllPlugins
())
{
plugin
.
onGLSurfaceCreated
(
gl
,
config
);
}
...
...
platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java
0 → 100644
View file @
af424b1c
/*************************************************************************/
/* GodotVulkanRenderView.java */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
package
org
.
godotengine
.
godot
;
import
android.annotation.SuppressLint
;
import
android.view.GestureDetector
;
import
android.view.KeyEvent
;
import
android.view.MotionEvent
;
import
android.view.SurfaceView
;
import
org.godotengine.godot.input.GodotGestureHandler
;
import
org.godotengine.godot.input.GodotInputHandler
;
import
org.godotengine.godot.vulkan.VkRenderer
;
import
org.godotengine.godot.vulkan.VkSurfaceView
;
public
class
GodotVulkanRenderView
extends
VkSurfaceView
implements
GodotRenderView
{
private
final
Godot
mActivity
;
private
final
GodotInputHandler
mInputHandler
;
private
final
GestureDetector
mGestureDetector
;
private
final
VkRenderer
mRenderer
;
public
GodotVulkanRenderView
(
Godot
activity
)
{
super
(
activity
);
mActivity
=
activity
;
mInputHandler
=
new
GodotInputHandler
(
this
);
mGestureDetector
=
new
GestureDetector
(
mActivity
,
new
GodotGestureHandler
(
this
));
mRenderer
=
new
VkRenderer
();
setFocusableInTouchMode
(
true
);
startRenderer
(
mRenderer
);
}
@Override
public
SurfaceView
getView
()
{
return
this
;
}
@Override
public
void
initInputDevices
()
{
mInputHandler
.
initInputDevices
();
}
@Override
public
void
queueOnRenderThread
(
Runnable
event
)
{
queueOnVkThread
(
event
);
}
@Override
public
void
onActivityPaused
()
{
onPause
();
}
@Override
public
void
onActivityResumed
()
{
onResume
();
}
@Override
public
void
onBackPressed
()
{
mActivity
.
onBackPressed
();
}
@SuppressLint
(
"ClickableViewAccessibility"
)
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
super
.
onTouchEvent
(
event
);
mGestureDetector
.
onTouchEvent
(
event
);
return
mActivity
.
gotTouchEvent
(
event
);
}
@Override
public
boolean
onKeyUp
(
final
int
keyCode
,
KeyEvent
event
)
{
return
mInputHandler
.
onKeyUp
(
keyCode
,
event
)
||
super
.
onKeyUp
(
keyCode
,
event
);
}
@Override
public
boolean
onKeyDown
(
final
int
keyCode
,
KeyEvent
event
)
{
return
mInputHandler
.
onKeyDown
(
keyCode
,
event
)
||
super
.
onKeyDown
(
keyCode
,
event
);
}
@Override
public
boolean
onGenericMotionEvent
(
MotionEvent
event
)
{
return
mInputHandler
.
onGenericMotionEvent
(
event
)
||
super
.
onGenericMotionEvent
(
event
);
}
@Override
public
void
onResume
()
{
super
.
onResume
();
queueOnVkThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
// Resume the renderer
mRenderer
.
onVkResume
();
GodotLib
.
focusin
();
}
});
}
@Override
public
void
onPause
()
{
super
.
onPause
();
queueOnVkThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
GodotLib
.
focusout
();
// Pause the renderer
mRenderer
.
onVkPause
();
}
});
}
}
platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
View file @
af424b1c
...
...
@@ -51,7 +51,7 @@ public class GodotEditText extends EditText {
// ===========================================================
// Fields
// ===========================================================
private
Godot
View
m
View
;
private
Godot
RenderView
mRender
View
;
private
GodotTextInputWrapper
mInputWrapper
;
private
EditHandler
sHandler
=
new
EditHandler
(
this
);
private
String
mOriginText
;
...
...
@@ -76,22 +76,22 @@ public class GodotEditText extends EditText {
// ===========================================================
public
GodotEditText
(
final
Context
context
)
{
super
(
context
);
this
.
initView
();
initView
();
}
public
GodotEditText
(
final
Context
context
,
final
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
this
.
initView
();
initView
();
}
public
GodotEditText
(
final
Context
context
,
final
AttributeSet
attrs
,
final
int
defStyle
)
{
super
(
context
,
attrs
,
defStyle
);
this
.
initView
();
initView
();
}
protected
void
initView
()
{
this
.
setPadding
(
0
,
0
,
0
,
0
);
this
.
setImeOptions
(
EditorInfo
.
IME_FLAG_NO_EXTRACT_UI
);
setPadding
(
0
,
0
,
0
,
0
);
setImeOptions
(
EditorInfo
.
IME_FLAG_NO_EXTRACT_UI
);
}
private
void
handleMessage
(
final
Message
msg
)
{
...
...
@@ -106,7 +106,7 @@ public class GodotEditText extends EditText {
edit
.
mInputWrapper
.
setOriginText
(
text
);
edit
.
addTextChangedListener
(
edit
.
mInputWrapper
);
setMaxInputLength
(
edit
,
msg
.
arg1
);
final
InputMethodManager
imm
=
(
InputMethodManager
)
m
View
.
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
final
InputMethodManager
imm
=
(
InputMethodManager
)
m
RenderView
.
getView
()
.
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
showSoftInput
(
edit
,
0
);
}
}
break
;
...
...
@@ -115,9 +115,9 @@ public class GodotEditText extends EditText {
GodotEditText
edit
=
(
GodotEditText
)
msg
.
obj
;
edit
.
removeTextChangedListener
(
mInputWrapper
);
final
InputMethodManager
imm
=
(
InputMethodManager
)
m
View
.
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
final
InputMethodManager
imm
=
(
InputMethodManager
)
m
RenderView
.
getView
()
.
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
edit
.
getWindowToken
(),
0
);
edit
.
m
View
.
requestFocus
();
edit
.
m
RenderView
.
getView
()
.
requestFocus
();
}
break
;
}
}
...
...
@@ -135,12 +135,12 @@ public class GodotEditText extends EditText {
// ===========================================================
// Getter & Setter
// ===========================================================
public
void
setView
(
final
GodotView
view
)
{
this
.
m
View
=
view
;
public
void
setView
(
final
Godot
Render
View
view
)
{
mRender
View
=
view
;
if
(
mInputWrapper
==
null
)
mInputWrapper
=
new
GodotTextInputWrapper
(
mView
,
this
);
this
.
setOnEditorActionListener
(
mInputWrapper
);
view
.
requestFocus
();
mInputWrapper
=
new
GodotTextInputWrapper
(
m
Render
View
,
this
);
setOnEditorActionListener
(
mInputWrapper
);
view
.
getView
().
requestFocus
();
}
// ===========================================================
...
...
@@ -152,7 +152,7 @@ public class GodotEditText extends EditText {
/* Let GlSurfaceView get focus if back key is input. */
if
(
keyCode
==
KeyEvent
.
KEYCODE_BACK
)
{
this
.
mView
.
requestFocus
();
mRenderView
.
getView
()
.
requestFocus
();
}
return
true
;
...
...
@@ -162,7 +162,7 @@ public class GodotEditText extends EditText {
// Methods
// ===========================================================
public
void
showKeyboard
(
String
p_existing_text
,
int
p_max_input_length
)
{
this
.
mOriginText
=
p_existing_text
;
mOriginText
=
p_existing_text
;
final
Message
msg
=
new
Message
();
msg
.
what
=
HANDLER_OPEN_IME_KEYBOARD
;
...
...
platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java
View file @
af424b1c
...
...
@@ -34,22 +34,22 @@ import android.util.Log;
import
android.view.GestureDetector
;
import
android.view.MotionEvent
;
import
org.godotengine.godot.GodotLib
;
import
org.godotengine.godot.GodotView
;
import
org.godotengine.godot.Godot
Render
View
;
/**
* Handles gesture input related events for the {@link GodotView} view.
* Handles gesture input related events for the {@link Godot
Render
View} view.
* https://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener
*/
public
class
GodotGestureHandler
extends
GestureDetector
.
SimpleOnGestureListener
{
private
final
Godot
View
godot
View
;
private
final
Godot
RenderView
mRender
View
;
public
GodotGestureHandler
(
GodotView
godotView
)
{
this
.
godot
View
=
godotView
;
public
GodotGestureHandler
(
Godot
Render
View
godotView
)
{
mRender
View
=
godotView
;
}
private
void
queueEvent
(
Runnable
task
)
{
godotView
.
queueEvent
(
task
);
mRenderView
.
queueOnRenderThread
(
task
);
}
@Override
...
...
platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
View file @
af424b1c
...
...
@@ -42,27 +42,27 @@ import java.util.Collections;
import
java.util.Comparator
;
import
java.util.List
;
import
org.godotengine.godot.GodotLib
;
import
org.godotengine.godot.GodotView
;
import
org.godotengine.godot.Godot
Render
View
;
import
org.godotengine.godot.input.InputManagerCompat.InputDeviceListener
;
/**
* Handles input related events for the {@link GodotView} view.
* Handles input related events for the {@link Godot
Render
View} view.
*/
public
class
GodotInputHandler
implements
InputDeviceListener
{
private
final
ArrayList
<
Joystick
>
j
oysticksDevices
=
new
ArrayList
<
Joystick
>();
private
final
ArrayList
<
Joystick
>
mJ
oysticksDevices
=
new
ArrayList
<
Joystick
>();
private
final
Godot
View
godot
View
;
private
final
InputManagerCompat
i
nputManager
;
private
final
Godot
RenderView
mRender
View
;
private
final
InputManagerCompat
mI
nputManager
;
public
GodotInputHandler
(
GodotView
godotView
)
{
this
.
godot
View
=
godotView
;
this
.
inputManager
=
InputManagerCompat
.
Factory
.
getInputManager
(
godotView
.
getContext
());
this
.
i
nputManager
.
registerInputDeviceListener
(
this
,
null
);
public
GodotInputHandler
(
Godot
Render
View
godotView
)
{
mRender
View
=
godotView
;
mInputManager
=
InputManagerCompat
.
Factory
.
getInputManager
(
mRenderView
.
getView
()
.
getContext
());
mI
nputManager
.
registerInputDeviceListener
(
this
,
null
);
}
private
void
queueEvent
(
Runnable
task
)
{
godotView
.
queueEvent
(
task
);
mRenderView
.
queueOnRenderThread
(
task
);
}
private
boolean
isKeyEvent_GameDevice
(
int
source
)
{
...
...
@@ -113,7 +113,7 @@ public class GodotInputHandler implements InputDeviceListener {
public
boolean
onKeyDown
(
final
int
keyCode
,
KeyEvent
event
)
{
if
(
keyCode
==
KeyEvent
.
KEYCODE_BACK
)
{
godot
View
.
onBackPressed
();
mRender
View
.
onBackPressed
();
// press 'back' button should not terminate program
//normal handle 'back' event in game logic
return
true
;
...
...
@@ -164,7 +164,7 @@ public class GodotInputHandler implements InputDeviceListener {
// Check if the device exists
if
(
device_id
>
-
1
)
{
Joystick
joy
=
j
oysticksDevices
.
get
(
device_id
);
Joystick
joy
=
mJ
oysticksDevices
.
get
(
device_id
);
for
(
int
i
=
0
;
i
<
joy
.
axes
.
size
();
i
++)
{
InputDevice
.
MotionRange
range
=
joy
.
axes
.
get
(
i
);
...
...
@@ -208,11 +208,11 @@ public class GodotInputHandler implements InputDeviceListener {
public
void
initInputDevices
()
{
/* initially add input devices*/
int
[]
deviceIds
=
i
nputManager
.
getInputDeviceIds
();
int
[]
deviceIds
=
mI
nputManager
.
getInputDeviceIds
();
for
(
int
deviceId
:
deviceIds
)
{
InputDevice
device
=
i
nputManager
.
getInputDevice
(
deviceId
);
InputDevice
device
=
mI
nputManager
.
getInputDevice
(
deviceId
);
if
(
DEBUG
)
{
Log
.
v
(
"Godot
View
"
,
String
.
format
(
"init() deviceId:%d, Name:%s\n"
,
deviceId
,
device
.
getName
()));
Log
.
v
(
"Godot
InputHandler
"
,
String
.
format
(
"init() deviceId:%d, Name:%s\n"
,
deviceId
,
device
.
getName
()));
}
onInputDeviceAdded
(
deviceId
);
}
...
...
@@ -224,13 +224,13 @@ public class GodotInputHandler implements InputDeviceListener {
// Check if the device has not been already added
if
(
id
<
0
)
{
InputDevice
device
=
i
nputManager
.
getInputDevice
(
deviceId
);
InputDevice
device
=
mI
nputManager
.
getInputDevice
(
deviceId
);
//device can be null if deviceId is not found
if
(
device
!=
null
)
{
int
sources
=
device
.
getSources
();
if
(((
sources
&
InputDevice
.
SOURCE_GAMEPAD
)
==
InputDevice
.
SOURCE_GAMEPAD
)
||
((
sources
&
InputDevice
.
SOURCE_JOYSTICK
)
==
InputDevice
.
SOURCE_JOYSTICK
))
{
id
=
j
oysticksDevices
.
size
();
id
=
mJ
oysticksDevices
.
size
();
Joystick
joy
=
new
Joystick
();
joy
.
device_id
=
deviceId
;
...
...
@@ -249,7 +249,7 @@ public class GodotInputHandler implements InputDeviceListener {
}
}
j
oysticksDevices
.
add
(
joy
);
mJ
oysticksDevices
.
add
(
joy
);
final
int
device_id
=
id
;
final
String
name
=
joy
.
name
;
...
...
@@ -270,7 +270,7 @@ public class GodotInputHandler implements InputDeviceListener {
// Check if the evice has not been already removed
if
(
device_id
>
-
1
)
{
j
oysticksDevices
.
remove
(
device_id
);
mJ
oysticksDevices
.
remove
(
device_id
);
queueEvent
(
new
Runnable
()
{
@Override
...
...
@@ -360,8 +360,8 @@ public class GodotInputHandler implements InputDeviceListener {
}
private
int
findJoystickDevice
(
int
device_id
)
{
for
(
int
i
=
0
;
i
<
j
oysticksDevices
.
size
();
i
++)
{
if
(
j
oysticksDevices
.
get
(
i
).
device_id
==
device_id
)
{
for
(
int
i
=
0
;
i
<
mJ
oysticksDevices
.
size
();
i
++)
{
if
(
mJ
oysticksDevices
.
get
(
i
).
device_id
==
device_id
)
{
return
i
;
}
}
...
...
platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java
View file @
af424b1c
...
...
@@ -48,7 +48,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
// ===========================================================
// Fields
// ===========================================================
private
final
Godot
View
m
View
;
private
final
Godot
RenderView
mRender
View
;
private
final
GodotEditText
mEdit
;
private
String
mOriginText
;
...
...
@@ -56,9 +56,9 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
// Constructors
// ===========================================================
public
GodotTextInputWrapper
(
final
GodotView
view
,
final
GodotEditText
edit
)
{
this
.
m
View
=
view
;
this
.
mEdit
=
edit
;
public
GodotTextInputWrapper
(
final
Godot
Render
View
view
,
final
GodotEditText
edit
)
{
mRender
View
=
view
;
mEdit
=
edit
;
}
// ===========================================================
...
...
@@ -66,13 +66,13 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
// ===========================================================
private
boolean
isFullScreenEdit
()
{
final
TextView
textField
=
this
.
mEdit
;
final
TextView
textField
=
mEdit
;
final
InputMethodManager
imm
=
(
InputMethodManager
)
textField
.
getContext
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
return
imm
.
isFullscreenMode
();
}
public
void
setOriginText
(
final
String
originText
)
{
this
.
mOriginText
=
originText
;
mOriginText
=
originText
;
}
// ===========================================================
...
...
@@ -87,7 +87,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
public
void
beforeTextChanged
(
final
CharSequence
pCharSequence
,
final
int
start
,
final
int
count
,
final
int
after
)
{
//Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after);
m
View
.
queueEvent
(
new
Runnable
()
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
...
...
@@ -106,7 +106,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
for
(
int
i
=
start
;
i
<
start
+
count
;
++
i
)
{
newChars
[
i
-
start
]
=
pCharSequence
.
charAt
(
i
);
}
m
View
.
queueEvent
(
new
Runnable
()
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
...
...
@@ -124,10 +124,10 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@Override
public
boolean
onEditorAction
(
final
TextView
pTextView
,
final
int
pActionID
,
final
KeyEvent
pKeyEvent
)
{
if
(
this
.
mEdit
==
pTextView
&&
this
.
isFullScreenEdit
())
{
if
(
mEdit
==
pTextView
&&
isFullScreenEdit
())
{
final
String
characters
=
pKeyEvent
.
getCharacters
();
m
View
.
queueEvent
(
new
Runnable
()
{
m
RenderView
.
queueOnRenderThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
characters
.
length
();
i
++)
{
...
...
@@ -144,7 +144,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
GodotLib
.
key
(
KeyEvent
.
KEYCODE_ENTER
,
KeyEvent
.
KEYCODE_ENTER
,
0
,
true
);
GodotLib
.
key
(
KeyEvent
.
KEYCODE_ENTER
,
KeyEvent
.
KEYCODE_ENTER
,
0
,
false
);
this
.
mView
.
requestFocus
();
mRenderView
.
getView
()
.
requestFocus
();
return
true
;
}
return
false
;
...
...
platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt
View file @
af424b1c
...
...
@@ -33,6 +33,11 @@ package org.godotengine.godot.vulkan
import
android.view.Surface
import
org.godotengine.godot.Godot
import
org.godotengine.godot.GodotLib
import
org.godotengine.godot.plugin.GodotPlugin
import
org.godotengine.godot.plugin.GodotPluginRegistry
/**
* Responsible to setting up and driving the Vulkan rendering logic.
*
...
...
@@ -48,52 +53,64 @@ import android.view.Surface
*/
internal
class
VkRenderer
{
private
val
pluginRegistry
:
GodotPluginRegistry
=
GodotPluginRegistry
.
getPluginRegistry
()
/**
* Called when the surface is created and signals the beginning of rendering.
*/
fun
onVkSurfaceCreated
(
surface
:
Surface
)
{
nativeOnVkSurfaceCreated
(
surface
)
// TODO: properly implement surface re-creation:
// GodotLib.newcontext should be called here once it's done.
//GodotLib.newcontext(surface, false)
for
(
plugin
in
pluginRegistry
.
getAllPlugins
())
{
plugin
.
onVkSurfaceCreated
(
surface
)
}
}
/**
* Called after the surface is created and whenever its size changes.
*/
fun
onVkSurfaceChanged
(
surface
:
Surface
,
width
:
Int
,
height
:
Int
)
{
nativeOnVkSurfaceChanged
(
surface
,
width
,
height
)
GodotLib
.
resize
(
width
,
height
)
// TODO: properly implement surface re-creation:
// Update the native renderer instead of restarting the app.
// GodotLib.newcontext should not be called here once it's done.
GodotLib
.
newcontext
(
surface
,
false
)
for
(
plugin
in
pluginRegistry
.
getAllPlugins
())
{
plugin
.
onVkSurfaceChanged
(
surface
,
width
,
height
)
}
}
/**
* Called to draw the current frame.
*/
fun
onVkDrawFrame
()
{
nativeOnVkDrawFrame
()
GodotLib
.
step
()
for
(
plugin
in
pluginRegistry
.
getAllPlugins
())
{
plugin
.
onVkDrawFrame
()
}
}
/**
* Called when the rendering thread is resumed.
*/
fun
onVkResume
()
{
nativeOnVkResume
()
GodotLib
.
onRendererResumed
()
}
/**
* Called when the rendering thread is paused.
*/
fun
onVkPause
()
{
nativeOnVkPause
()
GodotLib
.
onRendererPaused
()
}
/**
* Called when the rendering thread is destroyed and used as signal to tear down the Vulkan logic.
*/
fun
onVkDestroy
()
{
nativeOnVkDestroy
()
}
private
external
fun
nativeOnVkSurfaceCreated
(
surface
:
Surface
)
private
external
fun
nativeOnVkSurfaceChanged
(
surface
:
Surface
,
width
:
Int
,
height
:
Int
)
private
external
fun
nativeOnVkResume
()
private
external
fun
nativeOnVkDrawFrame
()
private
external
fun
nativeOnVkPause
()
private
external
fun
nativeOnVkDestroy
()
}
platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt
View file @
af424b1c
...
...
@@ -49,7 +49,7 @@ import android.view.SurfaceView
* UI thread.
* </ul>
*/
internal
class
VkSurfaceView
(
context
:
Context
)
:
SurfaceView
(
context
),
SurfaceHolder
.
Callback
{
open
internal
class
VkSurfaceView
(
context
:
Context
)
:
SurfaceView
(
context
),
SurfaceHolder
.
Callback
{
companion
object
{
fun
checkState
(
expression
:
Boolean
,
errorMessage
:
Any
)
{
...
...
@@ -100,7 +100,7 @@ internal class VkSurfaceView(context: Context) : SurfaceView(context), SurfaceHo
*
* Must not be called before a [VkRenderer] has been set.
*/
fun
onResume
()
{
open
fun
onResume
()
{
vkThread
.
onResume
()
}
...
...
@@ -109,7 +109,7 @@ internal class VkSurfaceView(context: Context) : SurfaceView(context), SurfaceHo
*
* Must not be called before a [VkRenderer] has been set.
*/
fun
onPause
()
{
open
fun
onPause
()
{
vkThread
.
onPause
()
}
...
...
platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt
View file @
af424b1c
...
...
@@ -219,9 +219,9 @@ internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vk
vkRenderer
.
onVkDrawFrame
()
}
}
catch
(
ex
:
InterruptedException
)
{
Log
.
i
(
TAG
,
ex
.
message
)
Log
.
i
(
TAG
,
"InterruptedException"
,
ex
)
}
catch
(
ex
:
IllegalStateException
)
{
Log
.
i
(
TAG
,
ex
.
message
)
Log
.
i
(
TAG
,
"IllegalStateException"
,
ex
)
}
finally
{
threadExiting
()
}
...
...
platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java
View file @
af424b1c
...
...
@@ -51,7 +51,6 @@ public class RegularContextFactory implements GLSurfaceView.EGLContextFactory {
private
static
int
EGL_CONTEXT_CLIENT_VERSION
=
0x3098
;
public
EGLContext
createContext
(
EGL10
egl
,
EGLDisplay
display
,
EGLConfig
eglConfig
)
{
String
driver_name
=
GodotLib
.
getGlobal
(
"rendering/quality/driver/driver_name"
);
// FIXME: Add support for Vulkan.
Log
.
w
(
TAG
,
"creating OpenGL ES 2.0 context :"
);
...
...
platform/android/java_godot_lib_jni.cpp
View file @
af424b1c
...
...
@@ -52,6 +52,8 @@
#include <unistd.h>
#include <android/native_window_jni.h>
static
JavaClassWrapper
*
java_class_wrapper
=
nullptr
;
static
OS_Android
*
os_android
=
nullptr
;
static
GodotJavaWrapper
*
godot_java
=
nullptr
;
...
...
@@ -168,14 +170,17 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
os_android
->
set_display_size
(
Size2
(
width
,
height
));
}
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_newcontext
(
JNIEnv
*
env
,
jclass
clazz
,
jboolean
p_32_bits
)
{
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_newcontext
(
JNIEnv
*
env
,
jclass
clazz
,
jobject
p_surface
,
jboolean
p_32_bits
)
{
if
(
os_android
)
{
if
(
step
==
0
)
{
// During startup
os_android
->
set_context_is_16_bits
(
!
p_32_bits
);
if
(
p_surface
)
{
ANativeWindow
*
native_window
=
ANativeWindow_fromSurface
(
env
,
p_surface
);
os_android
->
set_native_window
(
native_window
);
}
}
else
{
//
GL
context recreated because it was lost; restart app to let it reload everything
//
Rendering
context recreated because it was lost; restart app to let it reload everything
os_android
->
main_loop_end
();
godot_java
->
restart
(
env
);
step
=
-
1
;
// Ensure no further steps are attempted
...
...
platform/android/java_godot_lib_jni.h
View file @
af424b1c
...
...
@@ -41,7 +41,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_ondestroy
(
JNIEnv
*
env
,
jclass
clazz
,
jobject
activity
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_setup
(
JNIEnv
*
env
,
jclass
clazz
,
jobjectArray
p_cmdline
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_resize
(
JNIEnv
*
env
,
jclass
clazz
,
jint
width
,
jint
height
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_newcontext
(
JNIEnv
*
env
,
jclass
clazz
,
jboolean
p_32_bits
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_newcontext
(
JNIEnv
*
env
,
jclass
clazz
,
j
object
p_surface
,
j
boolean
p_32_bits
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_step
(
JNIEnv
*
env
,
jclass
clazz
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_back
(
JNIEnv
*
env
,
jclass
clazz
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_GodotLib_touch
(
JNIEnv
*
env
,
jclass
clazz
,
jint
ev
,
jint
pointer
,
jint
count
,
jintArray
positions
);
...
...
platform/android/os_android.cpp
View file @
af424b1c
...
...
@@ -35,6 +35,11 @@
#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
#endif
#if defined(VULKAN_ENABLED)
#include "drivers/vulkan/rendering_device_vulkan.h"
#include "platform/android/vulkan/vulkan_context_android.h"
#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
#endif
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "file_access_android.h"
...
...
@@ -60,19 +65,6 @@ public:
virtual
~
AndroidLogger
()
{}
};
int
OS_Android
::
get_video_driver_count
()
const
{
return
2
;
}
const
char
*
OS_Android
::
get_video_driver_name
(
int
p_driver
)
const
{
switch
(
p_driver
)
{
case
VIDEO_DRIVER_GLES2
:
return
"GLES2"
;
}
ERR_FAIL_V_MSG
(
nullptr
,
"Invalid video driver index: "
+
itos
(
p_driver
)
+
"."
);
}
int
OS_Android
::
get_audio_driver_count
()
const
{
return
1
;
...
...
@@ -121,8 +113,7 @@ int OS_Android::get_current_video_driver() const {
}
Error
OS_Android
::
initialize
(
const
VideoMode
&
p_desired
,
int
p_video_driver
,
int
p_audio_driver
)
{
// FIXME: Add Vulkan support. Readd fallback code from Vulkan to GLES2?
video_driver_index
=
p_video_driver
;
#if defined(OPENGL_ENABLED)
if
(
video_driver_index
==
VIDEO_DRIVER_GLES2
)
{
...
...
@@ -144,7 +135,31 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
}
#endif
video_driver_index
=
p_video_driver
;
#if defined(VULKAN_ENABLED)
if
(
video_driver_index
==
VIDEO_DRIVER_VULKAN
)
{
ERR_FAIL_COND_V
(
!
native_window
,
ERR_UNAVAILABLE
);
context_vulkan
=
memnew
(
VulkanContextAndroid
);
if
(
context_vulkan
->
initialize
()
!=
OK
)
{
memdelete
(
context_vulkan
);
context_vulkan
=
NULL
;
ERR_FAIL_V
(
ERR_UNAVAILABLE
);
}
Size2
window_size
=
get_window_size
();
if
(
context_vulkan
->
window_create
(
native_window
,
window_size
.
width
,
window_size
.
height
)
==
-
1
)
{
memdelete
(
context_vulkan
);
context_vulkan
=
NULL
;
ERR_FAIL_V_MSG
(
ERR_UNAVAILABLE
,
"Failed to create Vulkan window."
);
}
//temporary
rendering_device_vulkan
=
memnew
(
RenderingDeviceVulkan
);
rendering_device_vulkan
->
initialize
(
context_vulkan
);
RasterizerRD
::
make_current
();
}
#endif
rendering_server
=
memnew
(
RenderingServerRaster
);
if
(
get_render_thread_mode
()
!=
RENDER_THREAD_UNSAFE
)
{
...
...
@@ -175,6 +190,19 @@ void OS_Android::delete_main_loop() {
void
OS_Android
::
finalize
()
{
memdelete
(
input
);
#if defined(VULKAN_ENABLED)
if
(
video_driver_index
==
VIDEO_DRIVER_VULKAN
)
{
if
(
rendering_device_vulkan
)
{
rendering_device_vulkan
->
finalize
();
memdelete
(
rendering_device_vulkan
);
}
if
(
context_vulkan
)
{
memdelete
(
context_vulkan
);
}
}
#endif
}
GodotJavaWrapper
*
OS_Android
::
get_godot_java
()
{
...
...
@@ -572,9 +600,8 @@ void OS_Android::main_loop_request_go_back() {
}
void
OS_Android
::
set_display_size
(
Size2
p_size
)
{
default_videomode
.
width
=
p_size
.
x
;
default_videomode
.
height
=
p_size
.
y
;
default_videomode
.
width
=
p_size
.
width
;
default_videomode
.
height
=
p_size
.
height
;
}
Error
OS_Android
::
shell_open
(
String
p_uri
)
{
...
...
@@ -710,6 +737,12 @@ void OS_Android::set_context_is_16_bits(bool p_is_16) {
// rasterizer->set_force_16_bits_fbo(p_is_16);
}
void
OS_Android
::
set_native_window
(
ANativeWindow
*
p_native_window
)
{
#if defined(VULKAN_ENABLED)
native_window
=
p_native_window
;
#endif
}
void
OS_Android
::
joy_connection_changed
(
int
p_device
,
bool
p_connected
,
String
p_name
)
{
return
input
->
joy_connection_changed
(
p_device
,
p_connected
,
p_name
,
""
);
}
...
...
@@ -759,6 +792,12 @@ OS_Android::OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_god
//rasterizer = nullptr;
use_gl2
=
false
;
#if defined(VULKAN_ENABLED)
context_vulkan
=
NULL
;
rendering_device_vulkan
=
NULL
;
native_window
=
NULL
;
#endif
rendering_server
=
nullptr
;
godot_java
=
p_godot_java
;
...
...
platform/android/os_android.h
View file @
af424b1c
...
...
@@ -42,6 +42,13 @@
class
GodotJavaWrapper
;
class
GodotIOJavaWrapper
;
#if defined(VULKAN_ENABLED)
class
VulkanContextAndroid
;
class
RenderingDeviceVulkan
;
#endif
struct
ANativeWindow
;
class
OS_Android
:
public
OS_Unix
{
public
:
struct
TouchPos
{
...
...
@@ -75,6 +82,12 @@ private:
bool
use_16bits_fbo
;
#if defined(VULKAN_ENABLED)
VulkanContextAndroid
*
context_vulkan
;
RenderingDeviceVulkan
*
rendering_device_vulkan
;
ANativeWindow
*
native_window
;
#endif
RenderingServer
*
rendering_server
;
mutable
String
data_dir_cache
;
...
...
@@ -94,10 +107,6 @@ private:
int
video_driver_index
;
public
:
// functions used by main to initialize/deinitialize the OS
virtual
int
get_video_driver_count
()
const
;
virtual
const
char
*
get_video_driver_name
(
int
p_driver
)
const
;
virtual
int
get_audio_driver_count
()
const
;
virtual
const
char
*
get_audio_driver_name
(
int
p_driver
)
const
;
...
...
@@ -163,6 +172,8 @@ public:
void
set_context_is_16_bits
(
bool
p_is_16
);
void
set_native_window
(
ANativeWindow
*
p_native_window
);
virtual
void
set_screen_orientation
(
ScreenOrientation
p_orientation
);
virtual
Error
shell_open
(
String
p_uri
);
...
...
platform/android/vulkan/vulkan_context_android.cpp
0 → 100644
View file @
af424b1c
/*************************************************************************/
/* vulkan_context_android.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "vulkan_context_android.h"
#include <vulkan/vulkan_android.h>
#define VMA_IMPLEMENTATION
#ifdef DEBUG_ENABLED
#ifndef _MSC_VER
#define _DEBUG
#endif
#endif
#include <vk_mem_alloc.h>
const
char
*
VulkanContextAndroid
::
_get_platform_surface_extension
()
const
{
return
VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
;
}
int
VulkanContextAndroid
::
window_create
(
ANativeWindow
*
p_window
,
int
p_width
,
int
p_height
)
{
VkAndroidSurfaceCreateInfoKHR
createInfo
;
createInfo
.
sType
=
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR
;
createInfo
.
pNext
=
NULL
;
createInfo
.
flags
=
0
;
createInfo
.
window
=
p_window
;
VkSurfaceKHR
surface
;
VkResult
err
=
vkCreateAndroidSurfaceKHR
(
_get_instance
(),
&
createInfo
,
NULL
,
&
surface
);
if
(
err
!=
VK_SUCCESS
)
{
ERR_FAIL_V_MSG
(
-
1
,
"vkCreateAndroidSurfaceKHR failed with error "
+
itos
(
err
));
}
return
_window_create
(
surface
,
p_width
,
p_height
);
}
VulkanContextAndroid
::
VulkanContextAndroid
()
{
// TODO: fix validation layers
use_validation_layers
=
false
;
}
VulkanContextAndroid
::~
VulkanContextAndroid
()
{
}
platform/android/vulkan/v
k_renderer_jni.cpp
→
platform/android/vulkan/v
ulkan_context_android.h
View file @
af424b1c
/*************************************************************************/
/* v
k_renderer_jni.cpp
*/
/* v
ulkan_context_android.h
*/
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
...
...
@@ -28,31 +28,22 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "vk_renderer_jni.h"
#ifndef VULKAN_CONTEXT_ANDROID_H
#define VULKAN_CONTEXT_ANDROID_H
extern
"C"
{
#include "drivers/vulkan/vulkan_context.h"
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceCreated
(
JNIEnv
*
env
,
jobject
obj
,
jobject
j_surface
)
{
// TODO: complete
}
struct
ANativeWindow
;
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceChanged
(
JNIEnv
*
env
,
jobject
object
,
jobject
j_surface
,
jint
width
,
jint
height
)
{
// TODO: complete
}
class
VulkanContextAndroid
:
public
VulkanContext
{
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkResume
(
JNIEnv
*
env
,
jobject
obj
)
{
// TODO: complete
}
virtual
const
char
*
_get_platform_surface_extension
()
const
;
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDrawFrame
(
JNIEnv
*
env
,
jobject
obj
)
{
// TODO: complete
}
public
:
int
window_create
(
ANativeWindow
*
p_window
,
int
p_width
,
int
p_height
);
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkPause
(
JNIEnv
*
env
,
jobject
obj
)
{
// TODO: complete
}
VulkanContextAndroid
();
~
VulkanContextAndroid
();
}
;
JNIEXPORT
void
JNICALL
Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDestroy
(
JNIEnv
*
env
,
jobject
obj
)
{
// TODO: complete
}
}
#endif // VULKAN_CONTEXT_ANDROID_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment