mirror of
https://github.com/godotengine/godot
synced 2024-09-05 13:38:29 +00:00
Move storage for Mesh, MeshInstance, MultiMesh and Skeleton into MeshStorage
This commit is contained in:
parent
7bb963efe9
commit
b8be7903f3
|
@ -41,6 +41,7 @@
|
|||
#include "storage/config.h"
|
||||
#include "storage/decal_atlas_storage.h"
|
||||
#include "storage/material_storage.h"
|
||||
#include "storage/mesh_storage.h"
|
||||
#include "storage/render_target_storage.h"
|
||||
#include "storage/texture_storage.h"
|
||||
|
||||
|
@ -57,6 +58,7 @@ protected:
|
|||
GLES3::TextureStorage texture_storage;
|
||||
GLES3::DecalAtlasStorage decal_atlas_storage;
|
||||
GLES3::MaterialStorage material_storage;
|
||||
GLES3::MeshStorage mesh_storage;
|
||||
RasterizerStorageGLES3 storage;
|
||||
RasterizerCanvasGLES3 canvas;
|
||||
RasterizerSceneGLES3 scene;
|
||||
|
@ -66,6 +68,7 @@ protected:
|
|||
public:
|
||||
RendererCanvasTextureStorage *get_canvas_texture_storage() { return &canvas_texture_storage; }
|
||||
RendererMaterialStorage *get_material_storage() { return &material_storage; }
|
||||
RendererMeshStorage *get_mesh_storage() { return &mesh_storage; }
|
||||
RendererTextureStorage *get_texture_storage() { return &texture_storage; }
|
||||
RendererDecalAtlasStorage *get_decal_atlas_storage() { return &decal_atlas_storage; }
|
||||
RendererStorage *get_storage() { return &storage; }
|
||||
|
|
|
@ -58,202 +58,6 @@ RID RasterizerStorageGLES3::sky_create() {
|
|||
void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size) {
|
||||
}
|
||||
|
||||
/* MESH API */
|
||||
|
||||
RID RasterizerStorageGLES3::mesh_allocate() {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_initialize(RID p_rid) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) {
|
||||
}
|
||||
|
||||
bool RasterizerStorageGLES3::mesh_needs_instance(RID p_mesh, bool p_has_skeleton) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RID RasterizerStorageGLES3::mesh_instance_create(RID p_base) {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_instance_check_for_update(RID p_mesh_instance) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::update_mesh_instances() {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) {
|
||||
}
|
||||
|
||||
float RasterizerStorageGLES3::reflection_probe_get_mesh_lod_threshold(RID p_probe) const {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) {
|
||||
}
|
||||
|
||||
int RasterizerStorageGLES3::mesh_get_blend_shape_count(RID p_mesh) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) {
|
||||
}
|
||||
|
||||
RS::BlendShapeMode RasterizerStorageGLES3::mesh_get_blend_shape_mode(RID p_mesh) const {
|
||||
return RS::BLEND_SHAPE_MODE_NORMALIZED;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {
|
||||
}
|
||||
|
||||
RID RasterizerStorageGLES3::mesh_surface_get_material(RID p_mesh, int p_surface) const {
|
||||
return RID();
|
||||
}
|
||||
|
||||
RS::SurfaceData RasterizerStorageGLES3::mesh_get_surface(RID p_mesh, int p_surface) const {
|
||||
return RS::SurfaceData();
|
||||
}
|
||||
|
||||
int RasterizerStorageGLES3::mesh_get_surface_count(RID p_mesh) const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {
|
||||
}
|
||||
|
||||
AABB RasterizerStorageGLES3::mesh_get_custom_aabb(RID p_mesh) const {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::mesh_clear(RID p_mesh) {
|
||||
}
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
RID RasterizerStorageGLES3::multimesh_allocate() {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_initialize(RID p_rid) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors, bool p_use_custom_data) {
|
||||
}
|
||||
|
||||
int RasterizerStorageGLES3::multimesh_get_instance_count(RID p_multimesh) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
}
|
||||
|
||||
RID RasterizerStorageGLES3::multimesh_get_mesh(RID p_multimesh) const {
|
||||
return RID();
|
||||
}
|
||||
|
||||
AABB RasterizerStorageGLES3::multimesh_get_aabb(RID p_multimesh) const {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
Transform3D RasterizerStorageGLES3::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
|
||||
return Transform3D();
|
||||
}
|
||||
|
||||
Transform2D RasterizerStorageGLES3::multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const {
|
||||
return Transform2D();
|
||||
}
|
||||
|
||||
Color RasterizerStorageGLES3::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
|
||||
return Color();
|
||||
}
|
||||
|
||||
Color RasterizerStorageGLES3::multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const {
|
||||
return Color();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {
|
||||
}
|
||||
|
||||
Vector<float> RasterizerStorageGLES3::multimesh_get_buffer(RID p_multimesh) const {
|
||||
return Vector<float>();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
|
||||
}
|
||||
|
||||
int RasterizerStorageGLES3::multimesh_get_visible_instances(RID p_multimesh) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
RID RasterizerStorageGLES3::skeleton_allocate() {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::skeleton_initialize(RID p_rid) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) {
|
||||
}
|
||||
|
||||
int RasterizerStorageGLES3::skeleton_get_bone_count(RID p_skeleton) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) {
|
||||
}
|
||||
|
||||
Transform3D RasterizerStorageGLES3::skeleton_bone_get_transform(RID p_skeleton, int p_bone) const {
|
||||
return Transform3D();
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) {
|
||||
}
|
||||
|
||||
Transform2D RasterizerStorageGLES3::skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const {
|
||||
return Transform2D();
|
||||
}
|
||||
|
||||
/* Light API */
|
||||
|
||||
RID RasterizerStorageGLES3::directional_light_allocate() {
|
||||
|
@ -450,7 +254,11 @@ bool RasterizerStorageGLES3::reflection_probe_renders_shadows(RID p_probe) const
|
|||
void RasterizerStorageGLES3::base_update_dependency(RID p_base, DependencyTracker *p_instance) {
|
||||
}
|
||||
|
||||
void RasterizerStorageGLES3::skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) {
|
||||
void RasterizerStorageGLES3::reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) {
|
||||
}
|
||||
|
||||
float RasterizerStorageGLES3::reflection_probe_get_mesh_lod_threshold(RID p_probe) const {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
|
|
@ -132,143 +132,6 @@ public:
|
|||
RID sky_create();
|
||||
void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size);
|
||||
|
||||
/* MESH API */
|
||||
|
||||
RID mesh_allocate() override;
|
||||
void mesh_initialize(RID p_rid) override;
|
||||
void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override;
|
||||
bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
|
||||
RID mesh_instance_create(RID p_base) override;
|
||||
void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override;
|
||||
void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override;
|
||||
void mesh_instance_check_for_update(RID p_mesh_instance) override;
|
||||
void update_mesh_instances() override;
|
||||
void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) override;
|
||||
float reflection_probe_get_mesh_lod_threshold(RID p_probe) const override;
|
||||
|
||||
void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override;
|
||||
|
||||
int mesh_get_blend_shape_count(RID p_mesh) const override;
|
||||
|
||||
void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override;
|
||||
RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override;
|
||||
|
||||
void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
|
||||
void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override;
|
||||
RID mesh_surface_get_material(RID p_mesh, int p_surface) const override;
|
||||
|
||||
RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override;
|
||||
int mesh_get_surface_count(RID p_mesh) const override;
|
||||
|
||||
void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override;
|
||||
AABB mesh_get_custom_aabb(RID p_mesh) const override;
|
||||
|
||||
AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;
|
||||
void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;
|
||||
void mesh_clear(RID p_mesh) override;
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
struct MultiMesh {
|
||||
RID mesh;
|
||||
int instances = 0;
|
||||
RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
|
||||
bool uses_colors = false;
|
||||
bool uses_custom_data = false;
|
||||
int visible_instances = -1;
|
||||
AABB aabb;
|
||||
bool aabb_dirty = false;
|
||||
bool buffer_set = false;
|
||||
uint32_t stride_cache = 0;
|
||||
uint32_t color_offset_cache = 0;
|
||||
uint32_t custom_data_offset_cache = 0;
|
||||
|
||||
Vector<float> data_cache; //used if individual setting is used
|
||||
bool *data_cache_dirty_regions = nullptr;
|
||||
uint32_t data_cache_used_dirty_regions = 0;
|
||||
|
||||
RID buffer; //storage buffer
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_2d;
|
||||
|
||||
bool dirty = false;
|
||||
MultiMesh *dirty_list = nullptr;
|
||||
|
||||
Dependency dependency;
|
||||
};
|
||||
|
||||
mutable RID_Owner<MultiMesh, true> multimesh_owner;
|
||||
|
||||
MultiMesh *multimesh_dirty_list = nullptr;
|
||||
|
||||
_FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
|
||||
_FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
|
||||
void _update_dirty_multimeshes();
|
||||
|
||||
RID multimesh_allocate() override;
|
||||
void multimesh_initialize(RID p_rid) override;
|
||||
void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override;
|
||||
int multimesh_get_instance_count(RID p_multimesh) const override;
|
||||
|
||||
void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
|
||||
void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
|
||||
void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
|
||||
void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
|
||||
RID multimesh_get_mesh(RID p_multimesh) const override;
|
||||
AABB multimesh_get_aabb(RID p_multimesh) const override;
|
||||
|
||||
Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
|
||||
Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
|
||||
Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
|
||||
Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
|
||||
void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
|
||||
Vector<float> multimesh_get_buffer(RID p_multimesh) const override;
|
||||
|
||||
void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
|
||||
int multimesh_get_visible_instances(RID p_multimesh) const override;
|
||||
|
||||
_FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->xform_format;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_colors;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_custom_data;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (multimesh->visible_instances >= 0) {
|
||||
return multimesh->visible_instances;
|
||||
}
|
||||
return multimesh->instances;
|
||||
}
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
RID skeleton_allocate() override;
|
||||
void skeleton_initialize(RID p_rid) override;
|
||||
void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override;
|
||||
void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override;
|
||||
int skeleton_get_bone_count(RID p_skeleton) const override;
|
||||
void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override;
|
||||
Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override;
|
||||
void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override;
|
||||
Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override;
|
||||
|
||||
/* Light API */
|
||||
|
||||
RID directional_light_allocate() override;
|
||||
|
@ -328,6 +191,8 @@ public:
|
|||
void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override;
|
||||
void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override;
|
||||
void reflection_probe_set_resolution(RID p_probe, int p_resolution) override;
|
||||
void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) override;
|
||||
float reflection_probe_get_mesh_lod_threshold(RID p_probe) const override;
|
||||
|
||||
AABB reflection_probe_get_aabb(RID p_probe) const override;
|
||||
RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override;
|
||||
|
@ -338,7 +203,6 @@ public:
|
|||
bool reflection_probe_renders_shadows(RID p_probe) const override;
|
||||
|
||||
void base_update_dependency(RID p_base, DependencyTracker *p_instance) override;
|
||||
void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override;
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
||||
|
|
257
drivers/gles3/storage/mesh_storage.cpp
Normal file
257
drivers/gles3/storage/mesh_storage.cpp
Normal file
|
@ -0,0 +1,257 @@
|
|||
/*************************************************************************/
|
||||
/* mesh_storage.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "mesh_storage.h"
|
||||
|
||||
using namespace GLES3;
|
||||
|
||||
MeshStorage *MeshStorage::singleton = nullptr;
|
||||
|
||||
MeshStorage *MeshStorage::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
MeshStorage::MeshStorage() {
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
MeshStorage::~MeshStorage() {
|
||||
singleton = nullptr;
|
||||
}
|
||||
|
||||
/* MESH API */
|
||||
|
||||
RID MeshStorage::mesh_allocate() {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_initialize(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_free(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) {
|
||||
}
|
||||
|
||||
bool MeshStorage::mesh_needs_instance(RID p_mesh, bool p_has_skeleton) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) {
|
||||
}
|
||||
|
||||
int MeshStorage::mesh_get_blend_shape_count(RID p_mesh) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) {
|
||||
}
|
||||
|
||||
RS::BlendShapeMode MeshStorage::mesh_get_blend_shape_mode(RID p_mesh) const {
|
||||
return RS::BLEND_SHAPE_MODE_NORMALIZED;
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {
|
||||
}
|
||||
|
||||
RID MeshStorage::mesh_surface_get_material(RID p_mesh, int p_surface) const {
|
||||
return RID();
|
||||
}
|
||||
|
||||
RS::SurfaceData MeshStorage::mesh_get_surface(RID p_mesh, int p_surface) const {
|
||||
return RS::SurfaceData();
|
||||
}
|
||||
|
||||
int MeshStorage::mesh_get_surface_count(RID p_mesh) const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {
|
||||
}
|
||||
|
||||
AABB MeshStorage::mesh_get_custom_aabb(RID p_mesh) const {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
AABB MeshStorage::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_clear(RID p_mesh) {
|
||||
}
|
||||
|
||||
/* MESH INSTANCE API */
|
||||
|
||||
RID MeshStorage::mesh_instance_create(RID p_base) {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_instance_free(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) {
|
||||
}
|
||||
|
||||
void MeshStorage::mesh_instance_check_for_update(RID p_mesh_instance) {
|
||||
}
|
||||
|
||||
void MeshStorage::update_mesh_instances() {
|
||||
}
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
RID MeshStorage::multimesh_allocate() {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_initialize(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_free(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors, bool p_use_custom_data) {
|
||||
}
|
||||
|
||||
int MeshStorage::multimesh_get_instance_count(RID p_multimesh) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) {
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) {
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {
|
||||
}
|
||||
|
||||
RID MeshStorage::multimesh_get_mesh(RID p_multimesh) const {
|
||||
return RID();
|
||||
}
|
||||
|
||||
AABB MeshStorage::multimesh_get_aabb(RID p_multimesh) const {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
Transform3D MeshStorage::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
|
||||
return Transform3D();
|
||||
}
|
||||
|
||||
Transform2D MeshStorage::multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const {
|
||||
return Transform2D();
|
||||
}
|
||||
|
||||
Color MeshStorage::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
|
||||
return Color();
|
||||
}
|
||||
|
||||
Color MeshStorage::multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const {
|
||||
return Color();
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {
|
||||
}
|
||||
|
||||
Vector<float> MeshStorage::multimesh_get_buffer(RID p_multimesh) const {
|
||||
return Vector<float>();
|
||||
}
|
||||
|
||||
void MeshStorage::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
|
||||
}
|
||||
|
||||
int MeshStorage::multimesh_get_visible_instances(RID p_multimesh) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
RID MeshStorage::skeleton_allocate() {
|
||||
return RID();
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_initialize(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_free(RID p_rid) {
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton) {
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) {
|
||||
}
|
||||
|
||||
int MeshStorage::skeleton_get_bone_count(RID p_skeleton) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) {
|
||||
}
|
||||
|
||||
Transform3D MeshStorage::skeleton_bone_get_transform(RID p_skeleton, int p_bone) const {
|
||||
return Transform3D();
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) {
|
||||
}
|
||||
|
||||
Transform2D MeshStorage::skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const {
|
||||
return Transform2D();
|
||||
}
|
||||
|
||||
void MeshStorage::skeleton_update_dependency(RID p_base, RendererStorage::DependencyTracker *p_instance) {
|
||||
}
|
||||
|
||||
#endif // GLES3_ENABLED
|
204
drivers/gles3/storage/mesh_storage.h
Normal file
204
drivers/gles3/storage/mesh_storage.h
Normal file
|
@ -0,0 +1,204 @@
|
|||
/*************************************************************************/
|
||||
/* mesh_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef MESH_STORAGE_GLES3_H
|
||||
#define MESH_STORAGE_GLES3_H
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "core/templates/self_list.h"
|
||||
#include "servers/rendering/storage/mesh_storage.h"
|
||||
|
||||
namespace GLES3 {
|
||||
|
||||
class MeshStorage : public RendererMeshStorage {
|
||||
private:
|
||||
static MeshStorage *singleton;
|
||||
|
||||
public:
|
||||
static MeshStorage *get_singleton();
|
||||
|
||||
MeshStorage();
|
||||
virtual ~MeshStorage();
|
||||
|
||||
/* MESH API */
|
||||
|
||||
virtual RID mesh_allocate() override;
|
||||
virtual void mesh_initialize(RID p_rid) override;
|
||||
virtual void mesh_free(RID p_rid) override;
|
||||
|
||||
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override;
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
|
||||
|
||||
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override;
|
||||
|
||||
virtual int mesh_get_blend_shape_count(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override;
|
||||
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
|
||||
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override;
|
||||
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const override;
|
||||
|
||||
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override;
|
||||
virtual int mesh_get_surface_count(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override;
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const override;
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;
|
||||
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;
|
||||
virtual void mesh_clear(RID p_mesh) override;
|
||||
|
||||
/* MESH INSTANCE API */
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base) override;
|
||||
virtual void mesh_instance_free(RID p_rid) override;
|
||||
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override;
|
||||
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override;
|
||||
virtual void mesh_instance_check_for_update(RID p_mesh_instance) override;
|
||||
virtual void update_mesh_instances() override;
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
struct MultiMesh {
|
||||
RID mesh;
|
||||
int instances = 0;
|
||||
RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
|
||||
bool uses_colors = false;
|
||||
bool uses_custom_data = false;
|
||||
int visible_instances = -1;
|
||||
AABB aabb;
|
||||
bool aabb_dirty = false;
|
||||
bool buffer_set = false;
|
||||
uint32_t stride_cache = 0;
|
||||
uint32_t color_offset_cache = 0;
|
||||
uint32_t custom_data_offset_cache = 0;
|
||||
|
||||
Vector<float> data_cache; //used if individual setting is used
|
||||
bool *data_cache_dirty_regions = nullptr;
|
||||
uint32_t data_cache_used_dirty_regions = 0;
|
||||
|
||||
RID buffer; //storage buffer
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_2d;
|
||||
|
||||
bool dirty = false;
|
||||
MultiMesh *dirty_list = nullptr;
|
||||
|
||||
RendererStorage::Dependency dependency;
|
||||
};
|
||||
|
||||
mutable RID_Owner<MultiMesh, true> multimesh_owner;
|
||||
|
||||
MultiMesh *multimesh_dirty_list = nullptr;
|
||||
|
||||
_FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
|
||||
_FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
|
||||
void _update_dirty_multimeshes();
|
||||
|
||||
virtual RID multimesh_allocate() override;
|
||||
virtual void multimesh_initialize(RID p_rid) override;
|
||||
virtual void multimesh_free(RID p_rid) override;
|
||||
virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override;
|
||||
virtual int multimesh_get_instance_count(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
|
||||
virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
|
||||
virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
|
||||
virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
|
||||
virtual RID multimesh_get_mesh(RID p_multimesh) const override;
|
||||
virtual AABB multimesh_get_aabb(RID p_multimesh) const override;
|
||||
|
||||
virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
|
||||
virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
|
||||
virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
|
||||
virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
|
||||
virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
|
||||
virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
|
||||
virtual int multimesh_get_visible_instances(RID p_multimesh) const override;
|
||||
|
||||
_FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->xform_format;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_colors;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_custom_data;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (multimesh->visible_instances >= 0) {
|
||||
return multimesh->visible_instances;
|
||||
}
|
||||
return multimesh->instances;
|
||||
}
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
virtual RID skeleton_allocate() override;
|
||||
virtual void skeleton_initialize(RID p_rid) override;
|
||||
virtual void skeleton_free(RID p_rid) override;
|
||||
|
||||
virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override;
|
||||
virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override;
|
||||
virtual int skeleton_get_bone_count(RID p_skeleton) const override;
|
||||
virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override;
|
||||
virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override;
|
||||
virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override;
|
||||
virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override;
|
||||
|
||||
virtual void skeleton_update_dependency(RID p_base, RendererStorage::DependencyTracker *p_instance) override;
|
||||
};
|
||||
|
||||
} // namespace GLES3
|
||||
|
||||
#endif // GLES3_ENABLED
|
||||
|
||||
#endif // !MESH_STORAGE_GLES3_H
|
|
@ -40,6 +40,7 @@
|
|||
#include "servers/rendering/dummy/storage/canvas_texture_storage.h"
|
||||
#include "servers/rendering/dummy/storage/decal_atlas_storage.h"
|
||||
#include "servers/rendering/dummy/storage/material_storage.h"
|
||||
#include "servers/rendering/dummy/storage/mesh_storage.h"
|
||||
#include "servers/rendering/dummy/storage/texture_storage.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "servers/rendering_server.h"
|
||||
|
@ -53,6 +54,7 @@ protected:
|
|||
RasterizerCanvasDummy canvas;
|
||||
RendererDummy::CanvasTextureStorage canvas_texture_storage;
|
||||
RendererDummy::MaterialStorage material_storage;
|
||||
RendererDummy::MeshStorage mesh_storage;
|
||||
RendererDummy::TextureStorage texture_storage;
|
||||
RendererDummy::DecalAtlasStorage decal_atlas_storage;
|
||||
RasterizerStorageDummy storage;
|
||||
|
@ -61,6 +63,7 @@ protected:
|
|||
public:
|
||||
RendererCanvasTextureStorage *get_canvas_texture_storage() override { return &canvas_texture_storage; };
|
||||
RendererMaterialStorage *get_material_storage() override { return &material_storage; };
|
||||
RendererMeshStorage *get_mesh_storage() override { return &mesh_storage; };
|
||||
RendererTextureStorage *get_texture_storage() override { return &texture_storage; };
|
||||
RendererDecalAtlasStorage *get_decal_atlas_storage() override { return &decal_atlas_storage; };
|
||||
RendererStorage *get_storage() override { return &storage; }
|
||||
|
|
|
@ -36,82 +36,6 @@
|
|||
|
||||
class RasterizerStorageDummy : public RendererStorage {
|
||||
public:
|
||||
/* MESH API */
|
||||
|
||||
RID mesh_allocate() override { return RID(); }
|
||||
void mesh_initialize(RID p_rid) override {}
|
||||
void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override {}
|
||||
bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override { return false; }
|
||||
RID mesh_instance_create(RID p_base) override { return RID(); }
|
||||
void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override {}
|
||||
void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override {}
|
||||
void mesh_instance_check_for_update(RID p_mesh_instance) override {}
|
||||
void update_mesh_instances() override {}
|
||||
void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) override {}
|
||||
float reflection_probe_get_mesh_lod_threshold(RID p_probe) const override { return 0.0; }
|
||||
|
||||
void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override {}
|
||||
|
||||
int mesh_get_blend_shape_count(RID p_mesh) const override { return 0; }
|
||||
|
||||
void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override {}
|
||||
RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override { return RS::BLEND_SHAPE_MODE_NORMALIZED; }
|
||||
|
||||
void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
|
||||
void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
|
||||
void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
|
||||
|
||||
void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override {}
|
||||
RID mesh_surface_get_material(RID p_mesh, int p_surface) const override { return RID(); }
|
||||
|
||||
RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override { return RS::SurfaceData(); }
|
||||
int mesh_get_surface_count(RID p_mesh) const override { return 0; }
|
||||
|
||||
void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override {}
|
||||
AABB mesh_get_custom_aabb(RID p_mesh) const override { return AABB(); }
|
||||
|
||||
AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override { return AABB(); }
|
||||
void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override {}
|
||||
void mesh_clear(RID p_mesh) override {}
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
RID multimesh_allocate() override { return RID(); }
|
||||
void multimesh_initialize(RID p_rid) override {}
|
||||
void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override {}
|
||||
int multimesh_get_instance_count(RID p_multimesh) const override { return 0; }
|
||||
|
||||
void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override {}
|
||||
void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override {}
|
||||
void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override {}
|
||||
void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override {}
|
||||
void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override {}
|
||||
|
||||
RID multimesh_get_mesh(RID p_multimesh) const override { return RID(); }
|
||||
AABB multimesh_get_aabb(RID p_multimesh) const override { return AABB(); }
|
||||
|
||||
Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override { return Transform3D(); }
|
||||
Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override { return Transform2D(); }
|
||||
Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override { return Color(); }
|
||||
Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override { return Color(); }
|
||||
void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override {}
|
||||
Vector<float> multimesh_get_buffer(RID p_multimesh) const override { return Vector<float>(); }
|
||||
|
||||
void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override {}
|
||||
int multimesh_get_visible_instances(RID p_multimesh) const override { return 0; }
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
RID skeleton_allocate() override { return RID(); }
|
||||
void skeleton_initialize(RID p_rid) override {}
|
||||
void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override {}
|
||||
void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override {}
|
||||
int skeleton_get_bone_count(RID p_skeleton) const override { return 0; }
|
||||
void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override {}
|
||||
Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override { return Transform3D(); }
|
||||
void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override {}
|
||||
Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override { return Transform2D(); }
|
||||
|
||||
/* Light API */
|
||||
|
||||
RID directional_light_allocate() override { return RID(); }
|
||||
|
@ -171,6 +95,8 @@ public:
|
|||
void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override {}
|
||||
void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override {}
|
||||
void reflection_probe_set_resolution(RID p_probe, int p_resolution) override {}
|
||||
void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) override {}
|
||||
float reflection_probe_get_mesh_lod_threshold(RID p_probe) const override { return 0.0; }
|
||||
|
||||
AABB reflection_probe_get_aabb(RID p_probe) const override { return AABB(); }
|
||||
RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override { return RenderingServer::REFLECTION_PROBE_UPDATE_ONCE; }
|
||||
|
@ -181,7 +107,6 @@ public:
|
|||
bool reflection_probe_renders_shadows(RID p_probe) const override { return false; }
|
||||
|
||||
void base_update_dependency(RID p_base, DependencyTracker *p_instance) override {}
|
||||
void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override {}
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
||||
|
|
129
servers/rendering/dummy/storage/mesh_storage.h
Normal file
129
servers/rendering/dummy/storage/mesh_storage.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
/*************************************************************************/
|
||||
/* mesh_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef MESH_STORAGE_DUMMY_H
|
||||
#define MESH_STORAGE_DUMMY_H
|
||||
|
||||
#include "servers/rendering/storage/mesh_storage.h"
|
||||
|
||||
namespace RendererDummy {
|
||||
|
||||
class MeshStorage : public RendererMeshStorage {
|
||||
public:
|
||||
/* MESH API */
|
||||
|
||||
virtual RID mesh_allocate() override { return RID(); }
|
||||
virtual void mesh_initialize(RID p_rid) override {}
|
||||
virtual void mesh_free(RID p_rid) override {}
|
||||
|
||||
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override {}
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override { return false; }
|
||||
|
||||
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override {}
|
||||
|
||||
virtual int mesh_get_blend_shape_count(RID p_mesh) const override { return 0; }
|
||||
|
||||
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override {}
|
||||
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override { return RS::BLEND_SHAPE_MODE_NORMALIZED; }
|
||||
|
||||
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
|
||||
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
|
||||
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
|
||||
|
||||
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override {}
|
||||
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const override { return RID(); }
|
||||
|
||||
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override { return RS::SurfaceData(); }
|
||||
virtual int mesh_get_surface_count(RID p_mesh) const override { return 0; }
|
||||
|
||||
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override {}
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const override { return AABB(); }
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override { return AABB(); }
|
||||
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override {}
|
||||
virtual void mesh_clear(RID p_mesh) override {}
|
||||
|
||||
/* MESH INSTANCE */
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base) override { return RID(); }
|
||||
virtual void mesh_instance_free(RID p_rid) override {}
|
||||
|
||||
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override {}
|
||||
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override {}
|
||||
virtual void mesh_instance_check_for_update(RID p_mesh_instance) override {}
|
||||
virtual void update_mesh_instances() override {}
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
virtual RID multimesh_allocate() override { return RID(); }
|
||||
virtual void multimesh_initialize(RID p_rid) override {}
|
||||
virtual void multimesh_free(RID p_rid) override {}
|
||||
|
||||
virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override {}
|
||||
virtual int multimesh_get_instance_count(RID p_multimesh) const override { return 0; }
|
||||
|
||||
virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override {}
|
||||
virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override {}
|
||||
virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override {}
|
||||
virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override {}
|
||||
virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override {}
|
||||
|
||||
virtual RID multimesh_get_mesh(RID p_multimesh) const override { return RID(); }
|
||||
virtual AABB multimesh_get_aabb(RID p_multimesh) const override { return AABB(); }
|
||||
|
||||
virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override { return Transform3D(); }
|
||||
virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override { return Transform2D(); }
|
||||
virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override { return Color(); }
|
||||
virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override { return Color(); }
|
||||
virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override {}
|
||||
virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const override { return Vector<float>(); }
|
||||
|
||||
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override {}
|
||||
virtual int multimesh_get_visible_instances(RID p_multimesh) const override { return 0; }
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
virtual RID skeleton_allocate() override { return RID(); }
|
||||
virtual void skeleton_initialize(RID p_rid) override {}
|
||||
virtual void skeleton_free(RID p_rid) override {}
|
||||
virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override {}
|
||||
virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override {}
|
||||
virtual int skeleton_get_bone_count(RID p_skeleton) const override { return 0; }
|
||||
virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override {}
|
||||
virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override { return Transform3D(); }
|
||||
virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override {}
|
||||
virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override { return Transform2D(); }
|
||||
|
||||
virtual void skeleton_update_dependency(RID p_base, RendererStorage::DependencyTracker *p_instance) override {}
|
||||
};
|
||||
|
||||
} // namespace RendererDummy
|
||||
|
||||
#endif // !MESH_STORAGE_DUMMY_H
|
|
@ -997,8 +997,8 @@ void RendererCanvasCull::canvas_item_add_mesh(RID p_item, const RID &p_mesh, con
|
|||
ERR_FAIL_COND(!m);
|
||||
m->mesh = p_mesh;
|
||||
if (canvas_item->skeleton.is_valid()) {
|
||||
m->mesh_instance = RSG::storage->mesh_instance_create(p_mesh);
|
||||
RSG::storage->mesh_instance_set_skeleton(m->mesh_instance, canvas_item->skeleton);
|
||||
m->mesh_instance = RSG::mesh_storage->mesh_instance_create(p_mesh);
|
||||
RSG::mesh_storage->mesh_instance_set_skeleton(m->mesh_instance, canvas_item->skeleton);
|
||||
}
|
||||
|
||||
m->texture = p_texture;
|
||||
|
@ -1093,12 +1093,12 @@ void RendererCanvasCull::canvas_item_attach_skeleton(RID p_item, RID p_skeleton)
|
|||
Item::CommandMesh *cm = static_cast<Item::CommandMesh *>(c);
|
||||
if (canvas_item->skeleton.is_valid()) {
|
||||
if (cm->mesh_instance.is_null()) {
|
||||
cm->mesh_instance = RSG::storage->mesh_instance_create(cm->mesh);
|
||||
cm->mesh_instance = RSG::mesh_storage->mesh_instance_create(cm->mesh);
|
||||
}
|
||||
RSG::storage->mesh_instance_set_skeleton(cm->mesh_instance, canvas_item->skeleton);
|
||||
RSG::mesh_storage->mesh_instance_set_skeleton(cm->mesh_instance, canvas_item->skeleton);
|
||||
} else {
|
||||
if (cm->mesh_instance.is_valid()) {
|
||||
RSG::storage->free(cm->mesh_instance);
|
||||
RSG::mesh_storage->mesh_instance_free(cm->mesh_instance);
|
||||
cm->mesh_instance = RID();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#ifndef RENDERINGSERVERCANVASRENDER_H
|
||||
#define RENDERINGSERVERCANVASRENDER_H
|
||||
|
||||
#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
|
||||
#include "servers/rendering/renderer_storage.h"
|
||||
|
||||
class RendererCanvasRender {
|
||||
|
@ -403,14 +404,14 @@ public:
|
|||
} break;
|
||||
case Item::Command::TYPE_MESH: {
|
||||
const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c);
|
||||
AABB aabb = RendererStorage::base_singleton->mesh_get_aabb(mesh->mesh, RID());
|
||||
AABB aabb = RendererRD::MeshStorage::get_singleton()->mesh_get_aabb(mesh->mesh, RID());
|
||||
|
||||
r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y);
|
||||
|
||||
} break;
|
||||
case Item::Command::TYPE_MULTIMESH: {
|
||||
const Item::CommandMultiMesh *multimesh = static_cast<const Item::CommandMultiMesh *>(c);
|
||||
AABB aabb = RendererStorage::base_singleton->multimesh_get_aabb(multimesh->multimesh);
|
||||
AABB aabb = RendererRD::MeshStorage::get_singleton()->multimesh_get_aabb(multimesh->multimesh);
|
||||
|
||||
r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "servers/rendering/storage/canvas_texture_storage.h"
|
||||
#include "servers/rendering/storage/decal_atlas_storage.h"
|
||||
#include "servers/rendering/storage/material_storage.h"
|
||||
#include "servers/rendering/storage/mesh_storage.h"
|
||||
#include "servers/rendering/storage/texture_storage.h"
|
||||
#include "servers/rendering_server.h"
|
||||
|
||||
|
@ -76,6 +77,7 @@ public:
|
|||
|
||||
virtual RendererCanvasTextureStorage *get_canvas_texture_storage() = 0;
|
||||
virtual RendererMaterialStorage *get_material_storage() = 0;
|
||||
virtual RendererMeshStorage *get_mesh_storage() = 0;
|
||||
virtual RendererTextureStorage *get_texture_storage() = 0;
|
||||
virtual RendererDecalAtlasStorage *get_decal_atlas_storage() = 0;
|
||||
virtual RendererStorage *get_storage() = 0;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "render_forward_clustered.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/decal_atlas_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
|
||||
#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
#include "servers/rendering/rendering_server_default.h"
|
||||
|
@ -316,6 +317,7 @@ bool RenderForwardClustered::free(RID p_rid) {
|
|||
|
||||
template <RenderForwardClustered::PassMode p_pass_mode, uint32_t p_color_pass_flags>
|
||||
void RenderForwardClustered::_render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
RD::DrawListID draw_list = p_draw_list;
|
||||
RD::FramebufferFormatID framebuffer_format = p_framebuffer_Format;
|
||||
|
||||
|
@ -491,12 +493,12 @@ void RenderForwardClustered::_render_list_template(RenderingDevice::DrawListID p
|
|||
|
||||
//skeleton and blend shape
|
||||
if (surf->owner->mesh_instance.is_valid()) {
|
||||
storage->mesh_instance_surface_get_vertex_arrays_and_format(surf->owner->mesh_instance, surf->surface_index, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
mesh_storage->mesh_instance_surface_get_vertex_arrays_and_format(surf->owner->mesh_instance, surf->surface_index, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
} else {
|
||||
storage->mesh_surface_get_vertex_arrays_and_format(mesh_surface, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
mesh_storage->mesh_surface_get_vertex_arrays_and_format(mesh_surface, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
}
|
||||
|
||||
index_array_rd = storage->mesh_surface_get_index_array(mesh_surface, element_info.lod_index);
|
||||
index_array_rd = mesh_storage->mesh_surface_get_index_array(mesh_surface, element_info.lod_index);
|
||||
|
||||
if (prev_vertex_array_rd != vertex_array_rd) {
|
||||
RD::get_singleton()->draw_list_bind_vertex_array(draw_list, vertex_array_rd);
|
||||
|
@ -963,6 +965,8 @@ _FORCE_INLINE_ static uint32_t _indices_to_primitives(RS::PrimitiveType p_primit
|
|||
return (p_indices - subtractor[p_primitive]) / divisor[p_primitive];
|
||||
}
|
||||
void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_using_sdfgi, bool p_using_opaque_gi, bool p_append) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
if (p_render_list == RENDER_LIST_OPAQUE) {
|
||||
scene_state.used_sss = false;
|
||||
scene_state.used_screen_texture = false;
|
||||
|
@ -1099,7 +1103,7 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con
|
|||
|
||||
// LOD
|
||||
|
||||
if (p_render_data->screen_mesh_lod_threshold > 0.0 && storage->mesh_surface_has_lod(surf->surface)) {
|
||||
if (p_render_data->screen_mesh_lod_threshold > 0.0 && mesh_storage->mesh_surface_has_lod(surf->surface)) {
|
||||
//lod
|
||||
Vector3 lod_support_min = inst->transformed_aabb.get_support(-p_render_data->lod_camera_plane.normal);
|
||||
Vector3 lod_support_max = inst->transformed_aabb.get_support(p_render_data->lod_camera_plane.normal);
|
||||
|
@ -1123,7 +1127,7 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con
|
|||
}
|
||||
|
||||
uint32_t indices;
|
||||
surf->sort.lod_index = storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_mesh_lod_threshold, &indices);
|
||||
surf->sort.lod_index = mesh_storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_mesh_lod_threshold, &indices);
|
||||
if (p_render_data->render_info) {
|
||||
indices = _indices_to_primitives(surf->primitive, indices);
|
||||
if (p_render_list == RENDER_LIST_OPAQUE) { //opaque
|
||||
|
@ -1135,13 +1139,13 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con
|
|||
} else {
|
||||
surf->sort.lod_index = 0;
|
||||
if (p_render_data->render_info) {
|
||||
uint32_t to_draw = storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
uint32_t to_draw = mesh_storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
to_draw = _indices_to_primitives(surf->primitive, to_draw);
|
||||
to_draw *= inst->instance_count;
|
||||
if (p_render_list == RENDER_LIST_OPAQUE) { //opaque
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += mesh_storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
} else if (p_render_list == RENDER_LIST_SECONDARY) { //shadow
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += mesh_storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2610,6 +2614,8 @@ void RenderForwardClustered::_geometry_instance_mark_dirty(GeometryInstance *p_g
|
|||
}
|
||||
|
||||
void RenderForwardClustered::_geometry_instance_add_surface_with_material(GeometryInstanceForwardClustered *ginstance, uint32_t p_surface, SceneShaderForwardClustered::MaterialData *p_material, uint32_t p_material_id, uint32_t p_shader_id, RID p_mesh) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
bool has_read_screen_alpha = p_material->shader_data->uses_screen_texture || p_material->shader_data->uses_depth_texture || p_material->shader_data->uses_normal_texture;
|
||||
bool has_base_alpha = (p_material->shader_data->uses_alpha && !p_material->shader_data->uses_alpha_clip) || has_read_screen_alpha;
|
||||
bool has_blend_alpha = p_material->shader_data->uses_blend_alpha;
|
||||
|
@ -2660,10 +2666,10 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet
|
|||
flags |= GeometryInstanceSurfaceDataCache::FLAG_USES_SHARED_SHADOW_MATERIAL;
|
||||
material_shadow = (SceneShaderForwardClustered::MaterialData *)RendererRD::MaterialStorage::get_singleton()->material_get_data(scene_shader.default_material, RendererRD::SHADER_TYPE_3D);
|
||||
|
||||
RID shadow_mesh = storage->mesh_get_shadow_mesh(p_mesh);
|
||||
RID shadow_mesh = mesh_storage->mesh_get_shadow_mesh(p_mesh);
|
||||
|
||||
if (shadow_mesh.is_valid()) {
|
||||
surface_shadow = storage->mesh_get_surface(shadow_mesh, p_surface);
|
||||
surface_shadow = mesh_storage->mesh_get_surface(shadow_mesh, p_surface);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -2676,8 +2682,8 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet
|
|||
|
||||
sdcache->shader = p_material->shader_data;
|
||||
sdcache->material_uniform_set = p_material->uniform_set;
|
||||
sdcache->surface = storage->mesh_get_surface(p_mesh, p_surface);
|
||||
sdcache->primitive = storage->mesh_surface_get_primitive(sdcache->surface);
|
||||
sdcache->surface = mesh_storage->mesh_get_surface(p_mesh, p_surface);
|
||||
sdcache->primitive = mesh_storage->mesh_surface_get_primitive(sdcache->surface);
|
||||
sdcache->surface_index = p_surface;
|
||||
|
||||
if (ginstance->data->dirty_dependencies) {
|
||||
|
@ -2773,6 +2779,7 @@ void RenderForwardClustered::_geometry_instance_add_surface(GeometryInstanceForw
|
|||
}
|
||||
|
||||
void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geometry_instance) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
GeometryInstanceForwardClustered *ginstance = static_cast<GeometryInstanceForwardClustered *>(p_geometry_instance);
|
||||
|
||||
if (ginstance->data->dirty_dependencies) {
|
||||
|
@ -2786,7 +2793,7 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome
|
|||
uint32_t surface_count;
|
||||
RID mesh = ginstance->data->base;
|
||||
|
||||
materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
materials = mesh_storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
if (materials) {
|
||||
//if no materials, no surfaces.
|
||||
const RID *inst_materials = ginstance->data->surface_materials.ptr();
|
||||
|
@ -2803,19 +2810,19 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome
|
|||
} break;
|
||||
|
||||
case RS::INSTANCE_MULTIMESH: {
|
||||
RID mesh = storage->multimesh_get_mesh(ginstance->data->base);
|
||||
RID mesh = mesh_storage->multimesh_get_mesh(ginstance->data->base);
|
||||
if (mesh.is_valid()) {
|
||||
const RID *materials = nullptr;
|
||||
uint32_t surface_count;
|
||||
|
||||
materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
materials = mesh_storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
if (materials) {
|
||||
for (uint32_t j = 0; j < surface_count; j++) {
|
||||
_geometry_instance_add_surface(ginstance, j, materials[j], mesh);
|
||||
}
|
||||
}
|
||||
|
||||
ginstance->instance_count = storage->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
ginstance->instance_count = mesh_storage->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -2840,7 +2847,7 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome
|
|||
const RID *materials = nullptr;
|
||||
uint32_t surface_count;
|
||||
|
||||
materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
materials = mesh_storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
if (materials) {
|
||||
for (uint32_t k = 0; k < surface_count; k++) {
|
||||
_geometry_instance_add_surface(ginstance, k, materials[k], mesh);
|
||||
|
@ -2864,17 +2871,17 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome
|
|||
|
||||
if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH;
|
||||
if (storage->multimesh_get_transform_format(ginstance->data->base) == RS::MULTIMESH_TRANSFORM_2D) {
|
||||
if (mesh_storage->multimesh_get_transform_format(ginstance->data->base) == RS::MULTIMESH_TRANSFORM_2D) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH_FORMAT_2D;
|
||||
}
|
||||
if (storage->multimesh_uses_colors(ginstance->data->base)) {
|
||||
if (mesh_storage->multimesh_uses_colors(ginstance->data->base)) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH_HAS_COLOR;
|
||||
}
|
||||
if (storage->multimesh_uses_custom_data(ginstance->data->base)) {
|
||||
if (mesh_storage->multimesh_uses_custom_data(ginstance->data->base)) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA;
|
||||
}
|
||||
|
||||
ginstance->transforms_uniform_set = storage->multimesh_get_3d_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
ginstance->transforms_uniform_set = mesh_storage->multimesh_get_3d_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
|
||||
} else if (ginstance->data->base_type == RS::INSTANCE_PARTICLES) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH;
|
||||
|
@ -2891,10 +2898,10 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome
|
|||
ginstance->transforms_uniform_set = storage->particles_get_instance_buffer_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
|
||||
} else if (ginstance->data->base_type == RS::INSTANCE_MESH) {
|
||||
if (storage->skeleton_is_valid(ginstance->data->skeleton)) {
|
||||
ginstance->transforms_uniform_set = storage->skeleton_get_3d_uniform_set(ginstance->data->skeleton, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
if (mesh_storage->skeleton_is_valid(ginstance->data->skeleton)) {
|
||||
ginstance->transforms_uniform_set = mesh_storage->skeleton_get_3d_uniform_set(ginstance->data->skeleton, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
if (ginstance->data->dirty_dependencies) {
|
||||
storage->skeleton_update_dependency(ginstance->data->skeleton, &ginstance->data->dependency_tracker);
|
||||
mesh_storage->skeleton_update_dependency(ginstance->data->skeleton, &ginstance->data->dependency_tracker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2934,7 +2941,7 @@ void RenderForwardClustered::_geometry_instance_dependency_changed(RendererStora
|
|||
case RendererStorage::DEPENDENCY_CHANGED_MULTIMESH_VISIBLE_INSTANCES: {
|
||||
GeometryInstanceForwardClustered *ginstance = static_cast<GeometryInstanceForwardClustered *>(p_tracker->userdata);
|
||||
if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) {
|
||||
ginstance->instance_count = static_cast<RenderForwardClustered *>(singleton)->storage->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
ginstance->instance_count = RendererRD::MeshStorage::get_singleton()->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "render_forward_mobile.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/decal_atlas_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
#include "servers/rendering/rendering_server_default.h"
|
||||
|
||||
|
@ -1325,6 +1326,8 @@ _FORCE_INLINE_ static uint32_t _indices_to_primitives(RS::PrimitiveType p_primit
|
|||
}
|
||||
|
||||
void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_append) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
if (p_render_list == RENDER_LIST_OPAQUE) {
|
||||
scene_state.used_sss = false;
|
||||
scene_state.used_screen_texture = false;
|
||||
|
@ -1414,7 +1417,7 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const
|
|||
|
||||
// LOD
|
||||
|
||||
if (p_render_data->screen_mesh_lod_threshold > 0.0 && storage->mesh_surface_has_lod(surf->surface)) {
|
||||
if (p_render_data->screen_mesh_lod_threshold > 0.0 && mesh_storage->mesh_surface_has_lod(surf->surface)) {
|
||||
//lod
|
||||
Vector3 lod_support_min = inst->transformed_aabb.get_support(-p_render_data->lod_camera_plane.normal);
|
||||
Vector3 lod_support_max = inst->transformed_aabb.get_support(p_render_data->lod_camera_plane.normal);
|
||||
|
@ -1438,7 +1441,7 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const
|
|||
}
|
||||
|
||||
uint32_t indices;
|
||||
surf->lod_index = storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_mesh_lod_threshold, &indices);
|
||||
surf->lod_index = mesh_storage->mesh_surface_get_lod(surf->surface, inst->lod_model_scale * inst->lod_bias, distance * p_render_data->lod_distance_multiplier, p_render_data->screen_mesh_lod_threshold, &indices);
|
||||
if (p_render_data->render_info) {
|
||||
indices = _indices_to_primitives(surf->primitive, indices);
|
||||
if (p_render_list == RENDER_LIST_OPAQUE) { //opaque
|
||||
|
@ -1450,13 +1453,13 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const
|
|||
} else {
|
||||
surf->lod_index = 0;
|
||||
if (p_render_data->render_info) {
|
||||
uint32_t to_draw = storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
uint32_t to_draw = mesh_storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
to_draw = _indices_to_primitives(surf->primitive, to_draw);
|
||||
to_draw *= inst->instance_count;
|
||||
if (p_render_list == RENDER_LIST_OPAQUE) { //opaque
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_VISIBLE][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += mesh_storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
} else if (p_render_list == RENDER_LIST_SECONDARY) { //shadow
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
p_render_data->render_info->info[RS::VIEWPORT_RENDER_INFO_TYPE_SHADOW][RS::VIEWPORT_RENDER_INFO_PRIMITIVES_IN_FRAME] += mesh_storage->mesh_surface_get_vertices_drawn_count(surf->surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1814,6 +1817,8 @@ void RenderForwardMobile::_fill_push_constant_instance_indices(GeometryInstanceF
|
|||
|
||||
template <RenderForwardMobile::PassMode p_pass_mode>
|
||||
void RenderForwardMobile::_render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
RD::DrawListID draw_list = p_draw_list;
|
||||
RD::FramebufferFormatID framebuffer_format = p_framebuffer_Format;
|
||||
|
||||
|
@ -1956,12 +1961,12 @@ void RenderForwardMobile::_render_list_template(RenderingDevice::DrawListID p_dr
|
|||
|
||||
//skeleton and blend shape
|
||||
if (surf->owner->mesh_instance.is_valid()) {
|
||||
storage->mesh_instance_surface_get_vertex_arrays_and_format(surf->owner->mesh_instance, surf->surface_index, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
mesh_storage->mesh_instance_surface_get_vertex_arrays_and_format(surf->owner->mesh_instance, surf->surface_index, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
} else {
|
||||
storage->mesh_surface_get_vertex_arrays_and_format(mesh_surface, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
mesh_storage->mesh_surface_get_vertex_arrays_and_format(mesh_surface, pipeline->get_vertex_input_mask(), vertex_array_rd, vertex_format);
|
||||
}
|
||||
|
||||
index_array_rd = storage->mesh_surface_get_index_array(mesh_surface, element_info.lod_index);
|
||||
index_array_rd = mesh_storage->mesh_surface_get_index_array(mesh_surface, element_info.lod_index);
|
||||
|
||||
if (prev_vertex_array_rd != vertex_array_rd) {
|
||||
RD::get_singleton()->draw_list_bind_vertex_array(draw_list, vertex_array_rd);
|
||||
|
@ -2280,6 +2285,8 @@ void RenderForwardMobile::_geometry_instance_mark_dirty(GeometryInstance *p_geom
|
|||
}
|
||||
|
||||
void RenderForwardMobile::_geometry_instance_add_surface_with_material(GeometryInstanceForwardMobile *ginstance, uint32_t p_surface, SceneShaderForwardMobile::MaterialData *p_material, uint32_t p_material_id, uint32_t p_shader_id, RID p_mesh) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
bool has_read_screen_alpha = p_material->shader_data->uses_screen_texture || p_material->shader_data->uses_depth_texture || p_material->shader_data->uses_normal_texture;
|
||||
bool has_base_alpha = ((p_material->shader_data->uses_alpha && !p_material->shader_data->uses_alpha_clip) || has_read_screen_alpha);
|
||||
bool has_blend_alpha = p_material->shader_data->uses_blend_alpha;
|
||||
|
@ -2330,10 +2337,10 @@ void RenderForwardMobile::_geometry_instance_add_surface_with_material(GeometryI
|
|||
flags |= GeometryInstanceSurfaceDataCache::FLAG_USES_SHARED_SHADOW_MATERIAL;
|
||||
material_shadow = (SceneShaderForwardMobile::MaterialData *)RendererRD::MaterialStorage::get_singleton()->material_get_data(scene_shader.default_material, RendererRD::SHADER_TYPE_3D);
|
||||
|
||||
RID shadow_mesh = storage->mesh_get_shadow_mesh(p_mesh);
|
||||
RID shadow_mesh = mesh_storage->mesh_get_shadow_mesh(p_mesh);
|
||||
|
||||
if (shadow_mesh.is_valid()) {
|
||||
surface_shadow = storage->mesh_get_surface(shadow_mesh, p_surface);
|
||||
surface_shadow = mesh_storage->mesh_get_surface(shadow_mesh, p_surface);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -2346,8 +2353,8 @@ void RenderForwardMobile::_geometry_instance_add_surface_with_material(GeometryI
|
|||
|
||||
sdcache->shader = p_material->shader_data;
|
||||
sdcache->material_uniform_set = p_material->uniform_set;
|
||||
sdcache->surface = storage->mesh_get_surface(p_mesh, p_surface);
|
||||
sdcache->primitive = storage->mesh_surface_get_primitive(sdcache->surface);
|
||||
sdcache->surface = mesh_storage->mesh_get_surface(p_mesh, p_surface);
|
||||
sdcache->primitive = mesh_storage->mesh_surface_get_primitive(sdcache->surface);
|
||||
sdcache->surface_index = p_surface;
|
||||
|
||||
if (ginstance->data->dirty_dependencies) {
|
||||
|
@ -2441,6 +2448,7 @@ void RenderForwardMobile::_geometry_instance_add_surface(GeometryInstanceForward
|
|||
}
|
||||
|
||||
void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry_instance) {
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
GeometryInstanceForwardMobile *ginstance = static_cast<GeometryInstanceForwardMobile *>(p_geometry_instance);
|
||||
|
||||
if (ginstance->data->dirty_dependencies) {
|
||||
|
@ -2454,7 +2462,7 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry
|
|||
uint32_t surface_count;
|
||||
RID mesh = ginstance->data->base;
|
||||
|
||||
materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
materials = mesh_storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
if (materials) {
|
||||
//if no materials, no surfaces.
|
||||
const RID *inst_materials = ginstance->data->surface_materials.ptr();
|
||||
|
@ -2471,19 +2479,19 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry
|
|||
} break;
|
||||
|
||||
case RS::INSTANCE_MULTIMESH: {
|
||||
RID mesh = storage->multimesh_get_mesh(ginstance->data->base);
|
||||
RID mesh = mesh_storage->multimesh_get_mesh(ginstance->data->base);
|
||||
if (mesh.is_valid()) {
|
||||
const RID *materials = nullptr;
|
||||
uint32_t surface_count;
|
||||
|
||||
materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
materials = mesh_storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
if (materials) {
|
||||
for (uint32_t j = 0; j < surface_count; j++) {
|
||||
_geometry_instance_add_surface(ginstance, j, materials[j], mesh);
|
||||
}
|
||||
}
|
||||
|
||||
ginstance->instance_count = storage->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
ginstance->instance_count = mesh_storage->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -2508,7 +2516,7 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry
|
|||
const RID *materials = nullptr;
|
||||
uint32_t surface_count;
|
||||
|
||||
materials = storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
materials = mesh_storage->mesh_get_surface_count_and_materials(mesh, surface_count);
|
||||
if (materials) {
|
||||
for (uint32_t k = 0; k < surface_count; k++) {
|
||||
_geometry_instance_add_surface(ginstance, k, materials[k], mesh);
|
||||
|
@ -2531,17 +2539,17 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry
|
|||
|
||||
if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH;
|
||||
if (storage->multimesh_get_transform_format(ginstance->data->base) == RS::MULTIMESH_TRANSFORM_2D) {
|
||||
if (mesh_storage->multimesh_get_transform_format(ginstance->data->base) == RS::MULTIMESH_TRANSFORM_2D) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH_FORMAT_2D;
|
||||
}
|
||||
if (storage->multimesh_uses_colors(ginstance->data->base)) {
|
||||
if (mesh_storage->multimesh_uses_colors(ginstance->data->base)) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH_HAS_COLOR;
|
||||
}
|
||||
if (storage->multimesh_uses_custom_data(ginstance->data->base)) {
|
||||
if (mesh_storage->multimesh_uses_custom_data(ginstance->data->base)) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA;
|
||||
}
|
||||
|
||||
ginstance->transforms_uniform_set = storage->multimesh_get_3d_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
ginstance->transforms_uniform_set = mesh_storage->multimesh_get_3d_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
|
||||
} else if (ginstance->data->base_type == RS::INSTANCE_PARTICLES) {
|
||||
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH;
|
||||
|
@ -2561,10 +2569,10 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry
|
|||
ginstance->transforms_uniform_set = storage->particles_get_instance_buffer_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
|
||||
} else if (ginstance->data->base_type == RS::INSTANCE_MESH) {
|
||||
if (storage->skeleton_is_valid(ginstance->data->skeleton)) {
|
||||
ginstance->transforms_uniform_set = storage->skeleton_get_3d_uniform_set(ginstance->data->skeleton, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
if (mesh_storage->skeleton_is_valid(ginstance->data->skeleton)) {
|
||||
ginstance->transforms_uniform_set = mesh_storage->skeleton_get_3d_uniform_set(ginstance->data->skeleton, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
|
||||
if (ginstance->data->dirty_dependencies) {
|
||||
storage->skeleton_update_dependency(ginstance->data->skeleton, &ginstance->data->dependency_tracker);
|
||||
mesh_storage->skeleton_update_dependency(ginstance->data->skeleton, &ginstance->data->dependency_tracker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2597,7 +2605,7 @@ void RenderForwardMobile::_geometry_instance_dependency_changed(RendererStorage:
|
|||
case RendererStorage::DEPENDENCY_CHANGED_MULTIMESH_VISIBLE_INSTANCES: {
|
||||
GeometryInstanceForwardMobile *ginstance = static_cast<GeometryInstanceForwardMobile *>(p_tracker->userdata);
|
||||
if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) {
|
||||
ginstance->instance_count = static_cast<RenderForwardMobile *>(singleton)->storage->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
ginstance->instance_count = RendererRD::MeshStorage::get_singleton()->multimesh_get_instances_to_draw(ginstance->data->base);
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
|
|
|
@ -109,6 +109,8 @@ RendererCanvasRender::PolygonID RendererCanvasRenderRD::request_polygon(const Ve
|
|||
// This dramatically reduces the amount of pipeline objects
|
||||
// that need to be created for these formats.
|
||||
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
uint32_t vertex_count = p_points.size();
|
||||
uint32_t stride = 2; //vertices always repeat
|
||||
if ((uint32_t)p_colors.size() == vertex_count || p_colors.size() == 1) {
|
||||
|
@ -191,7 +193,7 @@ RendererCanvasRender::PolygonID RendererCanvasRenderRD::request_polygon(const Ve
|
|||
vd.stride = 0;
|
||||
|
||||
descriptions.write[1] = vd;
|
||||
buffers.write[1] = storage->mesh_get_default_rd_buffer(RendererStorageRD::DEFAULT_RD_BUFFER_COLOR);
|
||||
buffers.write[1] = mesh_storage->mesh_get_default_rd_buffer(RendererRD::DEFAULT_RD_BUFFER_COLOR);
|
||||
}
|
||||
|
||||
//uvs
|
||||
|
@ -219,7 +221,7 @@ RendererCanvasRender::PolygonID RendererCanvasRenderRD::request_polygon(const Ve
|
|||
vd.stride = 0;
|
||||
|
||||
descriptions.write[2] = vd;
|
||||
buffers.write[2] = storage->mesh_get_default_rd_buffer(RendererStorageRD::DEFAULT_RD_BUFFER_TEX_UV);
|
||||
buffers.write[2] = mesh_storage->mesh_get_default_rd_buffer(RendererRD::DEFAULT_RD_BUFFER_TEX_UV);
|
||||
}
|
||||
|
||||
//bones
|
||||
|
@ -252,7 +254,7 @@ RendererCanvasRender::PolygonID RendererCanvasRenderRD::request_polygon(const Ve
|
|||
vd.stride = 0;
|
||||
|
||||
descriptions.write[3] = vd;
|
||||
buffers.write[3] = storage->mesh_get_default_rd_buffer(RendererStorageRD::DEFAULT_RD_BUFFER_BONES);
|
||||
buffers.write[3] = mesh_storage->mesh_get_default_rd_buffer(RendererRD::DEFAULT_RD_BUFFER_BONES);
|
||||
}
|
||||
|
||||
//weights
|
||||
|
@ -285,7 +287,7 @@ RendererCanvasRender::PolygonID RendererCanvasRenderRD::request_polygon(const Ve
|
|||
vd.stride = 0;
|
||||
|
||||
descriptions.write[4] = vd;
|
||||
buffers.write[4] = storage->mesh_get_default_rd_buffer(RendererStorageRD::DEFAULT_RD_BUFFER_WEIGHTS);
|
||||
buffers.write[4] = mesh_storage->mesh_get_default_rd_buffer(RendererRD::DEFAULT_RD_BUFFER_WEIGHTS);
|
||||
}
|
||||
|
||||
//check that everything is as it should be
|
||||
|
@ -399,6 +401,7 @@ void RendererCanvasRenderRD::_bind_canvas_texture(RD::DrawListID p_draw_list, RI
|
|||
|
||||
void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_render_target, const Item *p_item, RD::FramebufferFormatID p_framebuffer_format, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, Light *p_lights, PipelineVariants *p_pipeline_variants) {
|
||||
//create an empty push constant
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
RS::CanvasItemTextureFilter current_filter = default_filter;
|
||||
RS::CanvasItemTextureRepeat current_repeat = default_repeat;
|
||||
|
@ -753,26 +756,26 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
|
|||
} else if (c->type == Item::Command::TYPE_MULTIMESH) {
|
||||
const Item::CommandMultiMesh *mm = static_cast<const Item::CommandMultiMesh *>(c);
|
||||
RID multimesh = mm->multimesh;
|
||||
mesh = storage->multimesh_get_mesh(multimesh);
|
||||
mesh = mesh_storage->multimesh_get_mesh(multimesh);
|
||||
texture = mm->texture;
|
||||
|
||||
if (storage->multimesh_get_transform_format(multimesh) != RS::MULTIMESH_TRANSFORM_2D) {
|
||||
if (mesh_storage->multimesh_get_transform_format(multimesh) != RS::MULTIMESH_TRANSFORM_2D) {
|
||||
break;
|
||||
}
|
||||
|
||||
instance_count = storage->multimesh_get_instances_to_draw(multimesh);
|
||||
instance_count = mesh_storage->multimesh_get_instances_to_draw(multimesh);
|
||||
|
||||
if (instance_count == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
RID uniform_set = storage->multimesh_get_2d_uniform_set(multimesh, shader.default_version_rd_shader, TRANSFORMS_UNIFORM_SET);
|
||||
RID uniform_set = mesh_storage->multimesh_get_2d_uniform_set(multimesh, shader.default_version_rd_shader, TRANSFORMS_UNIFORM_SET);
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(p_draw_list, uniform_set, TRANSFORMS_UNIFORM_SET);
|
||||
push_constant.flags |= 1; //multimesh, trails disabled
|
||||
if (storage->multimesh_uses_colors(multimesh)) {
|
||||
if (mesh_storage->multimesh_uses_colors(multimesh)) {
|
||||
push_constant.flags |= FLAGS_INSTANCING_HAS_COLORS;
|
||||
}
|
||||
if (storage->multimesh_uses_custom_data(multimesh)) {
|
||||
if (mesh_storage->multimesh_uses_custom_data(multimesh)) {
|
||||
push_constant.flags |= FLAGS_INSTANCING_HAS_CUSTOM_DATA;
|
||||
}
|
||||
} else if (c->type == Item::Command::TYPE_PARTICLES) {
|
||||
|
@ -837,7 +840,7 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
|
|||
|
||||
_bind_canvas_texture(p_draw_list, texture, current_filter, current_repeat, last_texture, push_constant, texpixel_size);
|
||||
|
||||
uint32_t surf_count = storage->mesh_get_surface_count(mesh);
|
||||
uint32_t surf_count = mesh_storage->mesh_get_surface_count(mesh);
|
||||
static const PipelineVariant variant[RS::PRIMITIVE_MAX] = { PIPELINE_VARIANT_ATTRIBUTE_POINTS, PIPELINE_VARIANT_ATTRIBUTE_LINES, PIPELINE_VARIANT_ATTRIBUTE_LINES_STRIP, PIPELINE_VARIANT_ATTRIBUTE_TRIANGLES, PIPELINE_VARIANT_ATTRIBUTE_TRIANGLE_STRIP };
|
||||
|
||||
push_constant.modulation[0] = base_color.r * modulate.r;
|
||||
|
@ -852,9 +855,9 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
|
|||
}
|
||||
|
||||
for (uint32_t j = 0; j < surf_count; j++) {
|
||||
void *surface = storage->mesh_get_surface(mesh, j);
|
||||
void *surface = mesh_storage->mesh_get_surface(mesh, j);
|
||||
|
||||
RS::PrimitiveType primitive = storage->mesh_surface_get_primitive(surface);
|
||||
RS::PrimitiveType primitive = mesh_storage->mesh_surface_get_primitive(surface);
|
||||
ERR_CONTINUE(primitive < 0 || primitive >= RS::PRIMITIVE_MAX);
|
||||
|
||||
uint32_t input_mask = pipeline_variants->variants[light_mode][variant[primitive]].get_vertex_input_mask();
|
||||
|
@ -863,15 +866,15 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
|
|||
RD::VertexFormatID vertex_format = RD::INVALID_FORMAT_ID;
|
||||
|
||||
if (mesh_instance.is_valid()) {
|
||||
storage->mesh_instance_surface_get_vertex_arrays_and_format(mesh_instance, j, input_mask, vertex_array, vertex_format);
|
||||
mesh_storage->mesh_instance_surface_get_vertex_arrays_and_format(mesh_instance, j, input_mask, vertex_array, vertex_format);
|
||||
} else {
|
||||
storage->mesh_surface_get_vertex_arrays_and_format(surface, input_mask, vertex_array, vertex_format);
|
||||
mesh_storage->mesh_surface_get_vertex_arrays_and_format(surface, input_mask, vertex_array, vertex_format);
|
||||
}
|
||||
|
||||
RID pipeline = pipeline_variants->variants[light_mode][variant[primitive]].get_render_pipeline(vertex_format, p_framebuffer_format);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(p_draw_list, pipeline);
|
||||
|
||||
RID index_array = storage->mesh_surface_get_index_array(surface, 0);
|
||||
RID index_array = mesh_storage->mesh_surface_get_index_array(surface, 0);
|
||||
|
||||
if (index_array.is_valid()) {
|
||||
RD::get_singleton()->draw_list_bind_index_array(p_draw_list, index_array);
|
||||
|
@ -1134,6 +1137,7 @@ void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_co
|
|||
|
||||
void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_light_list, const Transform2D &p_canvas_transform, RenderingServer::CanvasItemTextureFilter p_default_filter, RenderingServer::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) {
|
||||
RendererRD::MaterialStorage *material_storage = RendererRD::MaterialStorage::get_singleton();
|
||||
RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton();
|
||||
|
||||
r_sdf_used = false;
|
||||
int item_count = 0;
|
||||
|
@ -1395,7 +1399,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
|
|||
if (c->type == Item::Command::TYPE_MESH) {
|
||||
const Item::CommandMesh *cm = static_cast<const Item::CommandMesh *>(c);
|
||||
if (cm->mesh_instance.is_valid()) {
|
||||
storage->mesh_instance_check_for_update(cm->mesh_instance);
|
||||
mesh_storage->mesh_instance_check_for_update(cm->mesh_instance);
|
||||
update_skeletons = true;
|
||||
}
|
||||
}
|
||||
|
@ -1407,7 +1411,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
|
|||
if (canvas_group_owner == nullptr) {
|
||||
//Canvas group begins here, render until before this item
|
||||
if (update_skeletons) {
|
||||
storage->update_mesh_instances();
|
||||
mesh_storage->update_mesh_instances();
|
||||
update_skeletons = false;
|
||||
}
|
||||
_render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list);
|
||||
|
@ -1430,7 +1434,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
|
|||
|
||||
if (ci == canvas_group_owner) {
|
||||
if (update_skeletons) {
|
||||
storage->update_mesh_instances();
|
||||
mesh_storage->update_mesh_instances();
|
||||
update_skeletons = false;
|
||||
}
|
||||
|
||||
|
@ -1447,7 +1451,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
|
|||
if (backbuffer_copy) {
|
||||
//render anything pending, including clearing if no items
|
||||
if (update_skeletons) {
|
||||
storage->update_mesh_instances();
|
||||
mesh_storage->update_mesh_instances();
|
||||
update_skeletons = false;
|
||||
}
|
||||
_render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list);
|
||||
|
@ -1463,7 +1467,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p
|
|||
|
||||
if (!ci->next || item_count == MAX_RENDER_ITEMS - 1) {
|
||||
if (update_skeletons) {
|
||||
storage->update_mesh_instances();
|
||||
mesh_storage->update_mesh_instances();
|
||||
update_skeletons = false;
|
||||
}
|
||||
|
||||
|
@ -2579,7 +2583,7 @@ RendererCanvasRenderRD::RendererCanvasRenderRD(RendererStorageRD *p_storage) {
|
|||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(storage->get_default_rd_storage_buffer());
|
||||
u.append_id(RendererRD::MeshStorage::get_singleton()->get_default_rd_storage_buffer());
|
||||
uniforms.push_back(u);
|
||||
}
|
||||
|
||||
|
|
|
@ -156,6 +156,7 @@ void RendererCompositorRD::finalize() {
|
|||
memdelete(canvas);
|
||||
memdelete(storage);
|
||||
memdelete(decal_atlas_storage);
|
||||
memdelete(mesh_storage);
|
||||
memdelete(material_storage);
|
||||
memdelete(texture_storage);
|
||||
memdelete(canvas_texture_storage);
|
||||
|
@ -291,6 +292,7 @@ RendererCompositorRD::RendererCompositorRD() {
|
|||
texture_storage = memnew(RendererRD::TextureStorage);
|
||||
decal_atlas_storage = memnew(RendererRD::DecalAtlasStorage);
|
||||
material_storage = memnew(RendererRD::MaterialStorage);
|
||||
mesh_storage = memnew(RendererRD::MeshStorage);
|
||||
storage = memnew(RendererStorageRD);
|
||||
canvas = memnew(RendererCanvasRenderRD(storage));
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "servers/rendering/renderer_rd/storage_rd/canvas_texture_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/decal_atlas_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
|
||||
#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
|
||||
|
||||
|
@ -51,6 +52,7 @@ protected:
|
|||
RendererCanvasRenderRD *canvas;
|
||||
RendererRD::CanvasTextureStorage *canvas_texture_storage;
|
||||
RendererRD::MaterialStorage *material_storage;
|
||||
RendererRD::MeshStorage *mesh_storage;
|
||||
RendererRD::TextureStorage *texture_storage;
|
||||
RendererRD::DecalAtlasStorage *decal_atlas_storage;
|
||||
RendererStorageRD *storage;
|
||||
|
@ -99,6 +101,7 @@ public:
|
|||
RendererCanvasTextureStorage *get_canvas_texture_storage() { return canvas_texture_storage; }
|
||||
RendererDecalAtlasStorage *get_decal_atlas_storage() { return decal_atlas_storage; }
|
||||
RendererMaterialStorage *get_material_storage() { return material_storage; };
|
||||
RendererMeshStorage *get_mesh_storage() { return mesh_storage; };
|
||||
RendererTextureStorage *get_texture_storage() { return texture_storage; };
|
||||
RendererStorage *get_storage() { return storage; }
|
||||
RendererCanvasRender *get_canvas() { return canvas; }
|
||||
|
|
|
@ -5501,7 +5501,7 @@ TypedArray<Image> RendererSceneRenderRD::bake_render_uv2(RID p_base, const Vecto
|
|||
|
||||
GeometryInstance *gi = geometry_instance_create(p_base);
|
||||
|
||||
uint32_t sc = RSG::storage->mesh_get_surface_count(p_base);
|
||||
uint32_t sc = RSG::mesh_storage->mesh_get_surface_count(p_base);
|
||||
Vector<RID> materials;
|
||||
materials.resize(sc);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,12 +39,8 @@
|
|||
#include "servers/rendering/renderer_rd/shaders/canvas_sdf.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/particles.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/particles_copy.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/skeleton.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/voxel_gi_sdf.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/canvas_texture_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/decal_atlas_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
|
||||
#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
#include "servers/rendering/shader_compiler.h"
|
||||
|
@ -129,232 +125,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
enum DefaultRDBuffer {
|
||||
DEFAULT_RD_BUFFER_VERTEX,
|
||||
DEFAULT_RD_BUFFER_NORMAL,
|
||||
DEFAULT_RD_BUFFER_TANGENT,
|
||||
DEFAULT_RD_BUFFER_COLOR,
|
||||
DEFAULT_RD_BUFFER_TEX_UV,
|
||||
DEFAULT_RD_BUFFER_TEX_UV2,
|
||||
DEFAULT_RD_BUFFER_CUSTOM0,
|
||||
DEFAULT_RD_BUFFER_CUSTOM1,
|
||||
DEFAULT_RD_BUFFER_CUSTOM2,
|
||||
DEFAULT_RD_BUFFER_CUSTOM3,
|
||||
DEFAULT_RD_BUFFER_BONES,
|
||||
DEFAULT_RD_BUFFER_WEIGHTS,
|
||||
DEFAULT_RD_BUFFER_MAX,
|
||||
};
|
||||
|
||||
private:
|
||||
/* TEXTURE API */
|
||||
|
||||
RID default_rd_samplers[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
|
||||
RID custom_rd_samplers[RS::CANVAS_ITEM_TEXTURE_FILTER_MAX][RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX];
|
||||
RID default_rd_storage_buffer;
|
||||
|
||||
/* Mesh */
|
||||
|
||||
struct MeshInstance;
|
||||
|
||||
struct Mesh {
|
||||
struct Surface {
|
||||
RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS;
|
||||
uint32_t format = 0;
|
||||
|
||||
RID vertex_buffer;
|
||||
RID attribute_buffer;
|
||||
RID skin_buffer;
|
||||
uint32_t vertex_count = 0;
|
||||
uint32_t vertex_buffer_size = 0;
|
||||
uint32_t skin_buffer_size = 0;
|
||||
|
||||
// A different pipeline needs to be allocated
|
||||
// depending on the inputs available in the
|
||||
// material.
|
||||
// There are never that many geometry/material
|
||||
// combinations, so a simple array is the most
|
||||
// cache-efficient structure.
|
||||
|
||||
struct Version {
|
||||
uint32_t input_mask = 0;
|
||||
RD::VertexFormatID vertex_format = 0;
|
||||
RID vertex_array;
|
||||
};
|
||||
|
||||
SpinLock version_lock; //needed to access versions
|
||||
Version *versions = nullptr; //allocated on demand
|
||||
uint32_t version_count = 0;
|
||||
|
||||
RID index_buffer;
|
||||
RID index_array;
|
||||
uint32_t index_count = 0;
|
||||
|
||||
struct LOD {
|
||||
float edge_length = 0.0;
|
||||
uint32_t index_count = 0;
|
||||
RID index_buffer;
|
||||
RID index_array;
|
||||
};
|
||||
|
||||
LOD *lods = nullptr;
|
||||
uint32_t lod_count = 0;
|
||||
|
||||
AABB aabb;
|
||||
|
||||
Vector<AABB> bone_aabbs;
|
||||
|
||||
RID blend_shape_buffer;
|
||||
|
||||
RID material;
|
||||
|
||||
uint32_t render_index = 0;
|
||||
uint64_t render_pass = 0;
|
||||
|
||||
uint32_t multimesh_render_index = 0;
|
||||
uint64_t multimesh_render_pass = 0;
|
||||
|
||||
uint32_t particles_render_index = 0;
|
||||
uint64_t particles_render_pass = 0;
|
||||
|
||||
RID uniform_set;
|
||||
};
|
||||
|
||||
uint32_t blend_shape_count = 0;
|
||||
RS::BlendShapeMode blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED;
|
||||
|
||||
Surface **surfaces = nullptr;
|
||||
uint32_t surface_count = 0;
|
||||
|
||||
Vector<AABB> bone_aabbs;
|
||||
|
||||
bool has_bone_weights = false;
|
||||
|
||||
AABB aabb;
|
||||
AABB custom_aabb;
|
||||
|
||||
Vector<RID> material_cache;
|
||||
|
||||
List<MeshInstance *> instances;
|
||||
|
||||
RID shadow_mesh;
|
||||
Set<Mesh *> shadow_owners;
|
||||
|
||||
Dependency dependency;
|
||||
};
|
||||
|
||||
mutable RID_Owner<Mesh, true> mesh_owner;
|
||||
|
||||
struct MeshInstance {
|
||||
Mesh *mesh;
|
||||
RID skeleton;
|
||||
struct Surface {
|
||||
RID vertex_buffer;
|
||||
RID uniform_set;
|
||||
|
||||
Mesh::Surface::Version *versions = nullptr; //allocated on demand
|
||||
uint32_t version_count = 0;
|
||||
};
|
||||
LocalVector<Surface> surfaces;
|
||||
LocalVector<float> blend_weights;
|
||||
|
||||
RID blend_weights_buffer;
|
||||
List<MeshInstance *>::Element *I = nullptr; //used to erase itself
|
||||
uint64_t skeleton_version = 0;
|
||||
bool dirty = false;
|
||||
bool weights_dirty = false;
|
||||
SelfList<MeshInstance> weight_update_list;
|
||||
SelfList<MeshInstance> array_update_list;
|
||||
MeshInstance() :
|
||||
weight_update_list(this), array_update_list(this) {}
|
||||
};
|
||||
|
||||
void _mesh_instance_clear(MeshInstance *mi);
|
||||
void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
|
||||
|
||||
mutable RID_Owner<MeshInstance> mesh_instance_owner;
|
||||
|
||||
SelfList<MeshInstance>::List dirty_mesh_instance_weights;
|
||||
SelfList<MeshInstance>::List dirty_mesh_instance_arrays;
|
||||
|
||||
struct SkeletonShader {
|
||||
struct PushConstant {
|
||||
uint32_t has_normal;
|
||||
uint32_t has_tangent;
|
||||
uint32_t has_skeleton;
|
||||
uint32_t has_blend_shape;
|
||||
|
||||
uint32_t vertex_count;
|
||||
uint32_t vertex_stride;
|
||||
uint32_t skin_stride;
|
||||
uint32_t skin_weight_offset;
|
||||
|
||||
uint32_t blend_shape_count;
|
||||
uint32_t normalized_blend_shapes;
|
||||
uint32_t pad0;
|
||||
uint32_t pad1;
|
||||
};
|
||||
|
||||
enum {
|
||||
UNIFORM_SET_INSTANCE = 0,
|
||||
UNIFORM_SET_SURFACE = 1,
|
||||
UNIFORM_SET_SKELETON = 2,
|
||||
};
|
||||
enum {
|
||||
SHADER_MODE_2D,
|
||||
SHADER_MODE_3D,
|
||||
SHADER_MODE_MAX
|
||||
};
|
||||
|
||||
SkeletonShaderRD shader;
|
||||
RID version;
|
||||
RID version_shader[SHADER_MODE_MAX];
|
||||
RID pipeline[SHADER_MODE_MAX];
|
||||
|
||||
RID default_skeleton_uniform_set;
|
||||
} skeleton_shader;
|
||||
|
||||
void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint32_t p_input_mask, MeshInstance::Surface *mis = nullptr);
|
||||
|
||||
RID mesh_default_rd_buffers[DEFAULT_RD_BUFFER_MAX];
|
||||
|
||||
/* MultiMesh */
|
||||
struct MultiMesh {
|
||||
RID mesh;
|
||||
int instances = 0;
|
||||
RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
|
||||
bool uses_colors = false;
|
||||
bool uses_custom_data = false;
|
||||
int visible_instances = -1;
|
||||
AABB aabb;
|
||||
bool aabb_dirty = false;
|
||||
bool buffer_set = false;
|
||||
uint32_t stride_cache = 0;
|
||||
uint32_t color_offset_cache = 0;
|
||||
uint32_t custom_data_offset_cache = 0;
|
||||
|
||||
Vector<float> data_cache; //used if individual setting is used
|
||||
bool *data_cache_dirty_regions = nullptr;
|
||||
uint32_t data_cache_used_dirty_regions = 0;
|
||||
|
||||
RID buffer; //storage buffer
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_2d;
|
||||
|
||||
bool dirty = false;
|
||||
MultiMesh *dirty_list = nullptr;
|
||||
|
||||
Dependency dependency;
|
||||
};
|
||||
|
||||
mutable RID_Owner<MultiMesh, true> multimesh_owner;
|
||||
|
||||
MultiMesh *multimesh_dirty_list = nullptr;
|
||||
|
||||
_FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
|
||||
_FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
|
||||
void _update_dirty_multimeshes();
|
||||
|
||||
/* PARTICLES */
|
||||
|
||||
|
@ -732,34 +507,6 @@ private:
|
|||
|
||||
mutable RID_Owner<VisibilityNotifier> visibility_notifier_owner;
|
||||
|
||||
/* Skeleton */
|
||||
|
||||
struct Skeleton {
|
||||
bool use_2d = false;
|
||||
int size = 0;
|
||||
Vector<float> data;
|
||||
RID buffer;
|
||||
|
||||
bool dirty = false;
|
||||
Skeleton *dirty_list = nullptr;
|
||||
Transform2D base_transform_2d;
|
||||
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_mi;
|
||||
|
||||
uint64_t version = 1;
|
||||
|
||||
Dependency dependency;
|
||||
};
|
||||
|
||||
mutable RID_Owner<Skeleton, true> skeleton_owner;
|
||||
|
||||
_FORCE_INLINE_ void _skeleton_make_dirty(Skeleton *skeleton);
|
||||
|
||||
Skeleton *skeleton_dirty_list = nullptr;
|
||||
|
||||
void _update_dirty_skeletons();
|
||||
|
||||
/* LIGHT */
|
||||
|
||||
struct Light {
|
||||
|
@ -975,360 +722,6 @@ public:
|
|||
|
||||
void sampler_rd_set_default(float p_mipmap_bias);
|
||||
|
||||
/* MESH API */
|
||||
|
||||
RID mesh_allocate();
|
||||
void mesh_initialize(RID p_mesh);
|
||||
|
||||
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count);
|
||||
|
||||
/// Return stride
|
||||
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface);
|
||||
|
||||
virtual int mesh_get_blend_shape_count(RID p_mesh) const;
|
||||
|
||||
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode);
|
||||
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const;
|
||||
|
||||
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
|
||||
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
|
||||
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data);
|
||||
|
||||
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material);
|
||||
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const;
|
||||
|
||||
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const;
|
||||
|
||||
virtual int mesh_get_surface_count(RID p_mesh) const;
|
||||
|
||||
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb);
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const;
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID());
|
||||
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh);
|
||||
|
||||
virtual void mesh_clear(RID p_mesh);
|
||||
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton);
|
||||
|
||||
/* MESH INSTANCE */
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base);
|
||||
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton);
|
||||
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight);
|
||||
virtual void mesh_instance_check_for_update(RID p_mesh_instance);
|
||||
virtual void update_mesh_instances();
|
||||
|
||||
_FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_COND_V(!mesh, nullptr);
|
||||
r_surface_count = mesh->surface_count;
|
||||
if (r_surface_count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (mesh->material_cache.is_empty()) {
|
||||
mesh->material_cache.resize(mesh->surface_count);
|
||||
for (uint32_t i = 0; i < r_surface_count; i++) {
|
||||
mesh->material_cache.write[i] = mesh->surfaces[i]->material;
|
||||
}
|
||||
}
|
||||
|
||||
return mesh->material_cache.ptr();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_COND_V(!mesh, nullptr);
|
||||
ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
|
||||
|
||||
return mesh->surfaces[p_surface_index];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID mesh_get_shadow_mesh(RID p_mesh) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_COND_V(!mesh, RID());
|
||||
|
||||
return mesh->shadow_mesh;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RS::PrimitiveType mesh_surface_get_primitive(void *p_surface) {
|
||||
Mesh::Surface *surface = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
return surface->primitive;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool mesh_surface_has_lod(void *p_surface) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
return s->lod_count > 0;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_vertices_drawn_count(void *p_surface) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
return s->index_count ? s->index_count : s->vertex_count;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_mesh_lod_threshold, uint32_t *r_index_count = nullptr) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
|
||||
int32_t current_lod = -1;
|
||||
if (r_index_count) {
|
||||
*r_index_count = s->index_count;
|
||||
}
|
||||
for (uint32_t i = 0; i < s->lod_count; i++) {
|
||||
float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold;
|
||||
if (screen_size > p_mesh_lod_threshold) {
|
||||
break;
|
||||
}
|
||||
current_lod = i;
|
||||
}
|
||||
if (current_lod == -1) {
|
||||
return 0;
|
||||
} else {
|
||||
if (r_index_count) {
|
||||
*r_index_count = s->lods[current_lod].index_count;
|
||||
}
|
||||
return current_lod + 1;
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID mesh_surface_get_index_array(void *p_surface, uint32_t p_lod) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
|
||||
if (p_lod == 0) {
|
||||
return s->index_array;
|
||||
} else {
|
||||
return s->lods[p_lod - 1].index_array;
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void mesh_surface_get_vertex_arrays_and_format(void *p_surface, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
|
||||
s->version_lock.lock();
|
||||
|
||||
//there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
|
||||
|
||||
for (uint32_t i = 0; i < s->version_count; i++) {
|
||||
if (s->versions[i].input_mask != p_input_mask) {
|
||||
continue;
|
||||
}
|
||||
//we have this version, hooray
|
||||
r_vertex_format = s->versions[i].vertex_format;
|
||||
r_vertex_array_rd = s->versions[i].vertex_array;
|
||||
s->version_lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t version = s->version_count;
|
||||
s->version_count++;
|
||||
s->versions = (Mesh::Surface::Version *)memrealloc(s->versions, sizeof(Mesh::Surface::Version) * s->version_count);
|
||||
|
||||
_mesh_surface_generate_version_for_input_mask(s->versions[version], s, p_input_mask);
|
||||
|
||||
r_vertex_format = s->versions[version].vertex_format;
|
||||
r_vertex_array_rd = s->versions[version].vertex_array;
|
||||
|
||||
s->version_lock.unlock();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void mesh_instance_surface_get_vertex_arrays_and_format(RID p_mesh_instance, uint32_t p_surface_index, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
|
||||
MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
|
||||
ERR_FAIL_COND(!mi);
|
||||
Mesh *mesh = mi->mesh;
|
||||
ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
|
||||
|
||||
MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
s->version_lock.lock();
|
||||
|
||||
//there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
|
||||
|
||||
for (uint32_t i = 0; i < mis->version_count; i++) {
|
||||
if (mis->versions[i].input_mask != p_input_mask) {
|
||||
continue;
|
||||
}
|
||||
//we have this version, hooray
|
||||
r_vertex_format = mis->versions[i].vertex_format;
|
||||
r_vertex_array_rd = mis->versions[i].vertex_array;
|
||||
s->version_lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t version = mis->version_count;
|
||||
mis->version_count++;
|
||||
mis->versions = (Mesh::Surface::Version *)memrealloc(mis->versions, sizeof(Mesh::Surface::Version) * mis->version_count);
|
||||
|
||||
_mesh_surface_generate_version_for_input_mask(mis->versions[version], s, p_input_mask, mis);
|
||||
|
||||
r_vertex_format = mis->versions[version].vertex_format;
|
||||
r_vertex_array_rd = mis->versions[version].vertex_array;
|
||||
|
||||
s->version_lock.unlock();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID mesh_get_default_rd_buffer(DefaultRDBuffer p_buffer) {
|
||||
ERR_FAIL_INDEX_V(p_buffer, DEFAULT_RD_BUFFER_MAX, RID());
|
||||
return mesh_default_rd_buffers[p_buffer];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
if (s->render_pass != p_render_pass) {
|
||||
(*r_index)++;
|
||||
s->render_pass = p_render_pass;
|
||||
s->render_index = *r_index;
|
||||
}
|
||||
|
||||
return s->render_index;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_multimesh_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
if (s->multimesh_render_pass != p_render_pass) {
|
||||
(*r_index)++;
|
||||
s->multimesh_render_pass = p_render_pass;
|
||||
s->multimesh_render_index = *r_index;
|
||||
}
|
||||
|
||||
return s->multimesh_render_index;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_particles_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
if (s->particles_render_pass != p_render_pass) {
|
||||
(*r_index)++;
|
||||
s->particles_render_pass = p_render_pass;
|
||||
s->particles_render_index = *r_index;
|
||||
}
|
||||
|
||||
return s->particles_render_index;
|
||||
}
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
RID multimesh_allocate();
|
||||
void multimesh_initialize(RID p_multimesh);
|
||||
|
||||
void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false);
|
||||
int multimesh_get_instance_count(RID p_multimesh) const;
|
||||
|
||||
void multimesh_set_mesh(RID p_multimesh, RID p_mesh);
|
||||
void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform);
|
||||
void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform);
|
||||
void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color);
|
||||
void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color);
|
||||
|
||||
RID multimesh_get_mesh(RID p_multimesh) const;
|
||||
|
||||
Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const;
|
||||
Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const;
|
||||
Color multimesh_instance_get_color(RID p_multimesh, int p_index) const;
|
||||
Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const;
|
||||
|
||||
void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer);
|
||||
Vector<float> multimesh_get_buffer(RID p_multimesh) const;
|
||||
|
||||
void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
|
||||
int multimesh_get_visible_instances(RID p_multimesh) const;
|
||||
|
||||
AABB multimesh_get_aabb(RID p_multimesh) const;
|
||||
|
||||
_FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->xform_format;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_colors;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_custom_data;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (multimesh->visible_instances >= 0) {
|
||||
return multimesh->visible_instances;
|
||||
}
|
||||
return multimesh->instances;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID multimesh_get_3d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (!multimesh->uniform_set_3d.is_valid()) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(multimesh->buffer);
|
||||
uniforms.push_back(u);
|
||||
multimesh->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
|
||||
}
|
||||
|
||||
return multimesh->uniform_set_3d;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID multimesh_get_2d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (!multimesh->uniform_set_2d.is_valid()) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(multimesh->buffer);
|
||||
uniforms.push_back(u);
|
||||
multimesh->uniform_set_2d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
|
||||
}
|
||||
|
||||
return multimesh->uniform_set_2d;
|
||||
}
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
RID skeleton_allocate();
|
||||
void skeleton_initialize(RID p_skeleton);
|
||||
|
||||
void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false);
|
||||
void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform);
|
||||
void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform3D &p_world_transform);
|
||||
int skeleton_get_bone_count(RID p_skeleton) const;
|
||||
void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform);
|
||||
Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const;
|
||||
void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform);
|
||||
Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const;
|
||||
|
||||
_FORCE_INLINE_ bool skeleton_is_valid(RID p_skeleton) {
|
||||
return skeleton_owner.get_or_null(p_skeleton) != nullptr;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID skeleton_get_3d_uniform_set(RID p_skeleton, RID p_shader, uint32_t p_set) const {
|
||||
Skeleton *skeleton = skeleton_owner.get_or_null(p_skeleton);
|
||||
ERR_FAIL_COND_V(!skeleton, RID());
|
||||
ERR_FAIL_COND_V(skeleton->size == 0, RID());
|
||||
if (skeleton->use_2d) {
|
||||
return RID();
|
||||
}
|
||||
if (!skeleton->uniform_set_3d.is_valid()) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(skeleton->buffer);
|
||||
uniforms.push_back(u);
|
||||
skeleton->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
|
||||
}
|
||||
|
||||
return skeleton->uniform_set_3d;
|
||||
}
|
||||
/* Light API */
|
||||
|
||||
void _light_initialize(RID p_rid, RS::LightType p_type);
|
||||
|
@ -1498,7 +891,6 @@ public:
|
|||
float reflection_probe_get_ambient_color_energy(RID p_probe) const;
|
||||
|
||||
void base_update_dependency(RID p_base, DependencyTracker *p_instance);
|
||||
void skeleton_update_dependency(RID p_skeleton, DependencyTracker *p_instance);
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
||||
|
@ -1829,8 +1221,6 @@ public:
|
|||
virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;
|
||||
virtual String get_captured_timestamp_name(uint32_t p_index) const;
|
||||
|
||||
RID get_default_rd_storage_buffer() { return default_rd_storage_buffer; }
|
||||
|
||||
static RendererStorageRD *base_singleton;
|
||||
|
||||
void init_effects(bool p_prefer_raster_effects);
|
||||
|
|
1921
servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
Normal file
1921
servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
Normal file
File diff suppressed because it is too large
Load diff
694
servers/rendering/renderer_rd/storage_rd/mesh_storage.h
Normal file
694
servers/rendering/renderer_rd/storage_rd/mesh_storage.h
Normal file
|
@ -0,0 +1,694 @@
|
|||
/*************************************************************************/
|
||||
/* mesh_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef MESH_STORAGE_RD_H
|
||||
#define MESH_STORAGE_RD_H
|
||||
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "core/templates/self_list.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/skeleton.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_storage.h"
|
||||
#include "servers/rendering/storage/mesh_storage.h"
|
||||
|
||||
namespace RendererRD {
|
||||
|
||||
/* Mesh */
|
||||
|
||||
enum DefaultRDBuffer {
|
||||
DEFAULT_RD_BUFFER_VERTEX,
|
||||
DEFAULT_RD_BUFFER_NORMAL,
|
||||
DEFAULT_RD_BUFFER_TANGENT,
|
||||
DEFAULT_RD_BUFFER_COLOR,
|
||||
DEFAULT_RD_BUFFER_TEX_UV,
|
||||
DEFAULT_RD_BUFFER_TEX_UV2,
|
||||
DEFAULT_RD_BUFFER_CUSTOM0,
|
||||
DEFAULT_RD_BUFFER_CUSTOM1,
|
||||
DEFAULT_RD_BUFFER_CUSTOM2,
|
||||
DEFAULT_RD_BUFFER_CUSTOM3,
|
||||
DEFAULT_RD_BUFFER_BONES,
|
||||
DEFAULT_RD_BUFFER_WEIGHTS,
|
||||
DEFAULT_RD_BUFFER_MAX,
|
||||
};
|
||||
|
||||
struct MeshInstance;
|
||||
|
||||
struct Mesh {
|
||||
struct Surface {
|
||||
RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS;
|
||||
uint32_t format = 0;
|
||||
|
||||
RID vertex_buffer;
|
||||
RID attribute_buffer;
|
||||
RID skin_buffer;
|
||||
uint32_t vertex_count = 0;
|
||||
uint32_t vertex_buffer_size = 0;
|
||||
uint32_t skin_buffer_size = 0;
|
||||
|
||||
// A different pipeline needs to be allocated
|
||||
// depending on the inputs available in the
|
||||
// material.
|
||||
// There are never that many geometry/material
|
||||
// combinations, so a simple array is the most
|
||||
// cache-efficient structure.
|
||||
|
||||
struct Version {
|
||||
uint32_t input_mask = 0;
|
||||
RD::VertexFormatID vertex_format = 0;
|
||||
RID vertex_array;
|
||||
};
|
||||
|
||||
SpinLock version_lock; //needed to access versions
|
||||
Version *versions = nullptr; //allocated on demand
|
||||
uint32_t version_count = 0;
|
||||
|
||||
RID index_buffer;
|
||||
RID index_array;
|
||||
uint32_t index_count = 0;
|
||||
|
||||
struct LOD {
|
||||
float edge_length = 0.0;
|
||||
uint32_t index_count = 0;
|
||||
RID index_buffer;
|
||||
RID index_array;
|
||||
};
|
||||
|
||||
LOD *lods = nullptr;
|
||||
uint32_t lod_count = 0;
|
||||
|
||||
AABB aabb;
|
||||
|
||||
Vector<AABB> bone_aabbs;
|
||||
|
||||
RID blend_shape_buffer;
|
||||
|
||||
RID material;
|
||||
|
||||
uint32_t render_index = 0;
|
||||
uint64_t render_pass = 0;
|
||||
|
||||
uint32_t multimesh_render_index = 0;
|
||||
uint64_t multimesh_render_pass = 0;
|
||||
|
||||
uint32_t particles_render_index = 0;
|
||||
uint64_t particles_render_pass = 0;
|
||||
|
||||
RID uniform_set;
|
||||
};
|
||||
|
||||
uint32_t blend_shape_count = 0;
|
||||
RS::BlendShapeMode blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED;
|
||||
|
||||
Surface **surfaces = nullptr;
|
||||
uint32_t surface_count = 0;
|
||||
|
||||
Vector<AABB> bone_aabbs;
|
||||
|
||||
bool has_bone_weights = false;
|
||||
|
||||
AABB aabb;
|
||||
AABB custom_aabb;
|
||||
|
||||
Vector<RID> material_cache;
|
||||
|
||||
List<MeshInstance *> instances;
|
||||
|
||||
RID shadow_mesh;
|
||||
Set<Mesh *> shadow_owners;
|
||||
|
||||
RendererStorage::Dependency dependency;
|
||||
};
|
||||
|
||||
/* Mesh Instance */
|
||||
|
||||
struct MeshInstance {
|
||||
Mesh *mesh;
|
||||
RID skeleton;
|
||||
struct Surface {
|
||||
RID vertex_buffer;
|
||||
RID uniform_set;
|
||||
|
||||
Mesh::Surface::Version *versions = nullptr; //allocated on demand
|
||||
uint32_t version_count = 0;
|
||||
};
|
||||
LocalVector<Surface> surfaces;
|
||||
LocalVector<float> blend_weights;
|
||||
|
||||
RID blend_weights_buffer;
|
||||
List<MeshInstance *>::Element *I = nullptr; //used to erase itself
|
||||
uint64_t skeleton_version = 0;
|
||||
bool dirty = false;
|
||||
bool weights_dirty = false;
|
||||
SelfList<MeshInstance> weight_update_list;
|
||||
SelfList<MeshInstance> array_update_list;
|
||||
MeshInstance() :
|
||||
weight_update_list(this), array_update_list(this) {}
|
||||
};
|
||||
|
||||
/* MultiMesh */
|
||||
|
||||
struct MultiMesh {
|
||||
RID mesh;
|
||||
int instances = 0;
|
||||
RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
|
||||
bool uses_colors = false;
|
||||
bool uses_custom_data = false;
|
||||
int visible_instances = -1;
|
||||
AABB aabb;
|
||||
bool aabb_dirty = false;
|
||||
bool buffer_set = false;
|
||||
uint32_t stride_cache = 0;
|
||||
uint32_t color_offset_cache = 0;
|
||||
uint32_t custom_data_offset_cache = 0;
|
||||
|
||||
Vector<float> data_cache; //used if individual setting is used
|
||||
bool *data_cache_dirty_regions = nullptr;
|
||||
uint32_t data_cache_used_dirty_regions = 0;
|
||||
|
||||
RID buffer; //storage buffer
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_2d;
|
||||
|
||||
bool dirty = false;
|
||||
MultiMesh *dirty_list = nullptr;
|
||||
|
||||
RendererStorage::Dependency dependency;
|
||||
};
|
||||
|
||||
/* Skeleton */
|
||||
|
||||
struct SkeletonShader {
|
||||
struct PushConstant {
|
||||
uint32_t has_normal;
|
||||
uint32_t has_tangent;
|
||||
uint32_t has_skeleton;
|
||||
uint32_t has_blend_shape;
|
||||
|
||||
uint32_t vertex_count;
|
||||
uint32_t vertex_stride;
|
||||
uint32_t skin_stride;
|
||||
uint32_t skin_weight_offset;
|
||||
|
||||
uint32_t blend_shape_count;
|
||||
uint32_t normalized_blend_shapes;
|
||||
uint32_t pad0;
|
||||
uint32_t pad1;
|
||||
};
|
||||
|
||||
enum {
|
||||
UNIFORM_SET_INSTANCE = 0,
|
||||
UNIFORM_SET_SURFACE = 1,
|
||||
UNIFORM_SET_SKELETON = 2,
|
||||
};
|
||||
enum {
|
||||
SHADER_MODE_2D,
|
||||
SHADER_MODE_3D,
|
||||
SHADER_MODE_MAX
|
||||
};
|
||||
|
||||
SkeletonShaderRD shader;
|
||||
RID version;
|
||||
RID version_shader[SHADER_MODE_MAX];
|
||||
RID pipeline[SHADER_MODE_MAX];
|
||||
|
||||
RID default_skeleton_uniform_set;
|
||||
};
|
||||
|
||||
struct Skeleton {
|
||||
bool use_2d = false;
|
||||
int size = 0;
|
||||
Vector<float> data;
|
||||
RID buffer;
|
||||
|
||||
bool dirty = false;
|
||||
Skeleton *dirty_list = nullptr;
|
||||
Transform2D base_transform_2d;
|
||||
|
||||
RID uniform_set_3d;
|
||||
RID uniform_set_mi;
|
||||
|
||||
uint64_t version = 1;
|
||||
|
||||
RendererStorage::Dependency dependency;
|
||||
};
|
||||
|
||||
class MeshStorage : public RendererMeshStorage {
|
||||
private:
|
||||
static MeshStorage *singleton;
|
||||
|
||||
RID mesh_default_rd_buffers[DEFAULT_RD_BUFFER_MAX];
|
||||
RID default_rd_storage_buffer;
|
||||
|
||||
/* Mesh */
|
||||
|
||||
mutable RID_Owner<Mesh, true> mesh_owner;
|
||||
|
||||
void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint32_t p_input_mask, MeshInstance::Surface *mis = nullptr);
|
||||
|
||||
/* Mesh Instance API */
|
||||
|
||||
void _mesh_instance_clear(MeshInstance *mi);
|
||||
void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
|
||||
|
||||
mutable RID_Owner<MeshInstance> mesh_instance_owner;
|
||||
|
||||
SelfList<MeshInstance>::List dirty_mesh_instance_weights;
|
||||
SelfList<MeshInstance>::List dirty_mesh_instance_arrays;
|
||||
|
||||
/* MultiMesh */
|
||||
|
||||
mutable RID_Owner<MultiMesh, true> multimesh_owner;
|
||||
|
||||
MultiMesh *multimesh_dirty_list = nullptr;
|
||||
|
||||
_FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
|
||||
_FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
|
||||
_FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
|
||||
|
||||
/* Skeleton */
|
||||
|
||||
SkeletonShader skeleton_shader;
|
||||
|
||||
mutable RID_Owner<Skeleton, true> skeleton_owner;
|
||||
|
||||
_FORCE_INLINE_ void _skeleton_make_dirty(Skeleton *skeleton);
|
||||
|
||||
Skeleton *skeleton_dirty_list = nullptr;
|
||||
|
||||
public:
|
||||
static MeshStorage *get_singleton();
|
||||
|
||||
MeshStorage();
|
||||
virtual ~MeshStorage();
|
||||
|
||||
RID get_default_rd_storage_buffer() { return default_rd_storage_buffer; }
|
||||
|
||||
/* MESH API */
|
||||
|
||||
Mesh *get_mesh(RID p_rid) { return mesh_owner.get_or_null(p_rid); };
|
||||
bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); };
|
||||
|
||||
virtual RID mesh_allocate() override;
|
||||
virtual void mesh_initialize(RID p_mesh) override;
|
||||
virtual void mesh_free(RID p_rid) override;
|
||||
|
||||
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override;
|
||||
|
||||
/// Return stride
|
||||
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override;
|
||||
|
||||
virtual int mesh_get_blend_shape_count(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override;
|
||||
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
|
||||
|
||||
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override;
|
||||
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const override;
|
||||
|
||||
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override;
|
||||
|
||||
virtual int mesh_get_surface_count(RID p_mesh) const override;
|
||||
|
||||
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override;
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const override;
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;
|
||||
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;
|
||||
|
||||
virtual void mesh_clear(RID p_mesh) override;
|
||||
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
|
||||
|
||||
_FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_COND_V(!mesh, nullptr);
|
||||
r_surface_count = mesh->surface_count;
|
||||
if (r_surface_count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (mesh->material_cache.is_empty()) {
|
||||
mesh->material_cache.resize(mesh->surface_count);
|
||||
for (uint32_t i = 0; i < r_surface_count; i++) {
|
||||
mesh->material_cache.write[i] = mesh->surfaces[i]->material;
|
||||
}
|
||||
}
|
||||
|
||||
return mesh->material_cache.ptr();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_COND_V(!mesh, nullptr);
|
||||
ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
|
||||
|
||||
return mesh->surfaces[p_surface_index];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID mesh_get_shadow_mesh(RID p_mesh) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
ERR_FAIL_COND_V(!mesh, RID());
|
||||
|
||||
return mesh->shadow_mesh;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RS::PrimitiveType mesh_surface_get_primitive(void *p_surface) {
|
||||
Mesh::Surface *surface = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
return surface->primitive;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool mesh_surface_has_lod(void *p_surface) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
return s->lod_count > 0;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_vertices_drawn_count(void *p_surface) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
return s->index_count ? s->index_count : s->vertex_count;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_mesh_lod_threshold, uint32_t *r_index_count = nullptr) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
|
||||
int32_t current_lod = -1;
|
||||
if (r_index_count) {
|
||||
*r_index_count = s->index_count;
|
||||
}
|
||||
for (uint32_t i = 0; i < s->lod_count; i++) {
|
||||
float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold;
|
||||
if (screen_size > p_mesh_lod_threshold) {
|
||||
break;
|
||||
}
|
||||
current_lod = i;
|
||||
}
|
||||
if (current_lod == -1) {
|
||||
return 0;
|
||||
} else {
|
||||
if (r_index_count) {
|
||||
*r_index_count = s->lods[current_lod].index_count;
|
||||
}
|
||||
return current_lod + 1;
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID mesh_surface_get_index_array(void *p_surface, uint32_t p_lod) const {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
|
||||
if (p_lod == 0) {
|
||||
return s->index_array;
|
||||
} else {
|
||||
return s->lods[p_lod - 1].index_array;
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void mesh_surface_get_vertex_arrays_and_format(void *p_surface, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
|
||||
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
|
||||
|
||||
s->version_lock.lock();
|
||||
|
||||
//there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
|
||||
|
||||
for (uint32_t i = 0; i < s->version_count; i++) {
|
||||
if (s->versions[i].input_mask != p_input_mask) {
|
||||
continue;
|
||||
}
|
||||
//we have this version, hooray
|
||||
r_vertex_format = s->versions[i].vertex_format;
|
||||
r_vertex_array_rd = s->versions[i].vertex_array;
|
||||
s->version_lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t version = s->version_count;
|
||||
s->version_count++;
|
||||
s->versions = (Mesh::Surface::Version *)memrealloc(s->versions, sizeof(Mesh::Surface::Version) * s->version_count);
|
||||
|
||||
_mesh_surface_generate_version_for_input_mask(s->versions[version], s, p_input_mask);
|
||||
|
||||
r_vertex_format = s->versions[version].vertex_format;
|
||||
r_vertex_array_rd = s->versions[version].vertex_array;
|
||||
|
||||
s->version_lock.unlock();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void mesh_instance_surface_get_vertex_arrays_and_format(RID p_mesh_instance, uint32_t p_surface_index, uint32_t p_input_mask, RID &r_vertex_array_rd, RD::VertexFormatID &r_vertex_format) {
|
||||
MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
|
||||
ERR_FAIL_COND(!mi);
|
||||
Mesh *mesh = mi->mesh;
|
||||
ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
|
||||
|
||||
MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
s->version_lock.lock();
|
||||
|
||||
//there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
|
||||
|
||||
for (uint32_t i = 0; i < mis->version_count; i++) {
|
||||
if (mis->versions[i].input_mask != p_input_mask) {
|
||||
continue;
|
||||
}
|
||||
//we have this version, hooray
|
||||
r_vertex_format = mis->versions[i].vertex_format;
|
||||
r_vertex_array_rd = mis->versions[i].vertex_array;
|
||||
s->version_lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t version = mis->version_count;
|
||||
mis->version_count++;
|
||||
mis->versions = (Mesh::Surface::Version *)memrealloc(mis->versions, sizeof(Mesh::Surface::Version) * mis->version_count);
|
||||
|
||||
_mesh_surface_generate_version_for_input_mask(mis->versions[version], s, p_input_mask, mis);
|
||||
|
||||
r_vertex_format = mis->versions[version].vertex_format;
|
||||
r_vertex_array_rd = mis->versions[version].vertex_array;
|
||||
|
||||
s->version_lock.unlock();
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID mesh_get_default_rd_buffer(DefaultRDBuffer p_buffer) {
|
||||
ERR_FAIL_INDEX_V(p_buffer, DEFAULT_RD_BUFFER_MAX, RID());
|
||||
return mesh_default_rd_buffers[p_buffer];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
if (s->render_pass != p_render_pass) {
|
||||
(*r_index)++;
|
||||
s->render_pass = p_render_pass;
|
||||
s->render_index = *r_index;
|
||||
}
|
||||
|
||||
return s->render_index;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_multimesh_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
if (s->multimesh_render_pass != p_render_pass) {
|
||||
(*r_index)++;
|
||||
s->multimesh_render_pass = p_render_pass;
|
||||
s->multimesh_render_index = *r_index;
|
||||
}
|
||||
|
||||
return s->multimesh_render_index;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t mesh_surface_get_particles_render_pass_index(RID p_mesh, uint32_t p_surface_index, uint64_t p_render_pass, uint32_t *r_index) {
|
||||
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
|
||||
Mesh::Surface *s = mesh->surfaces[p_surface_index];
|
||||
|
||||
if (s->particles_render_pass != p_render_pass) {
|
||||
(*r_index)++;
|
||||
s->particles_render_pass = p_render_pass;
|
||||
s->particles_render_index = *r_index;
|
||||
}
|
||||
|
||||
return s->particles_render_index;
|
||||
}
|
||||
|
||||
/* MESH INSTANCE API */
|
||||
|
||||
MeshInstance *get_mesh_instance(RID p_rid) { return mesh_instance_owner.get_or_null(p_rid); };
|
||||
bool owns_mesh_instance(RID p_rid) { return mesh_instance_owner.owns(p_rid); };
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base) override;
|
||||
virtual void mesh_instance_free(RID p_rid) override;
|
||||
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override;
|
||||
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override;
|
||||
virtual void mesh_instance_check_for_update(RID p_mesh_instance) override;
|
||||
virtual void update_mesh_instances() override;
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
MultiMesh *get_multimesh(RID p_rid) { return multimesh_owner.get_or_null(p_rid); };
|
||||
bool owns_multimesh(RID p_rid) { return multimesh_owner.owns(p_rid); };
|
||||
|
||||
virtual RID multimesh_allocate() override;
|
||||
virtual void multimesh_initialize(RID p_multimesh) override;
|
||||
virtual void multimesh_free(RID p_rid) override;
|
||||
|
||||
virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) override;
|
||||
virtual int multimesh_get_instance_count(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
|
||||
virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
|
||||
virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
|
||||
virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
|
||||
|
||||
virtual RID multimesh_get_mesh(RID p_multimesh) const override;
|
||||
|
||||
virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
|
||||
virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
|
||||
virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
|
||||
virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
|
||||
|
||||
virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
|
||||
virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const override;
|
||||
|
||||
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
|
||||
virtual int multimesh_get_visible_instances(RID p_multimesh) const override;
|
||||
|
||||
virtual AABB multimesh_get_aabb(RID p_multimesh) const override;
|
||||
|
||||
void _update_dirty_multimeshes();
|
||||
|
||||
_FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->xform_format;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_colors;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
return multimesh->uses_custom_data;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (multimesh->visible_instances >= 0) {
|
||||
return multimesh->visible_instances;
|
||||
}
|
||||
return multimesh->instances;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID multimesh_get_3d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (!multimesh->uniform_set_3d.is_valid()) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(multimesh->buffer);
|
||||
uniforms.push_back(u);
|
||||
multimesh->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
|
||||
}
|
||||
|
||||
return multimesh->uniform_set_3d;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID multimesh_get_2d_uniform_set(RID p_multimesh, RID p_shader, uint32_t p_set) const {
|
||||
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
|
||||
if (!multimesh->uniform_set_2d.is_valid()) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(multimesh->buffer);
|
||||
uniforms.push_back(u);
|
||||
multimesh->uniform_set_2d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
|
||||
}
|
||||
|
||||
return multimesh->uniform_set_2d;
|
||||
}
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
Skeleton *get_skeleton(RID p_rid) { return skeleton_owner.get_or_null(p_rid); };
|
||||
bool owns_skeleton(RID p_rid) { return skeleton_owner.owns(p_rid); };
|
||||
|
||||
virtual RID skeleton_allocate() override;
|
||||
virtual void skeleton_initialize(RID p_skeleton) override;
|
||||
virtual void skeleton_free(RID p_rid) override;
|
||||
|
||||
virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override;
|
||||
virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override;
|
||||
void skeleton_set_world_transform(RID p_skeleton, bool p_enable, const Transform3D &p_world_transform);
|
||||
virtual int skeleton_get_bone_count(RID p_skeleton) const override;
|
||||
virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override;
|
||||
virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override;
|
||||
virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override;
|
||||
virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override;
|
||||
|
||||
virtual void skeleton_update_dependency(RID p_skeleton, RendererStorage::DependencyTracker *p_instance) override;
|
||||
|
||||
void _update_dirty_skeletons();
|
||||
|
||||
_FORCE_INLINE_ bool skeleton_is_valid(RID p_skeleton) {
|
||||
return skeleton_owner.get_or_null(p_skeleton) != nullptr;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ RID skeleton_get_3d_uniform_set(RID p_skeleton, RID p_shader, uint32_t p_set) const {
|
||||
Skeleton *skeleton = skeleton_owner.get_or_null(p_skeleton);
|
||||
ERR_FAIL_COND_V(!skeleton, RID());
|
||||
ERR_FAIL_COND_V(skeleton->size == 0, RID());
|
||||
if (skeleton->use_2d) {
|
||||
return RID();
|
||||
}
|
||||
if (!skeleton->uniform_set_3d.is_valid()) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
|
||||
u.binding = 0;
|
||||
u.append_id(skeleton->buffer);
|
||||
uniforms.push_back(u);
|
||||
skeleton->uniform_set_3d = RD::get_singleton()->uniform_set_create(uniforms, p_shader, p_set);
|
||||
}
|
||||
|
||||
return skeleton->uniform_set_3d;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
||||
#endif // !MESH_STORAGE_RD_H
|
|
@ -464,10 +464,10 @@ void RendererSceneCull::instance_initialize(RID p_rid) {
|
|||
}
|
||||
|
||||
void RendererSceneCull::_instance_update_mesh_instance(Instance *p_instance) {
|
||||
bool needs_instance = RSG::storage->mesh_needs_instance(p_instance->base, p_instance->skeleton.is_valid());
|
||||
bool needs_instance = RSG::mesh_storage->mesh_needs_instance(p_instance->base, p_instance->skeleton.is_valid());
|
||||
if (needs_instance != p_instance->mesh_instance.is_valid()) {
|
||||
if (needs_instance) {
|
||||
p_instance->mesh_instance = RSG::storage->mesh_instance_create(p_instance->base);
|
||||
p_instance->mesh_instance = RSG::mesh_storage->mesh_instance_create(p_instance->base);
|
||||
|
||||
} else {
|
||||
RSG::storage->free(p_instance->mesh_instance);
|
||||
|
@ -488,7 +488,7 @@ void RendererSceneCull::_instance_update_mesh_instance(Instance *p_instance) {
|
|||
}
|
||||
|
||||
if (p_instance->mesh_instance.is_valid()) {
|
||||
RSG::storage->mesh_instance_set_skeleton(p_instance->mesh_instance, p_instance->skeleton);
|
||||
RSG::mesh_storage->mesh_instance_set_skeleton(p_instance->mesh_instance, p_instance->skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -890,7 +890,7 @@ void RendererSceneCull::instance_set_blend_shape_weight(RID p_instance, int p_sh
|
|||
}
|
||||
|
||||
if (instance->mesh_instance.is_valid()) {
|
||||
RSG::storage->mesh_instance_set_blend_shape_weight(instance->mesh_instance, p_shape, p_weight);
|
||||
RSG::mesh_storage->mesh_instance_set_blend_shape_weight(instance->mesh_instance, p_shape, p_weight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -900,7 +900,7 @@ void RendererSceneCull::instance_set_surface_override_material(RID p_instance, i
|
|||
|
||||
if (instance->base_type == RS::INSTANCE_MESH) {
|
||||
//may not have been updated yet, may also have not been set yet. When updated will be correcte, worst case
|
||||
instance->materials.resize(MAX(p_surface + 1, RSG::storage->mesh_get_surface_count(instance->base)));
|
||||
instance->materials.resize(MAX(p_surface + 1, RSG::mesh_storage->mesh_get_surface_count(instance->base)));
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX(p_surface, instance->materials.size());
|
||||
|
@ -997,7 +997,7 @@ void RendererSceneCull::instance_attach_skeleton(RID p_instance, RID p_skeleton)
|
|||
|
||||
if (p_skeleton.is_valid()) {
|
||||
//update the dependency now, so if cleared, we remove it
|
||||
RSG::storage->skeleton_update_dependency(p_skeleton, &instance->dependency_tracker);
|
||||
RSG::mesh_storage->skeleton_update_dependency(p_skeleton, &instance->dependency_tracker);
|
||||
}
|
||||
|
||||
_instance_queue_update(instance, true, true);
|
||||
|
@ -1847,7 +1847,7 @@ void RendererSceneCull::_update_instance_aabb(Instance *p_instance) {
|
|||
if (p_instance->custom_aabb) {
|
||||
new_aabb = *p_instance->custom_aabb;
|
||||
} else {
|
||||
new_aabb = RSG::storage->mesh_get_aabb(p_instance->base, p_instance->skeleton);
|
||||
new_aabb = RSG::mesh_storage->mesh_get_aabb(p_instance->base, p_instance->skeleton);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -1856,7 +1856,7 @@ void RendererSceneCull::_update_instance_aabb(Instance *p_instance) {
|
|||
if (p_instance->custom_aabb) {
|
||||
new_aabb = *p_instance->custom_aabb;
|
||||
} else {
|
||||
new_aabb = RSG::storage->multimesh_get_aabb(p_instance->base);
|
||||
new_aabb = RSG::mesh_storage->multimesh_get_aabb(p_instance->base);
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -2271,14 +2271,14 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons
|
|||
}
|
||||
|
||||
if (instance->mesh_instance.is_valid()) {
|
||||
RSG::storage->mesh_instance_check_for_update(instance->mesh_instance);
|
||||
RSG::mesh_storage->mesh_instance_check_for_update(instance->mesh_instance);
|
||||
}
|
||||
}
|
||||
|
||||
shadow_data.instances.push_back(static_cast<InstanceGeometryData *>(instance->base_data)->geometry_instance);
|
||||
}
|
||||
|
||||
RSG::storage->update_mesh_instances();
|
||||
RSG::mesh_storage->update_mesh_instances();
|
||||
|
||||
scene_render->light_instance_set_shadow_transform(light->instance, CameraMatrix(), light_transform, radius, 0, i, 0);
|
||||
shadow_data.light = light->instance;
|
||||
|
@ -2348,14 +2348,14 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons
|
|||
animated_material_found = true;
|
||||
}
|
||||
if (instance->mesh_instance.is_valid()) {
|
||||
RSG::storage->mesh_instance_check_for_update(instance->mesh_instance);
|
||||
RSG::mesh_storage->mesh_instance_check_for_update(instance->mesh_instance);
|
||||
}
|
||||
}
|
||||
|
||||
shadow_data.instances.push_back(static_cast<InstanceGeometryData *>(instance->base_data)->geometry_instance);
|
||||
}
|
||||
|
||||
RSG::storage->update_mesh_instances();
|
||||
RSG::mesh_storage->update_mesh_instances();
|
||||
scene_render->light_instance_set_shadow_transform(light->instance, cm, xform, radius, 0, i, 0);
|
||||
|
||||
shadow_data.light = light->instance;
|
||||
|
@ -2412,13 +2412,13 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons
|
|||
}
|
||||
|
||||
if (instance->mesh_instance.is_valid()) {
|
||||
RSG::storage->mesh_instance_check_for_update(instance->mesh_instance);
|
||||
RSG::mesh_storage->mesh_instance_check_for_update(instance->mesh_instance);
|
||||
}
|
||||
}
|
||||
shadow_data.instances.push_back(static_cast<InstanceGeometryData *>(instance->base_data)->geometry_instance);
|
||||
}
|
||||
|
||||
RSG::storage->update_mesh_instances();
|
||||
RSG::mesh_storage->update_mesh_instances();
|
||||
|
||||
scene_render->light_instance_set_shadow_transform(light->instance, cm, light_transform, radius, 0, 0, 0);
|
||||
shadow_data.light = light->instance;
|
||||
|
@ -3037,9 +3037,9 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c
|
|||
|
||||
if (scene_cull_result.mesh_instances.size()) {
|
||||
for (uint64_t i = 0; i < scene_cull_result.mesh_instances.size(); i++) {
|
||||
RSG::storage->mesh_instance_check_for_update(scene_cull_result.mesh_instances[i]);
|
||||
RSG::mesh_storage->mesh_instance_check_for_update(scene_cull_result.mesh_instances[i]);
|
||||
}
|
||||
RSG::storage->update_mesh_instances();
|
||||
RSG::mesh_storage->update_mesh_instances();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3677,7 +3677,7 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) {
|
|||
if (p_instance->base_type == RS::INSTANCE_MESH) {
|
||||
//remove materials no longer used and un-own them
|
||||
|
||||
int new_mat_count = RSG::storage->mesh_get_surface_count(p_instance->base);
|
||||
int new_mat_count = RSG::mesh_storage->mesh_get_surface_count(p_instance->base);
|
||||
p_instance->materials.resize(new_mat_count);
|
||||
|
||||
_instance_update_mesh_instance(p_instance);
|
||||
|
@ -3717,7 +3717,7 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) {
|
|||
bool cast_shadows = false;
|
||||
|
||||
for (int i = 0; i < p_instance->materials.size(); i++) {
|
||||
RID mat = p_instance->materials[i].is_valid() ? p_instance->materials[i] : RSG::storage->mesh_surface_get_material(mesh, i);
|
||||
RID mat = p_instance->materials[i].is_valid() ? p_instance->materials[i] : RSG::mesh_storage->mesh_surface_get_material(mesh, i);
|
||||
|
||||
if (!mat.is_valid()) {
|
||||
cast_shadows = true;
|
||||
|
@ -3742,13 +3742,13 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) {
|
|||
}
|
||||
|
||||
} else if (p_instance->base_type == RS::INSTANCE_MULTIMESH) {
|
||||
RID mesh = RSG::storage->multimesh_get_mesh(p_instance->base);
|
||||
RID mesh = RSG::mesh_storage->multimesh_get_mesh(p_instance->base);
|
||||
if (mesh.is_valid()) {
|
||||
bool cast_shadows = false;
|
||||
|
||||
int sc = RSG::storage->mesh_get_surface_count(mesh);
|
||||
int sc = RSG::mesh_storage->mesh_get_surface_count(mesh);
|
||||
for (int i = 0; i < sc; i++) {
|
||||
RID mat = RSG::storage->mesh_surface_get_material(mesh, i);
|
||||
RID mat = RSG::mesh_storage->mesh_surface_get_material(mesh, i);
|
||||
|
||||
if (!mat.is_valid()) {
|
||||
cast_shadows = true;
|
||||
|
@ -3784,9 +3784,9 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) {
|
|||
continue;
|
||||
}
|
||||
|
||||
int sc = RSG::storage->mesh_get_surface_count(mesh);
|
||||
int sc = RSG::mesh_storage->mesh_get_surface_count(mesh);
|
||||
for (int j = 0; j < sc; j++) {
|
||||
RID mat = RSG::storage->mesh_surface_get_material(mesh, j);
|
||||
RID mat = RSG::mesh_storage->mesh_surface_get_material(mesh, j);
|
||||
|
||||
if (!mat.is_valid()) {
|
||||
cast_shadows = true;
|
||||
|
@ -3851,7 +3851,7 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) {
|
|||
}
|
||||
|
||||
if (p_instance->skeleton.is_valid()) {
|
||||
RSG::storage->skeleton_update_dependency(p_instance->skeleton, &p_instance->dependency_tracker);
|
||||
RSG::mesh_storage->skeleton_update_dependency(p_instance->skeleton, &p_instance->dependency_tracker);
|
||||
}
|
||||
|
||||
p_instance->dependency_tracker.update_end();
|
||||
|
|
|
@ -119,94 +119,6 @@ public:
|
|||
Set<Dependency *> dependencies;
|
||||
};
|
||||
|
||||
/* MESH API */
|
||||
|
||||
virtual RID mesh_allocate() = 0;
|
||||
virtual void mesh_initialize(RID p_rid) = 0;
|
||||
|
||||
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) = 0;
|
||||
|
||||
/// Returns stride
|
||||
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) = 0;
|
||||
|
||||
virtual int mesh_get_blend_shape_count(RID p_mesh) const = 0;
|
||||
|
||||
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) = 0;
|
||||
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0;
|
||||
|
||||
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0;
|
||||
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0;
|
||||
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0;
|
||||
|
||||
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0;
|
||||
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0;
|
||||
|
||||
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const = 0;
|
||||
|
||||
virtual int mesh_get_surface_count(RID p_mesh) const = 0;
|
||||
|
||||
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) = 0;
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const = 0;
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) = 0;
|
||||
|
||||
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) = 0;
|
||||
|
||||
virtual void mesh_clear(RID p_mesh) = 0;
|
||||
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) = 0;
|
||||
|
||||
/* MESH INSTANCE */
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base) = 0;
|
||||
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) = 0;
|
||||
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) = 0;
|
||||
virtual void mesh_instance_check_for_update(RID p_mesh_instance) = 0;
|
||||
virtual void update_mesh_instances() = 0;
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
virtual RID multimesh_allocate() = 0;
|
||||
virtual void multimesh_initialize(RID p_rid) = 0;
|
||||
|
||||
virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) = 0;
|
||||
|
||||
virtual int multimesh_get_instance_count(RID p_multimesh) const = 0;
|
||||
|
||||
virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) = 0;
|
||||
virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) = 0;
|
||||
virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) = 0;
|
||||
virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) = 0;
|
||||
virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) = 0;
|
||||
|
||||
virtual RID multimesh_get_mesh(RID p_multimesh) const = 0;
|
||||
|
||||
virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const = 0;
|
||||
virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const = 0;
|
||||
virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const = 0;
|
||||
virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const = 0;
|
||||
|
||||
virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) = 0;
|
||||
virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const = 0;
|
||||
|
||||
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0;
|
||||
virtual int multimesh_get_visible_instances(RID p_multimesh) const = 0;
|
||||
|
||||
virtual AABB multimesh_get_aabb(RID p_multimesh) const = 0;
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
virtual RID skeleton_allocate() = 0;
|
||||
virtual void skeleton_initialize(RID p_rid) = 0;
|
||||
|
||||
virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) = 0;
|
||||
virtual int skeleton_get_bone_count(RID p_skeleton) const = 0;
|
||||
virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) = 0;
|
||||
virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const = 0;
|
||||
virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) = 0;
|
||||
virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const = 0;
|
||||
virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) = 0;
|
||||
|
||||
/* Light API */
|
||||
|
||||
virtual RID directional_light_allocate() = 0;
|
||||
|
@ -282,7 +194,6 @@ public:
|
|||
virtual float reflection_probe_get_mesh_lod_threshold(RID p_probe) const = 0;
|
||||
|
||||
virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) = 0;
|
||||
virtual void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) = 0;
|
||||
|
||||
/* VOXEL GI API */
|
||||
|
||||
|
|
|
@ -401,6 +401,7 @@ RenderingServerDefault::RenderingServerDefault(bool p_create_thread) :
|
|||
RSG::canvas_texture_storage = RSG::rasterizer->get_canvas_texture_storage();
|
||||
RSG::decal_atlas_storage = RSG::rasterizer->get_decal_atlas_storage();
|
||||
RSG::material_storage = RSG::rasterizer->get_material_storage();
|
||||
RSG::mesh_storage = RSG::rasterizer->get_mesh_storage();
|
||||
RSG::texture_storage = RSG::rasterizer->get_texture_storage();
|
||||
RSG::storage = RSG::rasterizer->get_storage();
|
||||
RSG::canvas_render = RSG::rasterizer->get_canvas();
|
||||
|
|
|
@ -252,11 +252,11 @@ public:
|
|||
#undef ServerName
|
||||
#undef server_name
|
||||
|
||||
#define ServerName RendererStorage
|
||||
#define server_name RSG::storage
|
||||
#define ServerName RendererMeshStorage
|
||||
#define server_name RSG::mesh_storage
|
||||
|
||||
virtual RID mesh_create_from_surfaces(const Vector<SurfaceData> &p_surfaces, int p_blend_shape_count = 0) override {
|
||||
RID mesh = RSG::storage->mesh_allocate();
|
||||
RID mesh = RSG::mesh_storage->mesh_allocate();
|
||||
|
||||
// TODO once we have RSG::mesh_storage, add can_create_resources_async and call here instead of texture_storage!!
|
||||
|
||||
|
@ -264,16 +264,16 @@ public:
|
|||
if (Thread::get_caller_id() == server_thread) {
|
||||
command_queue.flush_if_pending();
|
||||
}
|
||||
RSG::storage->mesh_initialize(mesh);
|
||||
RSG::storage->mesh_set_blend_shape_count(mesh, p_blend_shape_count);
|
||||
RSG::mesh_storage->mesh_initialize(mesh);
|
||||
RSG::mesh_storage->mesh_set_blend_shape_count(mesh, p_blend_shape_count);
|
||||
for (int i = 0; i < p_surfaces.size(); i++) {
|
||||
RSG::storage->mesh_add_surface(mesh, p_surfaces[i]);
|
||||
RSG::mesh_storage->mesh_add_surface(mesh, p_surfaces[i]);
|
||||
}
|
||||
} else {
|
||||
command_queue.push(RSG::storage, &RendererStorage::mesh_initialize, mesh);
|
||||
command_queue.push(RSG::storage, &RendererStorage::mesh_set_blend_shape_count, mesh, p_blend_shape_count);
|
||||
command_queue.push(RSG::mesh_storage, &RendererMeshStorage::mesh_initialize, mesh);
|
||||
command_queue.push(RSG::mesh_storage, &RendererMeshStorage::mesh_set_blend_shape_count, mesh, p_blend_shape_count);
|
||||
for (int i = 0; i < p_surfaces.size(); i++) {
|
||||
command_queue.push(RSG::storage, &RendererStorage::mesh_add_surface, mesh, p_surfaces[i]);
|
||||
command_queue.push(RSG::mesh_storage, &RendererMeshStorage::mesh_add_surface, mesh, p_surfaces[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,6 +348,11 @@ public:
|
|||
FUNC2(skeleton_set_base_transform_2d, RID, const Transform2D &)
|
||||
|
||||
/* Light API */
|
||||
#undef ServerName
|
||||
#undef server_name
|
||||
|
||||
#define ServerName RendererStorage
|
||||
#define server_name RSG::storage
|
||||
|
||||
FUNCRIDSPLIT(directional_light)
|
||||
FUNCRIDSPLIT(omni_light)
|
||||
|
|
|
@ -35,6 +35,7 @@ bool RenderingServerGlobals::threaded = false;
|
|||
RendererCanvasTextureStorage *RenderingServerGlobals::canvas_texture_storage = nullptr;
|
||||
RendererDecalAtlasStorage *RenderingServerGlobals::decal_atlas_storage = nullptr;
|
||||
RendererMaterialStorage *RenderingServerGlobals::material_storage = nullptr;
|
||||
RendererMeshStorage *RenderingServerGlobals::mesh_storage = nullptr;
|
||||
RendererTextureStorage *RenderingServerGlobals::texture_storage = nullptr;
|
||||
RendererStorage *RenderingServerGlobals::storage = nullptr;
|
||||
RendererCanvasRender *RenderingServerGlobals::canvas_render = nullptr;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "servers/rendering/storage/canvas_texture_storage.h"
|
||||
#include "servers/rendering/storage/decal_atlas_storage.h"
|
||||
#include "servers/rendering/storage/material_storage.h"
|
||||
#include "servers/rendering/storage/mesh_storage.h"
|
||||
#include "servers/rendering/storage/texture_storage.h"
|
||||
|
||||
class RendererCanvasCull;
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
|
||||
static RendererCanvasTextureStorage *canvas_texture_storage;
|
||||
static RendererMaterialStorage *material_storage;
|
||||
static RendererMeshStorage *mesh_storage;
|
||||
static RendererTextureStorage *texture_storage;
|
||||
static RendererDecalAtlasStorage *decal_atlas_storage;
|
||||
static RendererStorage *storage;
|
||||
|
|
136
servers/rendering/storage/mesh_storage.h
Normal file
136
servers/rendering/storage/mesh_storage.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*************************************************************************/
|
||||
/* mesh_storage.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef MESH_STORAGE_H
|
||||
#define MESH_STORAGE_H
|
||||
|
||||
#include "servers/rendering/renderer_storage.h"
|
||||
#include "servers/rendering_server.h"
|
||||
|
||||
class RendererMeshStorage {
|
||||
public:
|
||||
virtual ~RendererMeshStorage() {}
|
||||
|
||||
/* MESH API */
|
||||
|
||||
virtual RID mesh_allocate() = 0;
|
||||
virtual void mesh_initialize(RID p_rid) = 0;
|
||||
virtual void mesh_free(RID p_rid) = 0;
|
||||
|
||||
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) = 0;
|
||||
|
||||
/// Returns stride
|
||||
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) = 0;
|
||||
|
||||
virtual int mesh_get_blend_shape_count(RID p_mesh) const = 0;
|
||||
|
||||
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) = 0;
|
||||
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0;
|
||||
|
||||
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0;
|
||||
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0;
|
||||
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) = 0;
|
||||
|
||||
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0;
|
||||
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0;
|
||||
|
||||
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const = 0;
|
||||
|
||||
virtual int mesh_get_surface_count(RID p_mesh) const = 0;
|
||||
|
||||
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) = 0;
|
||||
virtual AABB mesh_get_custom_aabb(RID p_mesh) const = 0;
|
||||
|
||||
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) = 0;
|
||||
|
||||
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) = 0;
|
||||
|
||||
virtual void mesh_clear(RID p_mesh) = 0;
|
||||
|
||||
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) = 0;
|
||||
|
||||
/* MESH INSTANCE */
|
||||
|
||||
virtual RID mesh_instance_create(RID p_base) = 0;
|
||||
virtual void mesh_instance_free(RID p_rid) = 0;
|
||||
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) = 0;
|
||||
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) = 0;
|
||||
virtual void mesh_instance_check_for_update(RID p_mesh_instance) = 0;
|
||||
virtual void update_mesh_instances() = 0;
|
||||
|
||||
/* MULTIMESH API */
|
||||
|
||||
virtual RID multimesh_allocate() = 0;
|
||||
virtual void multimesh_initialize(RID p_rid) = 0;
|
||||
virtual void multimesh_free(RID p_rid) = 0;
|
||||
|
||||
virtual void multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) = 0;
|
||||
|
||||
virtual int multimesh_get_instance_count(RID p_multimesh) const = 0;
|
||||
|
||||
virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) = 0;
|
||||
virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) = 0;
|
||||
virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) = 0;
|
||||
virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) = 0;
|
||||
virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) = 0;
|
||||
|
||||
virtual RID multimesh_get_mesh(RID p_multimesh) const = 0;
|
||||
|
||||
virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const = 0;
|
||||
virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const = 0;
|
||||
virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const = 0;
|
||||
virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const = 0;
|
||||
|
||||
virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) = 0;
|
||||
virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const = 0;
|
||||
|
||||
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0;
|
||||
virtual int multimesh_get_visible_instances(RID p_multimesh) const = 0;
|
||||
|
||||
virtual AABB multimesh_get_aabb(RID p_multimesh) const = 0;
|
||||
|
||||
/* SKELETON API */
|
||||
|
||||
virtual RID skeleton_allocate() = 0;
|
||||
virtual void skeleton_initialize(RID p_rid) = 0;
|
||||
virtual void skeleton_free(RID p_rid) = 0;
|
||||
|
||||
virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) = 0;
|
||||
virtual int skeleton_get_bone_count(RID p_skeleton) const = 0;
|
||||
virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) = 0;
|
||||
virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const = 0;
|
||||
virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) = 0;
|
||||
virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const = 0;
|
||||
virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) = 0;
|
||||
|
||||
virtual void skeleton_update_dependency(RID p_base, RendererStorage::DependencyTracker *p_instance) = 0;
|
||||
};
|
||||
|
||||
#endif // !MESH_STORAGE_H
|
Loading…
Reference in a new issue