Skip to content

Commit

Permalink
[SUTK] Added setActive for SGE Render Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi688 committed Aug 15, 2024
1 parent 9edd2af commit b16549f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions sutk/include/sutk/IGfxDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace SUTK
virtual GfxDriverObjectHandleType getTextObject(GfxDriverObjectHandleType handle) = 0;

virtual GfxDriverObjectHandleType getObject(GfxDriverObjectHandleType handle) = 0;
virtual void setObjectActive(GfxDriverObjectHandleType handle, bool isActive) = 0;
// rect should be in centimeters
virtual void setObjectScissor(GfxDriverObjectHandleType handle, const Rect2Df rect) = 0;
// position should be centimeters
Expand Down
9 changes: 6 additions & 3 deletions sutk/include/sutk/RenderRect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace SUTK
private:
Rect2Df m_rect;
Color4 m_color;
bool m_isActiveDirty;

protected:
void setRect(const Rect2Df& rect) noexcept { m_rect = rect; }
Expand All @@ -20,11 +21,13 @@ namespace SUTK

public:
// Constructors
RenderRect(UIDriver& driver, RenderableContainer* container) noexcept : GeometryRenderable(driver, container), m_rect { 0, 0, 2.0f, 2.0f }, m_color(Color4::white()) { }
RenderRect(UIDriver& driver, RenderableContainer* container) noexcept : GeometryRenderable(driver, container), m_rect { 0, 0, 2.0f, 2.0f }, m_color(Color4::white()), m_isActiveDirty(false) { }

// Implementation of Renderable
virtual bool isDirty() = 0;
virtual void update() = 0;
virtual bool isDirty();
virtual void update();

virtual void setActive(bool isActive) noexcept override;

virtual Color4 getColor() const noexcept override { return m_color; }
// it must be called in the overriding method
Expand Down
5 changes: 5 additions & 0 deletions sutk/include/sutk/Renderable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace SUTK
{
private:
RenderableContainer* m_container;
bool m_isActive;

protected:
friend class RenderableContainer;
Expand All @@ -35,6 +36,10 @@ namespace SUTK
// updates (copies CPU side data to) GPU side data, and it may also create or recreate exisiting GPU Driver objects
virtual void update() = 0;

// mandatory to be called in overriding method
virtual void setActive(bool isActive) noexcept { m_isActive = isActive; }
virtual bool isActive() const noexcept { return m_isActive; }

bool ensureUpdated() noexcept
{
if(isDirty())
Expand Down
1 change: 1 addition & 0 deletions sutk/include/sutk/SGEGfxDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace SUTK

virtual GfxDriverObjectHandleType getTextObject(GfxDriverObjectHandleType handle) override;
virtual GfxDriverObjectHandleType getObject(GfxDriverObjectHandleType handle) override;
virtual void setObjectActive(GfxDriverObjectHandleType handle, bool isActive) override;
virtual void setObjectScissor(GfxDriverObjectHandleType handle, const Rect2Df rect) override;
virtual void setObjectPosition(GfxDriverObjectHandleType handle, const Vec2Df position) override;

Expand Down
31 changes: 29 additions & 2 deletions sutk/source/RenderRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@

namespace SUTK
{

void RenderRect::setActive(bool isActive) noexcept
{
// mandatory to call
GeometryRenderable::setActive(isActive);
m_isActiveDirty = true;
}

bool RenderRect::isDirty()
{
return m_isActiveDirty;
}

void RenderRect::update()
{
if(m_isActiveDirty)
{
auto handle = getGfxDriverObjectHandle();
_com_assert(handle != GFX_DRIVER_OBJECT_NULL_HANDLE);
auto obj = getGfxDriver().getGeometryObject(handle);
getGfxDriver().setObjectActive(obj, isActive());
m_isActiveDirty = false;
}
}

RenderRectOutline::RenderRectOutline(UIDriver& driver, RenderableContainer* container) noexcept : RenderRect(driver, container),
m_isPosDirty(true),
m_isSizeDirty(true),
Expand All @@ -32,11 +57,12 @@ namespace SUTK

bool RenderRectOutline::isDirty()
{
return m_isPosDirty || m_isSizeDirty || m_isColorDirty;
return m_isPosDirty || m_isSizeDirty || m_isColorDirty || RenderRect::isDirty();
}

void RenderRectOutline::update()
{
RenderRect::update();
if(m_isSizeDirty || m_isPosDirty)
{
Geometry::VertexPositionArray& array = getGeometry().getVertexPositionArrayForWrite();
Expand Down Expand Up @@ -147,11 +173,12 @@ namespace SUTK

bool RenderRectFill::isDirty()
{
return m_isPosDirty || m_isSizeDirty || m_isColorDirty;
return m_isPosDirty || m_isSizeDirty || m_isColorDirty || RenderRect::isDirty();
}

void RenderRectFill::update()
{
RenderRect::update();
if(m_isSizeDirty || m_isPosDirty)
{
Geometry::VertexPositionArray& array = getGeometry().getVertexPositionArrayForWrite();
Expand Down
6 changes: 6 additions & 0 deletions sutk/source/SGEGfxDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ namespace SUTK
return GFX_DRIVER_OBJECT_NULL_HANDLE;
}

void SGEGfxDriver::setObjectActive(GfxDriverObjectHandleType handle, bool isActive)
{
auto it = getRenderObjectIterator(handle);
it->second.setActive(isActive);
}

void SGEGfxDriver::setObjectScissor(GfxDriverObjectHandleType handle, const Rect2Df rect)
{
auto it = getRenderObjectIterator(handle);
Expand Down

0 comments on commit b16549f

Please sign in to comment.