mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
Merge "gl_engine: gl infrastructure interfaces" into tizen
This commit is contained in:
commit
e2c6f4523c
11 changed files with 310 additions and 8 deletions
|
@ -240,6 +240,7 @@ public:
|
|||
|
||||
//TODO: Gl Specific methods. Need gl backend configuration methods as well.
|
||||
|
||||
int target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept;
|
||||
int sync() noexcept override;
|
||||
static std::unique_ptr<GlCanvas> gen() noexcept;
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
source_file = [
|
||||
'tvgGlRenderer.h',
|
||||
'tvgGlCommon.h',
|
||||
'tvgGlGpuBuffer.h',
|
||||
'tvgGlProgram.h',
|
||||
'tvgGlRenderer.cpp',
|
||||
]
|
||||
'tvgGlRenderer.h',
|
||||
'tvgGlShader.h',
|
||||
'tvgGlGeometry.h',
|
||||
]
|
||||
|
||||
glraster_dep = declare_dependency(
|
||||
include_directories : include_directories('.'),
|
||||
|
|
19
src/lib/gl_engine/tvgGlCommon.h
Normal file
19
src/lib/gl_engine/tvgGlCommon.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef _TVG_GL_COMMON_H_
|
||||
#define _TVG_GL_COMMON_H_
|
||||
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgGlProgram.h"
|
||||
#include "tvgGlShader.h"
|
||||
#include "tvgGlGeometry.h"
|
||||
|
||||
|
||||
struct GlShape
|
||||
{
|
||||
float viewWd;
|
||||
float viewHt;
|
||||
RenderUpdateFlag updateFlag;
|
||||
unique_ptr<GlGeometry> geometry;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _TVG_GL_COMMON_H_ */
|
180
src/lib/gl_engine/tvgGlGeometry.h
Normal file
180
src/lib/gl_engine/tvgGlGeometry.h
Normal file
|
@ -0,0 +1,180 @@
|
|||
#ifndef _TVG_GL_GEOMETRY_H_
|
||||
#define _TVG_GL_GEOMETRY_H_
|
||||
|
||||
#include "tvgGlGpuBuffer.h"
|
||||
|
||||
class GlPoint
|
||||
{
|
||||
public:
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
|
||||
GlPoint(float pX, float pY):x(pX), y(pY)
|
||||
{}
|
||||
|
||||
GlPoint(const Point& rhs):GlPoint(rhs.x, rhs.y)
|
||||
{}
|
||||
|
||||
GlPoint(const GlPoint& rhs) = default;
|
||||
GlPoint(GlPoint&& rhs) = default;
|
||||
|
||||
GlPoint& operator= (const GlPoint& rhs) = default;
|
||||
GlPoint& operator= (GlPoint&& rhs) = default;
|
||||
|
||||
GlPoint& operator= (const Point& rhs)
|
||||
{
|
||||
x = rhs.x;
|
||||
y = rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator== (const GlPoint& rhs)
|
||||
{
|
||||
if (&rhs == this)
|
||||
return true;
|
||||
if (rhs.x == this->x && rhs.y == this->y)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!= (const GlPoint& rhs)
|
||||
{
|
||||
if (&rhs == this)
|
||||
return true;
|
||||
if (rhs.x != this->x || rhs.y != this->y)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
GlPoint operator+ (const GlPoint& rhs) const
|
||||
{
|
||||
return GlPoint(x + rhs.x, y + rhs.y);
|
||||
}
|
||||
|
||||
GlPoint operator+ (const float c) const
|
||||
{
|
||||
return GlPoint(x + c, y + c);
|
||||
}
|
||||
|
||||
GlPoint operator- (const GlPoint& rhs) const
|
||||
{
|
||||
return GlPoint(x - rhs.x, y - rhs.y);
|
||||
}
|
||||
|
||||
GlPoint operator- (const float c) const
|
||||
{
|
||||
return GlPoint(x - c, y - c);
|
||||
}
|
||||
|
||||
GlPoint operator* (const GlPoint& rhs) const
|
||||
{
|
||||
return GlPoint(x * rhs.x, y * rhs.y);
|
||||
}
|
||||
|
||||
GlPoint operator* (const float c) const
|
||||
{
|
||||
return GlPoint(x * c, y * c);
|
||||
}
|
||||
|
||||
GlPoint operator/ (const GlPoint& rhs) const
|
||||
{
|
||||
return GlPoint(x / rhs.x, y / rhs.y);
|
||||
}
|
||||
|
||||
GlPoint operator/ (const float c) const
|
||||
{
|
||||
return GlPoint(x / c, y / c);
|
||||
}
|
||||
|
||||
void mod()
|
||||
{
|
||||
x = fabsf(x);
|
||||
y = fabsf(y);
|
||||
}
|
||||
|
||||
void normalize()
|
||||
{
|
||||
auto length = sqrtf( (x * x) + (y * y) );
|
||||
if (length != 0.0f)
|
||||
{
|
||||
const auto inverseLen = 1.0f / length;
|
||||
x *= inverseLen;
|
||||
y *= inverseLen;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct SmoothPoint
|
||||
{
|
||||
GlPoint orgPt;
|
||||
GlPoint fillOuterBlur;
|
||||
GlPoint fillOuter;
|
||||
GlPoint strokeOuterBlur;
|
||||
GlPoint strokeOuter;
|
||||
GlPoint strokeInnerBlur;
|
||||
GlPoint strokeInner;
|
||||
|
||||
SmoothPoint(GlPoint pt)
|
||||
:orgPt(pt),
|
||||
fillOuterBlur(pt),
|
||||
fillOuter(pt),
|
||||
strokeOuterBlur(pt),
|
||||
strokeOuter(pt),
|
||||
strokeInnerBlur(pt),
|
||||
strokeInner(pt)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct PointNormals
|
||||
{
|
||||
GlPoint normal1;
|
||||
GlPoint normal2;
|
||||
GlPoint normalF;
|
||||
};
|
||||
|
||||
struct VertexData
|
||||
{
|
||||
GlPoint point;
|
||||
float opacity = 0.0f;
|
||||
};
|
||||
|
||||
struct VertexDataArray
|
||||
{
|
||||
vector<VertexData> vertices;
|
||||
vector<uint32_t> indices;
|
||||
};
|
||||
|
||||
class GlGeometry
|
||||
{
|
||||
public:
|
||||
GlGeometry();
|
||||
void reset();
|
||||
void updateBuffer(const uint32_t location, const VertexDataArray& geometry);
|
||||
void draw(const VertexDataArray& geometry);
|
||||
bool decomposeOutline(const Shape& shape);
|
||||
bool generateAAPoints(const Shape& shape, float strokeWd, RenderUpdateFlag flag);
|
||||
bool tesselate(const Shape &shape, float viewWd, float viewHt, RenderUpdateFlag flag);
|
||||
|
||||
const VertexDataArray& getFill();
|
||||
const VertexDataArray& getStroke();
|
||||
|
||||
private:
|
||||
GlPoint normalizePoint(GlPoint &pt, float viewWd, float viewHt);
|
||||
void addGeometryPoint(VertexDataArray &geometry, GlPoint &pt, float viewWd, float viewHt, float opacity);
|
||||
GlPoint getNormal(GlPoint &p1, GlPoint &p2);
|
||||
float dotProduct(GlPoint &p1, GlPoint &p2);
|
||||
GlPoint extendEdge(GlPoint &pt, GlPoint &normal, float scalar);
|
||||
void addPoint(const GlPoint &pt);
|
||||
void addTriangleFanIndices(uint32_t &curPt, vector<uint32_t> &indices);
|
||||
void addQuadIndices(uint32_t &curPt, vector<uint32_t> &indices);
|
||||
bool isBezierFlat(const GlPoint &p1, const GlPoint &c1, const GlPoint &c2, const GlPoint &p2);
|
||||
void decomposeCubicCurve(const GlPoint &pt1, const GlPoint &cpt1, const GlPoint &cpt2, const GlPoint &pt2);
|
||||
|
||||
unique_ptr<GlGpuBuffer> mGpuBuffer;
|
||||
vector<SmoothPoint> mAAPoints;
|
||||
VertexDataArray mFill;
|
||||
VertexDataArray mStroke;
|
||||
};
|
||||
|
||||
#endif /* _TVG_GL_GEOMETRY_H_ */
|
26
src/lib/gl_engine/tvgGlGpuBuffer.h
Normal file
26
src/lib/gl_engine/tvgGlGpuBuffer.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef _TVG_GL_GPU_BUFFER_H_
|
||||
#define _TVG_GL_GPU_BUFFER_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
class GlGpuBuffer
|
||||
{
|
||||
public:
|
||||
enum class Target
|
||||
{
|
||||
ARRAY_BUFFER = GL_ARRAY_BUFFER,
|
||||
ELEMENT_ARRAY_BUFFER = GL_ARRAY_BUFFER
|
||||
};
|
||||
|
||||
GlGpuBuffer();
|
||||
~GlGpuBuffer();
|
||||
void updateBufferData(Target target, size_t size, void* data);
|
||||
|
||||
private:
|
||||
uint32_t mGlBufferId = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* _TVG_GL_GPU_BUFFER_H_ */
|
||||
|
29
src/lib/gl_engine/tvgGlProgram.h
Normal file
29
src/lib/gl_engine/tvgGlProgram.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef _TVG_GL_PROGRAM_H_
|
||||
#define _TVG_GL_PROGRAM_H_
|
||||
|
||||
#include "tvgGlShader.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
class GlProgram
|
||||
{
|
||||
public:
|
||||
GlProgram(shared_ptr<GlShader> shader);
|
||||
void create();
|
||||
void load();
|
||||
int32_t getAttributeLocation(const char* name);
|
||||
int32_t getUniformLocation(const char* name);
|
||||
void setUniformValue(int32_t location, float r, float g, float b, float a);
|
||||
|
||||
private:
|
||||
void linkProgram();
|
||||
std::shared_ptr<GlShader> mShader;
|
||||
uint32_t mProgramObj;
|
||||
static uint32_t mCurrentProgram;
|
||||
|
||||
static std::map<string, int32_t> mAttributeBuffer;
|
||||
static std::map<string, int32_t> mUniformBuffer;
|
||||
};
|
||||
|
||||
#endif /* _TVG_GL_PROGRAM_H_ */
|
|
@ -26,11 +26,6 @@
|
|||
|
||||
static RenderInitializer renderInit;
|
||||
|
||||
struct GlShape
|
||||
{
|
||||
//TODO:
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
|
|
@ -17,15 +17,23 @@
|
|||
#ifndef _TVG_GL_RENDERER_H_
|
||||
#define _TVG_GL_RENDERER_H_
|
||||
|
||||
#include "tvgGlCommon.h"
|
||||
|
||||
namespace tvg
|
||||
{
|
||||
|
||||
class GlRenderer : public RenderMethod
|
||||
{
|
||||
public:
|
||||
Surface surface;
|
||||
|
||||
void* prepare(const Shape& shape, void* data, const RenderTransform* transform, RenderUpdateFlag flags) override;
|
||||
bool dispose(const Shape& shape, void *data) override;
|
||||
bool render(const Shape& shape, void *data) override;
|
||||
bool target(uint32_t* buffer, size_t stride, size_t w, size_t h)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
bool clear() override;
|
||||
size_t ref() override;
|
||||
size_t unref() override;
|
||||
|
@ -37,6 +45,10 @@ public:
|
|||
private:
|
||||
GlRenderer(){};
|
||||
~GlRenderer(){};
|
||||
|
||||
std::unique_ptr<GlProgram> mColorProgram;
|
||||
int32_t mColorUniform;
|
||||
uint32_t mVertexAttrID;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
20
src/lib/gl_engine/tvgGlShader.h
Normal file
20
src/lib/gl_engine/tvgGlShader.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef _TVG_GL_SHADER_H_
|
||||
#define _TVG_GL_SHADER_H_
|
||||
|
||||
class GlShader
|
||||
{
|
||||
public:
|
||||
static shared_ptr<GlShader> gen(const char * vertSrc, const char * fragSrc);
|
||||
|
||||
uint32_t getVertexShader();
|
||||
uint32_t getFragmentShader();
|
||||
|
||||
private:
|
||||
void createShader(const char* vertSrc, const char* fragSrc);
|
||||
uint32_t complileShader(uint32_t type, char* shaderSrc);
|
||||
|
||||
uint32_t mVtShader;
|
||||
uint32_t mFrShader;
|
||||
};
|
||||
|
||||
#endif /* _TVG_GL_SHADER_H_ */
|
|
@ -45,6 +45,17 @@ GlCanvas::~GlCanvas()
|
|||
}
|
||||
|
||||
|
||||
int GlCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
|
||||
{
|
||||
auto renderer = dynamic_cast<GlRenderer*>(Canvas::pImpl.get()->renderer);
|
||||
assert(renderer);
|
||||
|
||||
if (!renderer->target(buffer, stride, w, h)) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int GlCanvas::sync() noexcept
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -2,8 +2,12 @@ compiler_flags = ['-DTIZENVG_BUILD']
|
|||
|
||||
subdir('lib')
|
||||
subdir('examples')
|
||||
m_dep = meson.get_compiler('cpp').find_library('m')
|
||||
egl_dep = meson.get_compiler('cpp').find_library('EGL')
|
||||
gl_dep = meson.get_compiler('cpp').find_library('GLESv2')
|
||||
|
||||
tizenvg_lib_dep = [ src_dep, swraster_dep, glraster_dep, m_dep, egl_dep, gl_dep]
|
||||
|
||||
tizenvg_lib_dep = [ src_dep, swraster_dep, glraster_dep ]
|
||||
|
||||
tizenvg_lib = library(
|
||||
'tizenvg',
|
||||
|
|
Loading…
Add table
Reference in a new issue