Skip to content

Commit

Permalink
Merge pull request #79142 from BastiaanOlij/register_render_buffers
Browse files Browse the repository at this point in the history
Expose RenderSceneBuffers(RD) through ClassDB
  • Loading branch information
YuriSizov committed Jul 27, 2023
2 parents 37c3e2e + 4874b96 commit 1fe49e7
Show file tree
Hide file tree
Showing 17 changed files with 639 additions and 142 deletions.
21 changes: 21 additions & 0 deletions doc/classes/RenderSceneBuffers.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RenderSceneBuffers" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Abstract scene buffers object, created for each viewport for which 3D rendering is done.
</brief_description>
<description>
Abstract scene buffers object, created for each viewport for which 3D rendering is done. It manages any additional buffers used during rendering and will discard buffers when the viewport is resized.
[b]Note:[/b] this is an internal rendering server object only exposed for GDExtension plugins.
</description>
<tutorials>
</tutorials>
<methods>
<method name="configure">
<return type="void" />
<param index="0" name="config" type="RenderSceneBuffersConfiguration" />
<description>
This method is called by the rendering server when the associated viewports configuration is changed. It will discard the old buffers and recreate the internal buffers used.
</description>
</method>
</methods>
</class>
40 changes: 40 additions & 0 deletions doc/classes/RenderSceneBuffersConfiguration.xml
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RenderSceneBuffersConfiguration" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Configuration object used to setup a [RenderSceneBuffers] object.
</brief_description>
<description>
This configuration object is created and populated by the render engine on a viewport change and used to (re)configure a [RenderSceneBuffers] object.
</description>
<tutorials>
</tutorials>
<members>
<member name="fsr_sharpness" type="float" setter="set_fsr_sharpness" getter="get_fsr_sharpness" default="0.0">
FSR Sharpness applicable if FSR upscaling is used.
</member>
<member name="internal_size" type="Vector2i" setter="set_internal_size" getter="get_internal_size" default="Vector2i(0, 0)">
The size of the 3D render buffer used for rendering.
</member>
<member name="msaa_3d" type="int" setter="set_msaa_3d" getter="get_msaa_3d" enum="RenderingServer.ViewportMSAA" default="0">
The MSAA mode we're using for 3D rendering.
</member>
<member name="render_target" type="RID" setter="set_render_target" getter="get_render_target" default="RID()">
The render target associated with these buffer.
</member>
<member name="scaling_3d_mode" type="int" setter="set_scaling_3d_mode" getter="get_scaling_3d_mode" enum="RenderingServer.ViewportScaling3DMode" default="255">
The requested scaling mode with which we upscale/downscale if [member internal_size] and [member target_size] are not equal.
</member>
<member name="screen_space_aa" type="int" setter="set_screen_space_aa" getter="get_screen_space_aa" enum="RenderingServer.ViewportScreenSpaceAA" default="0">
The requested screen space AA applied in post processing.
</member>
<member name="target_size" type="Vector2i" setter="set_target_size" getter="get_target_size" default="Vector2i(0, 0)">
The target (upscale) size if scaling is used.
</member>
<member name="texture_mipmap_bias" type="float" setter="set_texture_mipmap_bias" getter="get_texture_mipmap_bias" default="0.0">
Bias applied to mipmaps.
</member>
<member name="view_count" type="int" setter="set_view_count" getter="get_view_count" default="1">
The number of views we're rendering.
</member>
</members>
</class>
41 changes: 41 additions & 0 deletions doc/classes/RenderSceneBuffersExtension.xml
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RenderSceneBuffersExtension" inherits="RenderSceneBuffers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
This class allows for a RenderSceneBuffer implementation to be made in GDExtension.
</brief_description>
<description>
This class allows for a RenderSceneBuffer implementation to be made in GDExtension.
</description>
<tutorials>
</tutorials>
<methods>
<method name="_configure" qualifiers="virtual">
<return type="void" />
<param index="0" name="config" type="RenderSceneBuffersConfiguration" />
<description>
Implement this in GDExtension to handle the (re)sizing of a viewport.
</description>
</method>
<method name="_set_fsr_sharpness" qualifiers="virtual">
<return type="void" />
<param index="0" name="fsr_sharpness" type="float" />
<description>
Implement this in GDExtension to record a new FSR sharpness value.
</description>
</method>
<method name="_set_texture_mipmap_bias" qualifiers="virtual">
<return type="void" />
<param index="0" name="texture_mipmap_bias" type="float" />
<description>
Implement this in GDExtension to change the texture mipmap bias.
</description>
</method>
<method name="_set_use_debanding" qualifiers="virtual">
<return type="void" />
<param index="0" name="use_debanding" type="bool" />
<description>
Implement this in GDExtension to react to the debanding flag changing.
</description>
</method>
</methods>
</class>
167 changes: 167 additions & 0 deletions doc/classes/RenderSceneBuffersRD.xml
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="RenderSceneBuffersRD" inherits="RenderSceneBuffers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Abstract render scene buffer implementation for the RenderingDevice based renderers.
</brief_description>
<description>
This object manages all 3D rendering buffers for the rendering device based renderers. An instance of this object is created for every viewport that has 3D rendering enabled.
All buffers are organised in [b]contexts[/b]. The default context is called [b]render_buffers[/b] and can contain amongst others the color buffer, depth buffer, velocity buffers, VRS density map and MSAA variants of these buffers.
Buffers are only guaranteed to exist during rendering of the viewport.
[b]Note:[/b] this is an internal rendering server object only exposed for GDExtension plugins.
</description>
<tutorials>
</tutorials>
<methods>
<method name="clear_context">
<return type="void" />
<param index="0" name="context" type="StringName" />
<description>
Frees all buffers related to this context.
</description>
</method>
<method name="create_texture">
<return type="RID" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<param index="2" name="data_format" type="int" enum="RenderingDevice.DataFormat" />
<param index="3" name="usage_bits" type="int" />
<param index="4" name="texture_samples" type="int" enum="RenderingDevice.TextureSamples" />
<param index="5" name="size" type="Vector2i" />
<param index="6" name="layers" type="int" />
<param index="7" name="mipmaps" type="int" />
<param index="8" name="unique" type="bool" />
<description>
Create a new texture with the given definition and cache this under the given name. Will return the existing texture if it already exists.
</description>
</method>
<method name="create_texture_from_format">
<return type="RID" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<param index="2" name="format" type="RDTextureFormat" />
<param index="3" name="view" type="RDTextureView" />
<param index="4" name="unique" type="bool" />
<description>
Create a new texture using the given format and view and cache this under the given name. Will return the existing texture if it already exists.
</description>
</method>
<method name="create_texture_view">
<return type="RID" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<param index="2" name="view_name" type="StringName" />
<param index="3" name="view" type="RDTextureView" />
<description>
Create a new texture view for an existing texture and cache this under the given view_name. Will return the existing teture view if it already exists. Will error if the source texture doesn't exist.
</description>
</method>
<method name="get_color_layer">
<return type="RID" />
<param index="0" name="layer" type="int" />
<description>
Returns the specified layer from the color texture we are rendering 3D content to.
</description>
</method>
<method name="get_color_texture">
<return type="RID" />
<description>
Returns the color texture we are rendering 3D content to. If multiview is used this will be a texture array with all views.
</description>
</method>
<method name="get_depth_layer">
<return type="RID" />
<param index="0" name="layer" type="int" />
<description>
Returns the specified layer from the depth texture we are rendering 3D content to.
</description>
</method>
<method name="get_depth_texture">
<return type="RID" />
<description>
Returns the depth texture we are rendering 3D content to. If multiview is used this will be a texture array with all views.
</description>
</method>
<method name="get_internal_size" qualifiers="const">
<return type="Vector2i" />
<description>
Returns the internal size of the render buffer (size before upscaling) with which textures are created by default.
</description>
</method>
<method name="get_render_target" qualifiers="const">
<return type="RID" />
<description>
Returns the render target associated with this buffers object.
</description>
</method>
<method name="get_texture" qualifiers="const">
<return type="RID" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<description>
Returns a cached texture with this name.
</description>
</method>
<method name="get_texture_format" qualifiers="const">
<return type="RDTextureFormat" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<description>
Returns the texture format information with which a cached texture was created.
</description>
</method>
<method name="get_texture_slice">
<return type="RID" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<param index="2" name="layer" type="int" />
<param index="3" name="mipmap" type="int" />
<param index="4" name="layers" type="int" />
<param index="5" name="mipmaps" type="int" />
<description>
Returns a specific slice (layer or mipmap) for a cached texture.
</description>
</method>
<method name="get_texture_slice_size">
<return type="Vector2i" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<param index="2" name="mipmap" type="int" />
<description>
Returns the texture size of a given slice of a cached texture.
</description>
</method>
<method name="get_use_taa" qualifiers="const">
<return type="bool" />
<description>
Returns [b]true[/b] if TAA is enabled.
</description>
</method>
<method name="get_velocity_layer">
<return type="RID" />
<param index="0" name="layer" type="int" />
<description>
Returns the specified layer from the velocity texture we are rendering 3D content to.
</description>
</method>
<method name="get_velocity_texture">
<return type="RID" />
<description>
Returns the velocity texture we are rendering 3D content to. If multiview is used this will be a texture array with all views.
</description>
</method>
<method name="get_view_count" qualifiers="const">
<return type="int" />
<description>
Returns the view count for the associated viewport.
</description>
</method>
<method name="has_texture" qualifiers="const">
<return type="bool" />
<param index="0" name="context" type="StringName" />
<param index="1" name="name" type="StringName" />
<description>
Returns [b]true[/b] if a cached texture exists for this name.
</description>
</method>
</methods>
</class>
28 changes: 14 additions & 14 deletions drivers/gles3/storage/render_scene_buffers_gles3.cpp
Expand Up @@ -37,25 +37,25 @@ RenderSceneBuffersGLES3::~RenderSceneBuffersGLES3() {
free_render_buffer_data();
}

