Skip to content

Commit

Permalink
Add missing pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonnyg committed Nov 15, 2023
1 parent f0d554a commit b962297
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 72 deletions.
10 changes: 1 addition & 9 deletions defold-rive/include/common/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ namespace dmRive {

class DefoldBuffer : public rive::RenderBuffer {
public:
/*
SokolBuffer(RenderBufferType type, RenderBufferFlags renderBufferFlags, size_t sizeInBytes) :
RenderBuffer(type, renderBufferFlags, sizeInBytes), m_mappedMemory(new char[sizeInBytes])
*/

DefoldBuffer(rive::RenderBufferType type, rive::RenderBufferFlags renderBufferFlags, size_t sizeInBytes)
: rive::RenderBuffer(type, renderBufferFlags, sizeInBytes)
, m_Data(new char[sizeInBytes])
Expand Down Expand Up @@ -56,11 +51,9 @@ class DefoldBuffer : public rive::RenderBuffer {

void onUnmap() override
{
// ???
}
};

#if 0
class DefoldFactory : public rive::Factory {

public:
Expand Down Expand Up @@ -92,8 +85,7 @@ class DefoldFactory : public rive::Factory {

std::unique_ptr<rive::RenderPaint> makeRenderPaint() override;

std::unique_ptr<rive::RenderImage> decodeImage(rive::Span<const uint8_t> data) override;
rive::rcp<rive::RenderImage> decodeImage(rive::Span<const uint8_t> data) override;
};
#endif
} // namespace rive
#endif
54 changes: 0 additions & 54 deletions defold-rive/include/common/tess_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,6 @@
#define DM_RIVE_TESS_RENDERER_H

#include <rive/math/mat4.hpp>

namespace dmRive
{
struct VsUniforms
{
rive::Mat4 world;
rive::Vec2D gradientStart;
rive::Vec2D gradientEnd;
int fillType;
};

struct FsUniforms
{
int fillType;
float colors[16][4];
float stops[4][4];
int stopCount;
};

enum DrawMode
{
DRAW_MODE_DEFAULT = 0,
DRAW_MODE_CLIP_DECR = 1,
DRAW_MODE_CLIP_INCR = 2,
};

// Must match shader fill type
// Note: The 'texrtured' fill type is a Defold fill type so we can use the same shader for all content
enum FillType
{
FILL_TYPE_SOLID = 0,
FILL_TYPE_LINEAR = 1,
FILL_TYPE_RADIAL = 2,
FILL_TYPE_TEXTURED = 3,
};

struct DrawDescriptor
{
VsUniforms m_VsUniforms;
FsUniforms m_FsUniforms;
rive::BlendMode m_BlendMode;
rive::Vec2D* m_Vertices;
rive::Vec2D* m_TexCoords;
uint16_t* m_Indices;
DrawMode m_DrawMode;
uint32_t m_VerticesCount;
uint32_t m_IndicesCount;
uint32_t m_TexCoordsCount;
uint8_t m_ClipIndex;
};
}

#if 0
#include <rive/renderer.hpp>
#include <rive/tess/tess_render_path.hpp>
#include <rive/tess/tess_renderer.hpp>
Expand Down Expand Up @@ -236,6 +183,5 @@ class DefoldTessRenderer : public rive::TessRenderer {
};

} // namespace dmRive
#endif

#endif
44 changes: 44 additions & 0 deletions defold-rive/include/rive/rive_counter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2022 Rive
*/

#ifndef _RIVE_COUNTER_HPP_
#define _RIVE_COUNTER_HPP_

#include "rive/rive_types.hpp"

namespace rive
{

struct Counter
{
enum Type
{
kFile,
kArtboardInstance,
kLinearAnimationInstance,
kStateMachineInstance,

kBuffer,
kPath,
kPaint,
kShader,
kImage,

kLastType = kImage,
};

static constexpr int kNumTypes = Type::kLastType + 1;
static int counts[kNumTypes];

static void update(Type ct, int delta)
{
assert(delta == 1 || delta == -1);
counts[ct] += delta;
assert(counts[ct] >= 0);
}
};

} // namespace rive

#endif
2 changes: 1 addition & 1 deletion defold-rive/pluginsrc/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ __declspec(dllexport) int dummyFunc()
// Rive includes
#include <rive/artboard.hpp>
#include <rive/file.hpp>
#include <rive/file_asset_resolver.hpp>
#include <rive/file_asset_loader.hpp>
// Due to an X11.h issue (Likely Ubuntu 16.04 issue) we include the Rive/C++17 includes first

//#include <dmsdk/sdk.h>
Expand Down
4 changes: 2 additions & 2 deletions defold-rive/pluginsrc/rive_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RiveFile* LoadFileFromBuffer(const void* buffer, size_t buffer_size, const char*
dmRive::DefoldFactory* factory = new dmRive::DefoldFactory();

// Creates DefoldRenderImage with a hashed name for each image resource
dmRive::AtlasNameResolver atlas_resolver = dmRive::AtlasNameResolver();
dmRive::AtlasNameResolver atlas_resolver = dmRive::AtlasNameResolver(nullptr);

rive::Span<uint8_t> data((uint8_t*)buffer, buffer_size);

Expand Down Expand Up @@ -113,7 +113,7 @@ void PlayAnimation(RiveFile* rive_file, int index)
rive_file->m_AnimationInstance = rive_file->m_ArtboardInstance->animationAt(index);
rive_file->m_AnimationInstance->inputCount();

rive_file->m_AnimationInstance->time(rive_file->m_AnimationInstance->startSeconds());
rive_file->m_AnimationInstance->time(rive_file->m_AnimationInstance->animation()->startSeconds());
rive_file->m_AnimationInstance->loopValue((int)rive::Loop::loop);
rive_file->m_AnimationInstance->direction(1);
}
Expand Down
12 changes: 12 additions & 0 deletions defold-rive/pluginsrc/rive_renderer_null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#include <rive/refcnt.hpp>

#include <renderer.h>

namespace dmRive
{
rive::rcp<rive::RenderImage> CreateRiveRenderImage(HRenderContext context, void* bytes, uint32_t byte_count)
{
return nullptr;
}
}
7 changes: 1 addition & 6 deletions defold-rive/src/comp_rive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ namespace dmRive
uint32_t width, height;
GetDimensions(world->m_RiveRenderContext, &width, &height);

// rive::Mat2D viewTransform = GetViewTransform(world->m_RiveRenderContext, render_context);
rive::Mat2D viewTransform = GetViewTransform(world->m_RiveRenderContext, render_context);
rive::Renderer* renderer = GetRiveRenderer(world->m_RiveRenderContext);

for (uint32_t *i=begin;i!=end;i++)
Expand All @@ -375,11 +375,6 @@ namespace dmRive

rive::AABB bounds = c->m_ArtboardInstance->bounds();

rive::Mat2D viewTransform = rive::computeAlignment(rive::Fit::contain,
rive::Alignment::center,
rive::AABB(0, 0, bounds.maxX-bounds.minX, bounds.maxY-bounds.minY),
bounds);

renderer->save();

// Rive is using a different coordinate system that defold,
Expand Down

0 comments on commit b962297

Please sign in to comment.