Skip to content

Commit

Permalink
Added Width and Height of the resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemirtingas committed Oct 12, 2024
1 parent 821239e commit ae0057f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
14 changes: 11 additions & 3 deletions include/InGameOverlay/RendererResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class RendererResource_t
/// <summary>
/// Deletes the resource.
/// </summary>
/// <param name="unload">If for some reason this resource is still alive and you have deleted the renderer hook, set unload to false so you don't use the deleted renderer hook.</param>
virtual void Delete(bool unload = true) = 0;

virtual void Delete() = 0;
/// <summary>
/// Checks if the resource is loaded.
/// </summary>
Expand Down Expand Up @@ -81,6 +79,16 @@ class RendererResource_t
/// <returns>The ImGui's image handle</returns>
virtual uint64_t GetResourceId() = 0;
/// <summary>
/// Return the loaded or attached resource width.
/// </summary>
/// <returns></returns>
virtual uint32_t Width() const = 0;
/// <summary>
/// Return the loaded or attached resource height.
/// </summary>
/// <returns></returns>
virtual uint32_t Height() const = 0;
/// <summary>
/// Attach a resource to this RendererResource, it will NOT OWN the data.
/// You are responsible to not outlive this object usage to the resource buffer.
/// </summary>
Expand Down
27 changes: 21 additions & 6 deletions src/RendererResourceInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ bool RendererResourceInternal_t::_DoAutoLoad()
return !_RendererResource.expired();
}

void RendererResourceInternal_t::Delete(bool unload)
void RendererResourceInternal_t::Delete()
{
if (!unload)
_RendererResource.reset();

delete this;
}

Expand Down Expand Up @@ -105,6 +102,10 @@ bool RendererResourceInternal_t::Load(const void* data, uint32_t width, uint32_t
if (IsLoaded())
Unload(true);

_Data = nullptr;
_Width = width;
_Height = height;
_AttachementChanged = false;
_RendererResource = _RendererHook->CreateImageResource(data, width, height);
return !_RendererResource.expired();
}
Expand All @@ -121,6 +122,16 @@ uint64_t RendererResourceInternal_t::GetResourceId()
return r != nullptr ? *r : 0;
}

uint32_t RendererResourceInternal_t::Width() const
{
return _Width;
}

uint32_t RendererResourceInternal_t::Height() const
{
return _Height;
}

void RendererResourceInternal_t::AttachResource(const void* data, uint32_t width, uint32_t height)
{
_AttachementChanged = true;
Expand All @@ -133,8 +144,12 @@ void RendererResourceInternal_t::ClearAttachedResource()
{
_AttachementChanged = true;
_Data = nullptr;
_Width = 0;
_Height = 0;

if (_RendererResource.expired())
{
_Width = 0;
_Height = 0;
}
}

void RendererResourceInternal_t::Unload(bool clearAttachedResource)
Expand Down
6 changes: 5 additions & 1 deletion src/RendererResourceInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RendererResourceInternal_t : public RendererResource_t

virtual ~RendererResourceInternal_t();

virtual void Delete(bool unload = true);
virtual void Delete();

virtual bool IsLoaded() const;

Expand All @@ -68,6 +68,10 @@ class RendererResourceInternal_t : public RendererResource_t

virtual uint64_t GetResourceId();

virtual uint32_t Width() const;

virtual uint32_t Height() const;

virtual void AttachResource(const void* data, uint32_t width, uint32_t height);

virtual void ClearAttachedResource();
Expand Down

0 comments on commit ae0057f

Please sign in to comment.