Merge pull request #105701 from ColinSORourke/DrawableTexture

Implement DrawableTextures
This commit is contained in:
Thaddeus Crews 2026-01-30 09:32:05 -06:00
commit fd6e80d4e9
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
46 changed files with 2417 additions and 10 deletions

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="BlitMaterial" inherits="Material" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A material that processes blit calls to a DrawableTexture.
</brief_description>
<description>
A material resource that can be used by DrawableTextures when processing blit calls to draw.
</description>
<tutorials>
</tutorials>
<members>
<member name="blend_mode" type="int" setter="set_blend_mode" getter="get_blend_mode" enum="BlitMaterial.BlendMode" default="0">
The manner in which the newly blitted texture is blended with the original DrawableTexture.
</member>
</members>
<constants>
<constant name="BLEND_MODE_MIX" value="0" enum="BlendMode">
Mix blending mode. Colors are assumed to be independent of the alpha (opacity) value.
</constant>
<constant name="BLEND_MODE_ADD" value="1" enum="BlendMode">
Additive blending mode.
</constant>
<constant name="BLEND_MODE_SUB" value="2" enum="BlendMode">
Subtractive blending mode.
</constant>
<constant name="BLEND_MODE_MUL" value="3" enum="BlendMode">
Multiplicative blending mode.
</constant>
<constant name="BLEND_MODE_DISABLED" value="4" enum="BlendMode">
No blending mode, direct color copy.
</constant>
</constants>
</class>

View file

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="DrawableTexture2D" inherits="Texture2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A 2D texture that supports drawing to itself via Blit calls.
</brief_description>
<description>
A 2D texture that can be modified via blit calls, copying from a target texture to itself. Primarily intended to be managed in code, a user must call [method setup] to initialize the state before drawing. Each [method blit_rect] call takes at least a rectangle, the area to draw to, and another texture, what to be drawn. The draw calls use a Texture_Blit Shader to process and calculate the result, pixel by pixel. Users can supply their own ShaderMaterial with custom Texture_Blit shaders for more complex behaviors.
</description>
<tutorials>
</tutorials>
<methods>
<method name="blit_rect" experimental="This function and its parameters are likely to change in the 4.7 Dev Cycle">
<return type="void" />
<param index="0" name="rect" type="Rect2i" />
<param index="1" name="source" type="Texture2D" />
<param index="2" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<param index="3" name="mipmap" type="int" default="0" />
<param index="4" name="material" type="Material" default="null" />
<description>
Draws to given [param rect] on this texture by copying from the given [param source]. A [param modulate] color can be passed in for the shader to use, but defaults to White. The [param mipmap] value can specify a draw to a lower mipmap level. The [param material] parameter can take a ShaderMaterial with a TextureBlit Shader for custom drawing behavior.
</description>
</method>
<method name="blit_rect_multi" experimental="This function and its parameters are likely to change in the 4.7 Dev Cycle">
<return type="void" />
<param index="0" name="rect" type="Rect2i" />
<param index="1" name="sources" type="Texture2D[]" />
<param index="2" name="extra_targets" type="DrawableTexture2D[]" />
<param index="3" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<param index="4" name="mipmap" type="int" default="0" />
<param index="5" name="material" type="Material" default="null" />
<description>
Draws to the given [param rect] on this texture, as well as on up to 3 DrawableTexture [param extra_targets]. All [param extra_targets] must be the same size and DrawableFormat as the original target, otherwise the Shader may fail. Expects up to 4 Texture [param sources], but will replace missing [param sources] with default Black Textures.
</description>
</method>
<method name="generate_mipmaps">
<return type="void" />
<description>
Re-calculates the mipmaps for this texture on demand.
</description>
</method>
<method name="setup" experimental="This function and its parameters are likely to change in the 4.7 Dev Cycle">
<return type="void" />
<param index="0" name="width" type="int" />
<param index="1" name="height" type="int" />
<param index="2" name="format" type="int" enum="DrawableTexture2D.DrawableFormat" />
<param index="3" name="color" type="Color" default="Color(1, 1, 1, 1)" />
<param index="4" name="use_mipmaps" type="bool" default="false" />
<description>
Initializes the DrawableTexture to a White texture of the given [param width], [param height], and [param format].
</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" />
</members>
<constants>
<constant name="DRAWABLE_FORMAT_RGBA8" value="0" enum="DrawableFormat">
OpenGL texture format RGBA with four components, each with a bitdepth of 8.
</constant>
<constant name="DRAWABLE_FORMAT_RGBA8_SRGB" value="1" enum="DrawableFormat">
OpenGL texture format RGBA with four components, each with a bitdepth of 8.
When drawn to, an sRGB to linear color space conversion is performed.
</constant>
<constant name="DRAWABLE_FORMAT_RGBAH" value="2" enum="DrawableFormat">
OpenGL texture format GL_RGBA16F where there are four components, each a 16-bit "half-precision" floating-point value.
</constant>
<constant name="DRAWABLE_FORMAT_RGBAF" value="3" enum="DrawableFormat">
OpenGL texture format GL_RGBA32F where there are four components, each a 32-bit floating-point value.
</constant>
</constants>
</class>

