From 48e47b272bd474b5a6f5fc1131e2730bfc73e5c0 Mon Sep 17 00:00:00 2001 From: Prudhvi Raj Vasireddi Date: Mon, 11 May 2020 17:39:08 -0400 Subject: [PATCH] gl_engine: gl infrastructure interfaces Change-Id: Ie1a9d1b6632433413098282c1cfaf4cf8e1cf9b9 Signed-off-by: Prudhvi Raj Vasireddi --- inc/tizenvg.h | 1 + src/lib/gl_engine/meson.build | 9 +- src/lib/gl_engine/tvgGlCommon.h | 19 ++++ src/lib/gl_engine/tvgGlGeometry.h | 180 ++++++++++++++++++++++++++++++++++++ src/lib/gl_engine/tvgGlGpuBuffer.h | 26 ++++++ src/lib/gl_engine/tvgGlProgram.h | 29 ++++++ src/lib/gl_engine/tvgGlRenderer.cpp | 5 - src/lib/gl_engine/tvgGlRenderer.h | 12 +++ src/lib/gl_engine/tvgGlShader.h | 20 ++++ src/lib/tvgGlCanvas.cpp | 11 +++ src/meson.build | 6 +- 11 files changed, 310 insertions(+), 8 deletions(-) create mode 100644 src/lib/gl_engine/tvgGlCommon.h create mode 100644 src/lib/gl_engine/tvgGlGeometry.h create mode 100644 src/lib/gl_engine/tvgGlGpuBuffer.h create mode 100644 src/lib/gl_engine/tvgGlProgram.h create mode 100644 src/lib/gl_engine/tvgGlShader.h diff --git a/inc/tizenvg.h b/inc/tizenvg.h index 98b6faf..c133ace 100644 --- a/inc/tizenvg.h +++ b/inc/tizenvg.h @@ -220,6 +220,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 gen() noexcept; diff --git a/src/lib/gl_engine/meson.build b/src/lib/gl_engine/meson.build index 13e7fef..41a25e0 100644 --- a/src/lib/gl_engine/meson.build +++ b/src/lib/gl_engine/meson.build @@ -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('.'), diff --git a/src/lib/gl_engine/tvgGlCommon.h b/src/lib/gl_engine/tvgGlCommon.h new file mode 100644 index 0000000..f68666a --- /dev/null +++ b/src/lib/gl_engine/tvgGlCommon.h @@ -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 geometry; +}; + + +#endif /* _TVG_GL_COMMON_H_ */ diff --git a/src/lib/gl_engine/tvgGlGeometry.h b/src/lib/gl_engine/tvgGlGeometry.h new file mode 100644 index 0000000..8f7cc61 --- /dev/null +++ b/src/lib/gl_engine/tvgGlGeometry.h @@ -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 vertices; + vector 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 &indices); + void addQuadIndices(uint32_t &curPt, vector &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 mGpuBuffer; + vector mAAPoints; + VertexDataArray mFill; + VertexDataArray mStroke; +}; + +#endif /* _TVG_GL_GEOMETRY_H_ */ diff --git a/src/lib/gl_engine/tvgGlGpuBuffer.h b/src/lib/gl_engine/tvgGlGpuBuffer.h new file mode 100644 index 0000000..fd7086a --- /dev/null +++ b/src/lib/gl_engine/tvgGlGpuBuffer.h @@ -0,0 +1,26 @@ +#ifndef _TVG_GL_GPU_BUFFER_H_ +#define _TVG_GL_GPU_BUFFER_H_ + +#include +#include + +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_ */ + diff --git a/src/lib/gl_engine/tvgGlProgram.h b/src/lib/gl_engine/tvgGlProgram.h new file mode 100644 index 0000000..d485d3d --- /dev/null +++ b/src/lib/gl_engine/tvgGlProgram.h @@ -0,0 +1,29 @@ +#ifndef _TVG_GL_PROGRAM_H_ +#define _TVG_GL_PROGRAM_H_ + +#include "tvgGlShader.h" + +#include + + +class GlProgram +{ +public: + GlProgram(shared_ptr 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 mShader; + uint32_t mProgramObj; + static uint32_t mCurrentProgram; + + static std::map mAttributeBuffer; + static std::map mUniformBuffer; +}; + +#endif /* _TVG_GL_PROGRAM_H_ */ diff --git a/src/lib/gl_engine/tvgGlRenderer.cpp b/src/lib/gl_engine/tvgGlRenderer.cpp index 792e524..0eb9beb 100644 --- a/src/lib/gl_engine/tvgGlRenderer.cpp +++ b/src/lib/gl_engine/tvgGlRenderer.cpp @@ -26,11 +26,6 @@ static RenderInitializer renderInit; -struct GlShape -{ - //TODO: -}; - /************************************************************************/ /* External Class Implementation */ /************************************************************************/ diff --git a/src/lib/gl_engine/tvgGlRenderer.h b/src/lib/gl_engine/tvgGlRenderer.h index 4d6ba79..fcde08f 100644 --- a/src/lib/gl_engine/tvgGlRenderer.h +++ b/src/lib/gl_engine/tvgGlRenderer.h @@ -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 mColorProgram; + int32_t mColorUniform; + uint32_t mVertexAttrID; }; } diff --git a/src/lib/gl_engine/tvgGlShader.h b/src/lib/gl_engine/tvgGlShader.h new file mode 100644 index 0000000..36b125a --- /dev/null +++ b/src/lib/gl_engine/tvgGlShader.h @@ -0,0 +1,20 @@ +#ifndef _TVG_GL_SHADER_H_ +#define _TVG_GL_SHADER_H_ + +class GlShader +{ +public: + static shared_ptr 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_ */ diff --git a/src/lib/tvgGlCanvas.cpp b/src/lib/tvgGlCanvas.cpp index fb769a8..c1b7aeb 100644 --- a/src/lib/tvgGlCanvas.cpp +++ b/src/lib/tvgGlCanvas.cpp @@ -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(Canvas::pImpl.get()->renderer); + assert(renderer); + + if (!renderer->target(buffer, stride, w, h)) return -1; + + return 0; +} + + int GlCanvas::sync() noexcept { return 0; diff --git a/src/meson.build b/src/meson.build index 495e4c7..aded001 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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', -- 2.7.4