-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external texture support (GLES3)
Co-authored-by: Fredia Huya-Kouadio <[email protected]> Co-authored-by: Mauricio Narvaez <[email protected]>
- Loading branch information
1 parent
20c6a48
commit 6ed9781
Showing
24 changed files
with
354 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="ExternalTexture" inherits="Texture2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> | ||
<brief_description> | ||
Texture which displays the content of an external buffer. | ||
</brief_description> | ||
<description> | ||
Displays the content of an external buffer provided by the platform. | ||
Requires the [url=https://registry.khronos.org/OpenGL/extensions/OES/OES_EGL_image_external.txt]OES_EGL_image_external[/url] extension (OpenGL) or [url=https://registry.khronos.org/vulkan/specs/1.1-extensions/html/vkspec.html#VK_ANDROID_external_memory_android_hardware_buffer]VK_ANDROID_external_memory_android_hardware_buffer[/url] extension (Vulkan). | ||
[b]Note:[/b] This is currently only supported in Android builds. | ||
</description> | ||
<tutorials> | ||
</tutorials> | ||
<methods> | ||
<method name="get_external_texture_id" qualifiers="const"> | ||
<return type="int" /> | ||
<description> | ||
Returns the external texture ID. | ||
Depending on your use case, you may need to pass this to platform APIs, for example, when creating an [code]android.graphics.SurfaceTexture[/code] on Android. | ||
</description> | ||
</method> | ||
<method name="set_external_buffer_id"> | ||
<return type="void" /> | ||
<param index="0" name="external_buffer_id" type="int" /> | ||
<description> | ||
Sets the external buffer ID. | ||
Depending on your use case, you may need to call this with data received from a platform API, for example, [code]SurfaceTexture.getHardwareBuffer()[/code] on Android. | ||
</description> | ||
</method> | ||
</methods> | ||
<members> | ||
<member name="resource_local_to_scene" type="bool" setter="set_local_to_scene" getter="is_local_to_scene" overrides="Resource" default="false" /> | ||
<member name="size" type="Vector2" setter="set_size" getter="get_size" default="Vector2(256, 256)"> | ||
External texture size. | ||
</member> | ||
</members> | ||
</class> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/**************************************************************************/ | ||
/* external_texture.cpp */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* 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 "external_texture.h" | ||
#include "drivers/gles3/storage/texture_storage.h" | ||
#include "servers/rendering/rendering_server_globals.h" | ||
|
||
void ExternalTexture::_bind_methods() { | ||
ClassDB::bind_method(D_METHOD("set_size", "size"), &ExternalTexture::set_size); | ||
ClassDB::bind_method(D_METHOD("get_external_texture_id"), &ExternalTexture::get_external_texture_id); | ||
ClassDB::bind_method(D_METHOD("set_external_buffer_id", "external_buffer_id"), &ExternalTexture::set_external_buffer_id); | ||
|
||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); | ||
} | ||
|
||
uint64_t ExternalTexture::get_external_texture_id() const { | ||
return RenderingServer::get_singleton()->texture_get_native_handle(texture); | ||
} | ||
|
||
void ExternalTexture::set_size(const Size2 &p_size) { | ||
if (p_size.width > 0 && p_size.height > 0 && p_size != size) { | ||
size = p_size; | ||
RenderingServer::get_singleton()->texture_external_update(texture, size.width, size.height, external_buffer); | ||
emit_changed(); | ||
} | ||
} | ||
|
||
Size2 ExternalTexture::get_size() const { | ||
return size; | ||
} | ||
|
||
void ExternalTexture::set_external_buffer_id(uint64_t p_external_buffer) { | ||
if (p_external_buffer != external_buffer) { | ||
external_buffer = p_external_buffer; | ||
RenderingServer::get_singleton()->texture_external_update(texture, size.width, size.height, external_buffer); | ||
} | ||
} | ||
|
||
int ExternalTexture::get_width() const { | ||
return size.width; | ||
} | ||
|
||
int ExternalTexture::get_height() const { | ||
return size.height; | ||
} | ||
|
||
bool ExternalTexture::has_alpha() const { | ||
return false; | ||
} | ||
|
||
RID ExternalTexture::get_rid() const { | ||
return texture; | ||
} | ||
|
||
ExternalTexture::ExternalTexture() { | ||
texture = RenderingServer::get_singleton()->texture_external_create(size.width, size.height); | ||
} | ||
|
||
ExternalTexture::~ExternalTexture() { | ||
if (texture.is_valid()) { | ||
ERR_FAIL_NULL(RenderingServer::get_singleton()); | ||
RenderingServer::get_singleton()->free(texture); | ||
} | ||
} |
Oops, something went wrong.