View file

@ -3878,6 +3878,45 @@
[b]Note:[/b] If using only the rendering device renderer, it's recommend to use [method RenderingDevice.texture_create_from_extension] together with [method RenderingServer.texture_rd_create], rather than this method. This way, the texture's format and usage can be controlled more effectively.
</description>
</method>
<method name="texture_drawable_blit_rect">
<return type="void" />
<param index="0" name="textures" type="RID[]" />
<param index="1" name="rect" type="Rect2i" />
<param index="2" name="material" type="RID" />
<param index="3" name="modulate" type="Color" />
<param index="4" name="source_textures" type="RID[]" />
<param index="5" name="to_mipmap" type="int" default="0" />
<description>
Draws to [param rect] on up to 4 given Drawable [param textures], using a TextureBlit Shader from [param material]. [param modulate] and up to 4 [param source_textures] are uniforms for the Shader to process with. [param to_mipmap] can specify to perform this draw to a lower mipmap level.
[b]Note:[/b] All [param textures] must be the same size and format.
</description>
</method>
<method name="texture_drawable_create">
<return type="RID" />
<param index="0" name="width" type="int" />
<param index="1" name="height" type="int" />
<param index="2" name="format" type="int" enum="RenderingServer.TextureDrawableFormat" />
<param index="3" name="color" type="Color" default="Color(1, 1, 1, 1)" />
<param index="4" name="with_mipmaps" type="bool" default="false" />
<description>
Creates a 2-dimensional texture and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID will be used in all [code]texture_drawable*[/code] RenderingServer functions.
Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] method.
[b]Note:[/b] The equivalent resource is [DrawableTexture2D].
</description>
</method>
<method name="texture_drawable_generate_mipmaps">
<return type="void" />
<param index="0" name="texture" type="RID" />
<description>
Calculates new MipMaps for the given Drawable [param texture].
</description>
</method>
<method name="texture_drawable_get_default_material" qualifiers="const">
<return type="RID" />
<description>
Returns a ShaderMaterial with the default texture_blit Shader.
</description>
</method>
<method name="texture_get_format" qualifiers="const">
<return type="int" enum="Image.Format" />
<param index="0" name="texture" type="RID" />
@ -4677,6 +4716,19 @@
<constant name="CUBEMAP_LAYER_BACK" value="5" enum="CubeMapLayer">
Back face of a [Cubemap].
</constant>
<constant name="TEXTURE_DRAWABLE_FORMAT_RGBA8" value="0" enum="TextureDrawableFormat">
OpenGL texture format RGBA with four components, each with a bitdepth of 8.
</constant>
<constant name="TEXTURE_DRAWABLE_FORMAT_RGBA8_SRGB" value="1" enum="TextureDrawableFormat">
OpenGL texture format RGBA with four components, each with a bitdepth of 8.
When drawn to, an sRGB to linear color space conversion is performed.
</constant>
<constant name="TEXTURE_DRAWABLE_FORMAT_RGBAH" value="2" enum="TextureDrawableFormat">
OpenGL texture format GL_RGBA16F where there are four components, each a 16-bit "half-precision" floating-point value.
</constant>
<constant name="TEXTURE_DRAWABLE_FORMAT_RGBAF" value="3" enum="TextureDrawableFormat">
OpenGL texture format GL_RGBA32F where there are four components, each a 32-bit floating-point value.
</constant>
<constant name="SHADER_SPATIAL" value="0" enum="ShaderMode">
Shader is a 3D shader.
</constant>
@ -4692,7 +4744,10 @@
<constant name="SHADER_FOG" value="4" enum="ShaderMode">
Shader is a 3D fog shader.
</constant>
<constant name="SHADER_MAX" value="5" enum="ShaderMode">
<constant name="SHADER_TEXTURE_BLIT" value="5" enum="ShaderMode">
Shader is a texture_blit shader.
</constant>
<constant name="SHADER_MAX" value="6" enum="ShaderMode">
Represents the size of the [enum ShaderMode] enum.
</constant>
<constant name="MATERIAL_RENDER_PRIORITY_MIN" value="-128">

View file

@ -74,5 +74,8 @@
<constant name="MODE_FOG" value="4" enum="Mode">
Mode used for setting the color and density of volumetric fog effect.
</constant>
<constant name="MODE_TEXTURE_BLIT" value="5" enum="Mode">
Mode used for drawing to DrawableTexture resources via blit calls.
</constant>
</constants>
</class>

View file

@ -222,7 +222,10 @@
<constant name="TYPE_FOG" value="9" enum="Type">
A compute shader that runs for each froxel of the volumetric fog map.
</constant>
<constant name="TYPE_MAX" value="10" enum="Type">
<constant name="TYPE_TEXTURE_BLIT" value="10" enum="Type">
A shader used to process blit calls to a DrawableTexture.
</constant>
<constant name="TYPE_MAX" value="11" enum="Type">
Represents the size of the [enum Type] enum.
</constant>
<constant name="VARYING_MODE_VERTEX_TO_FRAG_LIGHT" value="0" enum="VaryingMode">