Skip to content

Commit

Permalink
Merge pull request #65068 from BastiaanOlij/fix_dummy_mesh_allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Aug 30, 2022
2 parents 94b3a50 + 9efff34 commit c1b178b
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 13 deletions.
57 changes: 55 additions & 2 deletions servers/rendering/dummy/rasterizer_scene_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,65 @@
#ifndef RASTERIZER_SCENE_DUMMY_H
#define RASTERIZER_SCENE_DUMMY_H

#include "core/templates/paged_allocator.h"
#include "servers/rendering/renderer_scene_render.h"
#include "storage/utilities.h"

class RasterizerSceneDummy : public RendererSceneRender {
public:
RenderGeometryInstance *geometry_instance_create(RID p_base) override { return nullptr; }
void geometry_instance_free(RenderGeometryInstance *p_geometry_instance) override {}
class GeometryInstanceDummy : public RenderGeometryInstance {
public:
GeometryInstanceDummy() {}

virtual void _mark_dirty() override {}

virtual void set_skeleton(RID p_skeleton) override {}
virtual void set_material_override(RID p_override) override {}
virtual void set_material_overlay(RID p_overlay) override {}
virtual void set_surface_materials(const Vector<RID> &p_materials) override {}
virtual void set_mesh_instance(RID p_mesh_instance) override {}
virtual void set_transform(const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) override {}
virtual void set_lod_bias(float p_lod_bias) override {}
virtual void set_layer_mask(uint32_t p_layer_mask) override {}
virtual void set_fade_range(bool p_enable_near, float p_near_begin, float p_near_end, bool p_enable_far, float p_far_begin, float p_far_end) override {}
virtual void set_parent_fade_alpha(float p_alpha) override {}
virtual void set_transparency(float p_transparency) override {}
virtual void set_use_baked_light(bool p_enable) override {}
virtual void set_use_dynamic_gi(bool p_enable) override {}
virtual void set_use_lightmap(RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override {}
virtual void set_lightmap_capture(const Color *p_sh9) override {}
virtual void set_instance_shader_uniforms_offset(int32_t p_offset) override {}
virtual void set_cast_double_sided_shadows(bool p_enable) override {}

virtual Transform3D get_transform() override { return Transform3D(); }
virtual AABB get_aabb() override { return AABB(); }

virtual void pair_light_instances(const RID *p_light_instances, uint32_t p_light_instance_count) override {}
virtual void pair_reflection_probe_instances(const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override {}
virtual void pair_decal_instances(const RID *p_decal_instances, uint32_t p_decal_instance_count) override {}
virtual void pair_voxel_gi_instances(const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) override {}

virtual void set_softshadow_projector_pairing(bool p_softshadow, bool p_projector) override {}
};

PagedAllocator<GeometryInstanceDummy> geometry_instance_alloc;

public:
RenderGeometryInstance *geometry_instance_create(RID p_base) override {
RS::InstanceType type = RendererDummy::Utilities::get_singleton()->get_base_type(p_base);
ERR_FAIL_COND_V(!((1 << type) & RS::INSTANCE_GEOMETRY_MASK), nullptr);

GeometryInstanceDummy *ginstance = geometry_instance_alloc.alloc();

return ginstance;
}

void geometry_instance_free(RenderGeometryInstance *p_geometry_instance) override {
GeometryInstanceDummy *ginstance = static_cast<GeometryInstanceDummy *>(p_geometry_instance);
ERR_FAIL_COND(!ginstance);

geometry_instance_alloc.free(ginstance);
}

uint32_t geometry_instance_get_pair_mask() override { return 0; }

Expand Down
58 changes: 58 additions & 0 deletions servers/rendering/dummy/storage/mesh_storage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*************************************************************************/
/* 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. */
/*************************************************************************/

#include "mesh_storage.h"

using namespace RendererDummy;

MeshStorage *MeshStorage::singleton = nullptr;

MeshStorage::MeshStorage() {
singleton = this;
}

MeshStorage::~MeshStorage() {
singleton = nullptr;
}

RID MeshStorage::mesh_allocate() {
return mesh_owner.allocate_rid();
}

void MeshStorage::mesh_initialize(RID p_rid) {
mesh_owner.initialize_rid(p_rid, DummyMesh());
}

void MeshStorage::mesh_free(RID p_rid) {
DummyMesh *mesh = mesh_owner.get_or_null(p_rid);
ERR_FAIL_COND(!mesh);

mesh_owner.free(p_rid);
}
25 changes: 16 additions & 9 deletions servers/rendering/dummy/storage/mesh_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
#ifndef MESH_STORAGE_DUMMY_H
#define MESH_STORAGE_DUMMY_H

#include "core/templates/local_vector.h"
#include "core/templates/rid_owner.h"
#include "servers/rendering/storage/mesh_storage.h"
#include "servers/rendering/storage/utilities.h"

namespace RendererDummy {

class MeshStorage : public RendererMeshStorage {
private:
struct DummyMesh : public RID {
static MeshStorage *singleton;

struct DummyMesh {
Vector<RS::SurfaceData> surfaces;
int blend_shape_count;
RS::BlendShapeMode blend_shape_mode;
Expand All @@ -48,16 +51,20 @@ class MeshStorage : public RendererMeshStorage {
mutable RID_Owner<DummyMesh> mesh_owner;

public:
static MeshStorage *get_singleton() {
return singleton;
};

MeshStorage();
~MeshStorage();

/* MESH API */

virtual RID mesh_allocate() override {
return mesh_owner.allocate_rid();
}
bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); };

virtual void mesh_initialize(RID p_rid) override {
mesh_owner.initialize_rid(p_rid, DummyMesh());
}
virtual void mesh_free(RID p_rid) override {}
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 { return false; }
Expand Down
1 change: 0 additions & 1 deletion servers/rendering/dummy/storage/texture_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class TextureStorage : public RendererTextureStorage {

/* Texture API */

DummyTexture *get_texture(RID p_rid) { return texture_owner.get_or_null(p_rid); };
bool owns_texture(RID p_rid) { return texture_owner.owns(p_rid); };

virtual RID texture_allocate() override {
Expand Down
43 changes: 43 additions & 0 deletions servers/rendering/dummy/storage/utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*************************************************************************/
/* utilities.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. */
/*************************************************************************/

#include "utilities.h"

using namespace RendererDummy;

Utilities *Utilities::singleton = nullptr;

Utilities::Utilities() {
singleton = this;
}

Utilities::~Utilities() {
singleton = nullptr;
}
20 changes: 19 additions & 1 deletion servers/rendering/dummy/storage/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,38 @@
#ifndef UTILITIES_DUMMY_H
#define UTILITIES_DUMMY_H

#include "mesh_storage.h"
#include "servers/rendering/storage/utilities.h"
#include "texture_storage.h"

namespace RendererDummy {

class Utilities : public RendererUtilities {
private:
static Utilities *singleton;

public:
static Utilities *get_singleton() { return singleton; }

Utilities();
~Utilities();

/* INSTANCES */

virtual RS::InstanceType get_base_type(RID p_rid) const override { return RS::INSTANCE_NONE; }
virtual RS::InstanceType get_base_type(RID p_rid) const override {
if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
return RS::INSTANCE_MESH;
}
return RS::INSTANCE_NONE;
}

virtual bool free(RID p_rid) override {
if (RendererDummy::TextureStorage::get_singleton()->owns_texture(p_rid)) {
RendererDummy::TextureStorage::get_singleton()->texture_free(p_rid);
return true;
} else if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
RendererDummy::MeshStorage::get_singleton()->mesh_free(p_rid);
return true;
}
return false;
}
Expand Down
Loading

0 comments on commit c1b178b

Please sign in to comment.