Skip to content

Commit

Permalink
+ Added new overload RendererInfoType::ref_resource(RendererHandle, R…
Browse files Browse the repository at this point in the history
…esourceHandle)
  • Loading branch information
harrand committed Oct 29, 2022
1 parent 5bd31f0 commit a7f8fa5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/tz/gl/api/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ namespace tz::gl
{
struct RendererTag{};
}

/**
* @ingroup tz_gl2_renderer
* Represents a handle for a renderer owned by an existing device.
*/
using RendererHandle = tz::Handle<detail::RendererTag>;

/**
* @ingroup tz_gl2_renderer
* Specifies options to enable extra functionality within Renderers.
Expand Down Expand Up @@ -48,14 +55,15 @@ namespace tz::gl
using RendererOptions = tz::EnumField<RendererOption>;

template<typename T>
concept RendererInfoType = requires(T t, ResourceHandle r, const IResource& resource, IComponent* component, IOutput& output, RendererOptions options, tz::Vec4 vec4, tz::Vec3ui vec3ui, std::string str)
concept RendererInfoType = requires(T t, RendererHandle ren, ResourceHandle r, const IResource& resource, IComponent* component, IOutput& output, RendererOptions options, tz::Vec4 vec4, tz::Vec3ui vec3ui, std::string str)
{
{t.resource_count()} -> std::convertible_to<unsigned int>;
{t.get_resource(r)} -> std::convertible_to<const IResource*>;
{t.get_resources()} -> std::same_as<std::vector<const IResource*>>;

{t.add_resource(resource)} -> std::same_as<ResourceHandle>;
{t.ref_resource(component)} -> std::same_as<ResourceHandle>;
{t.ref_resource(ren, r)} -> std::same_as<ResourceHandle>;
{t.set_output(output)} -> std::same_as<void>;
{t.get_output()} -> std::convertible_to<const IOutput*>;

Expand Down Expand Up @@ -140,12 +148,6 @@ namespace tz::gl
*/
using RendererEditRequest = std::vector<RendererEdit::Variant>;

/**
* @ingroup tz_gl2_renderer
* Represents a handle for a renderer owned by an existing device.
*/
using RendererHandle = tz::Handle<detail::RendererTag>;

/**
* @ingroup tz_gl2_renderer
* Named requirement for a Renderer.
Expand Down
6 changes: 6 additions & 0 deletions src/tz/gl/impl/frontend/common/renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "tz/gl/impl/frontend/common/renderer.hpp"
#include "tz/gl/device.hpp"

namespace tz::gl
{
Expand Down Expand Up @@ -93,6 +94,11 @@ namespace tz::gl
return static_cast<tz::HandleValue>(this->real_resource_count() - 1);
}

ResourceHandle RendererInfoCommon::ref_resource(RendererHandle ren, ResourceHandle res)
{
return this->ref_resource(tz::gl::device().get_renderer(ren).get_component(res));
}

void RendererInfoCommon::set_output(const IOutput& output)
{
this->output = output.unique_clone();
Expand Down
1 change: 1 addition & 0 deletions src/tz/gl/impl/frontend/common/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace tz::gl
*/
ResourceHandle add_resource(const IResource& resource);
ResourceHandle ref_resource(IComponent* component);
ResourceHandle ref_resource(RendererHandle ren, ResourceHandle res);
/**
* Renderers always render into something. By default, it renders to the window (only one window is supported so no confusion there). You can however set it to render into something else, such as a @ref TextureOutput if you want to render into the resource of another Renderer.
*/
Expand Down
4 changes: 2 additions & 2 deletions test/gl/tz_renderer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TESTFUNC_BEGIN(renderer_resource_reference_buffer)
tz::gl::RendererInfo rinfo2;
rinfo2.shader().set_shader(tz::gl::ShaderStage::Vertex, ImportedShaderSource(empty, vertex));
rinfo2.shader().set_shader(tz::gl::ShaderStage::Fragment, ImportedShaderSource(empty, fragment));
tz::gl::ResourceHandle r2bh = rinfo2.ref_resource(tz::gl::device().get_renderer(r1h).get_component(r1bh));
tz::gl::ResourceHandle r2bh = rinfo2.ref_resource(r1h, r1bh);

tz::gl::RendererHandle r2h = tz::gl::device().create_renderer(rinfo2);

Expand Down Expand Up @@ -104,7 +104,7 @@ TESTFUNC_BEGIN(renderer_resource_reference_image)
tz::gl::RendererInfo rinfo2;
rinfo2.shader().set_shader(tz::gl::ShaderStage::Vertex, ImportedShaderSource(empty, vertex));
rinfo2.shader().set_shader(tz::gl::ShaderStage::Fragment, ImportedShaderSource(empty, fragment));
tz::gl::ResourceHandle r2ih = rinfo2.ref_resource(tz::gl::device().get_renderer(r1h).get_component(r1ih));
tz::gl::ResourceHandle r2ih = rinfo2.ref_resource(r1h, r1ih);

tz::gl::RendererHandle r2h = tz::gl::device().create_renderer(rinfo2);

Expand Down

0 comments on commit a7f8fa5

Please sign in to comment.