//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;
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('.'),
--- /dev/null
+#ifndef _TVG_GL_COMMON_H_\r
+#define _TVG_GL_COMMON_H_\r
+\r
+#include "tvgCommon.h"\r
+#include "tvgGlProgram.h"\r
+#include "tvgGlShader.h"\r
+#include "tvgGlGeometry.h"\r
+\r
+\r
+struct GlShape\r
+{\r
+ float viewWd;\r
+ float viewHt;\r
+ RenderUpdateFlag updateFlag;\r
+ unique_ptr<GlGeometry> geometry;\r
+};\r
+\r
+\r
+#endif /* _TVG_GL_COMMON_H_ */\r
--- /dev/null
+#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_ */
--- /dev/null
+#ifndef _TVG_GL_GPU_BUFFER_H_
+#define _TVG_GL_GPU_BUFFER_H_
+
+#include <stdlib.h>
+#include <GLES2/gl2.h>\r
+
+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_ */
+
--- /dev/null
+#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_ */
static RenderInitializer renderInit;
-struct GlShape
-{
- //TODO:
-};
-
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
#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;
private:
GlRenderer(){};
~GlRenderer(){};
+
+ std::unique_ptr<GlProgram> mColorProgram;
+ int32_t mColorUniform;
+ uint32_t mVertexAttrID;
};
}
--- /dev/null
+#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_ */
}
+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;
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',