void RenderSceneBuffersGLES3::configure(RID p_render_target, const Size2i p_internal_size, const Size2i p_target_size, RS::ViewportScaling3DMode p_scaling_3d_mode, float p_fsr_sharpness, float p_texture_mipmap_bias, RS::ViewportMSAA p_msaa, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_taa, bool p_use_debanding, uint32_t p_view_count) {
void RenderSceneBuffersGLES3::configure(const RenderSceneBuffersConfiguration *p_config) {
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();

//internal_size.x = p_internal_size.x; // ignore for now
//internal_size.y = p_internal_size.y;
width = p_target_size.x;
height = p_target_size.y;
//scaling_3d_mode = p_scaling_3d_mode
//fsr_sharpness = p_fsr_sharpness;
//texture_mipmap_bias = p_texture_mipmap_bias;
render_target = p_render_target;
//msaa = p_msaa;
//screen_space_aa = p_screen_space_aa;
//use_debanding = p_use_debanding;
view_count = p_view_count;
//internal_size.x = p_config->get_internal_size().x; // ignore for now
//internal_size.y = p_config->get_internal_size().y;
width = p_config->get_target_size().x;
height = p_config->get_target_size().y;
//scaling_3d_mode = p_config->get_scaling_3d_mode()
//fsr_sharpness = p_config->get_fsr_sharpness();
//texture_mipmap_bias = p_config->get_texture_mipmap_bias();
render_target = p_config->get_render_target();
//msaa = p_config->get_msaa_3d();
//screen_space_aa = p_config->get_screen_space_aa();
//use_debanding = p_config->get_use_debanding();
view_count = p_config->get_view_count();

free_render_buffer_data();

GLES3::RenderTarget *rt = texture_storage->get_render_target(p_render_target);
GLES3::RenderTarget *rt = texture_storage->get_render_target(render_target);

is_transparent = rt->is_transparent;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/storage/render_scene_buffers_gles3.h
Expand Up @@ -81,7 +81,7 @@ class RenderSceneBuffersGLES3 : public RenderSceneBuffers {
private:
public:
virtual ~RenderSceneBuffersGLES3();
virtual void configure(RID p_render_target, const Size2i p_internal_size, const Size2i p_target_size, RS::ViewportScaling3DMode p_scaling_3d_mode, float p_fsr_sharpness, float p_texture_mipmap_bias, RS::ViewportMSAA p_msaa, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_taa, bool p_use_debanding, uint32_t p_view_count) override;
virtual void configure(const RenderSceneBuffersConfiguration *p_config) override;

virtual void set_fsr_sharpness(float p_fsr_sharpness) override{};
virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override{};
Expand Down
7 changes: 7 additions & 0 deletions servers/register_server_types.cpp
Expand Up @@ -69,8 +69,10 @@
#include "physics_server_3d.h"
#include "physics_server_3d_wrap_mt.h"
#include "rendering/renderer_compositor.h"
#include "rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
#include "rendering/rendering_device.h"
#include "rendering/rendering_device_binds.h"
#include "rendering/storage/render_scene_buffers.h"
#include "rendering_server.h"
#include "servers/extensions/physics_server_2d_extension.h"
#include "servers/extensions/physics_server_3d_extension.h"
Expand Down Expand Up @@ -247,6 +249,11 @@ void register_server_types() {
GDREGISTER_CLASS(RDShaderFile);
GDREGISTER_CLASS(RDPipelineSpecializationConstant);

GDREGISTER_CLASS(RenderSceneBuffersConfiguration);
GDREGISTER_ABSTRACT_CLASS(RenderSceneBuffers);
GDREGISTER_CLASS(RenderSceneBuffersExtension);
GDREGISTER_ABSTRACT_CLASS(RenderSceneBuffersRD);

GDREGISTER_CLASS(CameraFeed);

GDREGISTER_ABSTRACT_CLASS(PhysicsDirectBodyState2D);
Expand Down

0 comments on commit 1fe49e7

Please sign in to comment.