mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
gl_engine: remove unused alpha attribute
Since we choose MSAA, no need to calculate edge alpha during fragment stage. So this commit removed the alpha attribute and related code: * Remove the alpha attribute in vertex data. * Change position type from `vec3` to `vec2` in all shader code. * Remove alhpa multiplication in all fragment shaders
This commit is contained in:
parent
1e4bf308da
commit
cc2fa23359
4 changed files with 60 additions and 89 deletions
|
@ -20,17 +20,11 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <float.h>
|
|
||||||
#include "tvgGlGpuBuffer.h"
|
#include "tvgGlGpuBuffer.h"
|
||||||
#include "tvgGlGeometry.h"
|
#include "tvgGlGeometry.h"
|
||||||
#include "tvgGlTessellator.h"
|
#include "tvgGlTessellator.h"
|
||||||
#include "tvgGlRenderTask.h"
|
#include "tvgGlRenderTask.h"
|
||||||
|
|
||||||
#define NORMALIZED_TOP_3D 1.0f
|
|
||||||
#define NORMALIZED_BOTTOM_3D -1.0f
|
|
||||||
#define NORMALIZED_LEFT_3D -1.0f
|
|
||||||
#define NORMALIZED_RIGHT_3D 1.0f
|
|
||||||
|
|
||||||
GlGeometry::~GlGeometry()
|
GlGeometry::~GlGeometry()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -74,19 +68,19 @@ bool GlGeometry::tesselate(const Surface* image, const RenderMesh* mesh, RenderU
|
||||||
for (uint32_t i = 0; i < mesh->triangleCnt; i++) {
|
for (uint32_t i = 0; i < mesh->triangleCnt; i++) {
|
||||||
fillVertex.push(mesh->triangles[i].vertex[0].pt.x);
|
fillVertex.push(mesh->triangles[i].vertex[0].pt.x);
|
||||||
fillVertex.push(mesh->triangles[i].vertex[0].pt.y);
|
fillVertex.push(mesh->triangles[i].vertex[0].pt.y);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(mesh->triangles[i].vertex[0].uv.x);
|
fillVertex.push(mesh->triangles[i].vertex[0].uv.x);
|
||||||
fillVertex.push(mesh->triangles[i].vertex[0].uv.y);
|
fillVertex.push(mesh->triangles[i].vertex[0].uv.y);
|
||||||
|
|
||||||
fillVertex.push(mesh->triangles[i].vertex[1].pt.x);
|
fillVertex.push(mesh->triangles[i].vertex[1].pt.x);
|
||||||
fillVertex.push(mesh->triangles[i].vertex[1].pt.y);
|
fillVertex.push(mesh->triangles[i].vertex[1].pt.y);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(mesh->triangles[i].vertex[1].uv.x);
|
fillVertex.push(mesh->triangles[i].vertex[1].uv.x);
|
||||||
fillVertex.push(mesh->triangles[i].vertex[1].uv.y);
|
fillVertex.push(mesh->triangles[i].vertex[1].uv.y);
|
||||||
|
|
||||||
fillVertex.push(mesh->triangles[i].vertex[2].pt.x);
|
fillVertex.push(mesh->triangles[i].vertex[2].pt.x);
|
||||||
fillVertex.push(mesh->triangles[i].vertex[2].pt.y);
|
fillVertex.push(mesh->triangles[i].vertex[2].pt.y);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(mesh->triangles[i].vertex[2].uv.x);
|
fillVertex.push(mesh->triangles[i].vertex[2].uv.x);
|
||||||
fillVertex.push(mesh->triangles[i].vertex[2].uv.y);
|
fillVertex.push(mesh->triangles[i].vertex[2].uv.y);
|
||||||
|
|
||||||
|
@ -108,25 +102,25 @@ bool GlGeometry::tesselate(const Surface* image, const RenderMesh* mesh, RenderU
|
||||||
// left top point
|
// left top point
|
||||||
fillVertex.push(left);
|
fillVertex.push(left);
|
||||||
fillVertex.push(top);
|
fillVertex.push(top);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(0.f);
|
fillVertex.push(0.f);
|
||||||
fillVertex.push(1.f);
|
fillVertex.push(1.f);
|
||||||
// left bottom point
|
// left bottom point
|
||||||
fillVertex.push(left);
|
fillVertex.push(left);
|
||||||
fillVertex.push(bottom);
|
fillVertex.push(bottom);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(0.f);
|
fillVertex.push(0.f);
|
||||||
fillVertex.push(0.f);
|
fillVertex.push(0.f);
|
||||||
// right top point
|
// right top point
|
||||||
fillVertex.push(right);
|
fillVertex.push(right);
|
||||||
fillVertex.push(top);
|
fillVertex.push(top);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(1.f);
|
fillVertex.push(1.f);
|
||||||
fillVertex.push(1.f);
|
fillVertex.push(1.f);
|
||||||
// right bottom point
|
// right bottom point
|
||||||
fillVertex.push(right);
|
fillVertex.push(right);
|
||||||
fillVertex.push(bottom);
|
fillVertex.push(bottom);
|
||||||
fillVertex.push(1.f);
|
|
||||||
fillVertex.push(1.f);
|
fillVertex.push(1.f);
|
||||||
fillVertex.push(0.f);
|
fillVertex.push(0.f);
|
||||||
|
|
||||||
|
@ -176,10 +170,10 @@ bool GlGeometry::draw(GlRenderTask* task, GlStageBuffer* gpuBuffer, RenderUpdate
|
||||||
// vertex layout
|
// vertex layout
|
||||||
if (flag & RenderUpdateFlag::Image) {
|
if (flag & RenderUpdateFlag::Image) {
|
||||||
// image has two attribute: [pos, uv]
|
// image has two attribute: [pos, uv]
|
||||||
task->addVertexLayout(GlVertexLayout{0, 3, 5 * sizeof(float), vertexOffset});
|
task->addVertexLayout(GlVertexLayout{0, 2, 4 * sizeof(float), vertexOffset});
|
||||||
task->addVertexLayout(GlVertexLayout{1, 2, 5 * sizeof(float), vertexOffset + 3 * sizeof(float)});
|
task->addVertexLayout(GlVertexLayout{1, 2, 4 * sizeof(float), vertexOffset + 2 * sizeof(float)});
|
||||||
} else {
|
} else {
|
||||||
task->addVertexLayout(GlVertexLayout{0, 3, 3 * sizeof(float), vertexOffset});
|
task->addVertexLayout(GlVertexLayout{0, 2, 2 * sizeof(float), vertexOffset});
|
||||||
}
|
}
|
||||||
task->setDrawRange(indexOffset, indexBuffer->count);
|
task->setDrawRange(indexOffset, indexBuffer->count);
|
||||||
task->setViewport(viewport);
|
task->setViewport(viewport);
|
||||||
|
|
|
@ -108,7 +108,6 @@ bool GlRenderer::sync()
|
||||||
GL_CHECK(glDisable(GL_SCISSOR_TEST));
|
GL_CHECK(glDisable(GL_SCISSOR_TEST));
|
||||||
|
|
||||||
mRenderPassStack.clear();
|
mRenderPassStack.clear();
|
||||||
mClearBuffer = false;
|
|
||||||
|
|
||||||
delete task;
|
delete task;
|
||||||
|
|
||||||
|
@ -498,7 +497,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, uint8_t r, uint8_t g, uint8_t b,
|
||||||
if (sdata.geometry->needStencilCover(flag)) stencilTask = new GlRenderTask(mPrograms[RT_Stencil].get(), task);
|
if (sdata.geometry->needStencilCover(flag)) stencilTask = new GlRenderTask(mPrograms[RT_Stencil].get(), task);
|
||||||
|
|
||||||
a = MULTIPLY(a, sdata.opacity);
|
a = MULTIPLY(a, sdata.opacity);
|
||||||
|
|
||||||
// matrix buffer
|
// matrix buffer
|
||||||
{
|
{
|
||||||
auto matrix = sdata.geometry->getTransforMatrix();
|
auto matrix = sdata.geometry->getTransforMatrix();
|
||||||
|
@ -524,7 +523,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, uint8_t r, uint8_t g, uint8_t b,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// color
|
// color
|
||||||
{
|
{
|
||||||
float color[4] = {r / 255.f, g / 255.f, b / 255.f, a / 255.f};
|
float color[4] = {r / 255.f, g / 255.f, b / 255.f, a / 255.f};
|
||||||
|
|
||||||
|
@ -678,7 +677,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlRenderPass* GlRenderer::currentPass()
|
GlRenderPass* GlRenderer::currentPass()
|
||||||
{
|
{
|
||||||
if (mRenderPassStack.empty()) return nullptr;
|
if (mRenderPassStack.empty()) return nullptr;
|
||||||
|
|
||||||
|
|
|
@ -26,33 +26,28 @@
|
||||||
#define TVG_COMPOSE_SHADER(shader) #shader
|
#define TVG_COMPOSE_SHADER(shader) #shader
|
||||||
|
|
||||||
const char* COLOR_VERT_SHADER = TVG_COMPOSE_SHADER(
|
const char* COLOR_VERT_SHADER = TVG_COMPOSE_SHADER(
|
||||||
layout(location = 0) in vec3 aLocation; \n
|
layout(location = 0) in vec2 aLocation; \n
|
||||||
layout(std140) uniform Matrix { \n
|
layout(std140) uniform Matrix { \n
|
||||||
mat4 transform; \n
|
mat4 transform; \n
|
||||||
} uMatrix; \n
|
} uMatrix; \n
|
||||||
out float vOpacity; \n
|
|
||||||
void main() \n
|
void main() \n
|
||||||
{ \n
|
{ \n
|
||||||
gl_Position = \n
|
gl_Position = uMatrix.transform * vec4(aLocation, 0.0, 1.0);\n
|
||||||
uMatrix.transform * vec4(aLocation.xy, 0.0, 1.0); \n
|
|
||||||
vOpacity = aLocation.z; \n
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const char* COLOR_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
const char* COLOR_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
layout(std140) uniform ColorInfo { \n
|
layout(std140) uniform ColorInfo { \n
|
||||||
vec4 solidColor; \n
|
vec4 solidColor; \n
|
||||||
} uColorInfo; \n
|
} uColorInfo; \n
|
||||||
in float vOpacity; \n
|
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
void main() \n
|
void main() \n
|
||||||
{ \n
|
{ \n
|
||||||
vec4 uColor = uColorInfo.solidColor; \n
|
vec4 uColor = uColorInfo.solidColor; \n
|
||||||
FragColor = vec4(uColor.xyz, uColor.w*vOpacity); \n
|
FragColor = uColor; \n
|
||||||
});
|
});
|
||||||
|
|
||||||
const char* GRADIENT_VERT_SHADER = TVG_COMPOSE_SHADER(
|
const char* GRADIENT_VERT_SHADER = TVG_COMPOSE_SHADER(
|
||||||
layout(location = 0) in vec3 aLocation; \n
|
layout(location = 0) in vec2 aLocation; \n
|
||||||
out float vOpacity; \n
|
|
||||||
out vec2 vPos; \n
|
out vec2 vPos; \n
|
||||||
layout(std140) uniform Matrix { \n
|
layout(std140) uniform Matrix { \n
|
||||||
mat4 transform; \n
|
mat4 transform; \n
|
||||||
|
@ -60,16 +55,14 @@ layout(std140) uniform Matrix {
|
||||||
\n
|
\n
|
||||||
void main() \n
|
void main() \n
|
||||||
{ \n
|
{ \n
|
||||||
gl_Position = uMatrix.transform * vec4(aLocation.xy, 0.0, 1.0); \n
|
gl_Position = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
|
||||||
vOpacity = aLocation.z; \n
|
vPos = aLocation; \n
|
||||||
vPos = aLocation.xy; \n
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
std::string STR_GRADIENT_FRAG_COMMON_VARIABLES = TVG_COMPOSE_SHADER(
|
std::string STR_GRADIENT_FRAG_COMMON_VARIABLES = TVG_COMPOSE_SHADER(
|
||||||
const int MAX_STOP_COUNT = 16; \n
|
const int MAX_STOP_COUNT = 16; \n
|
||||||
in vec2 vPos; \n
|
in vec2 vPos; \n
|
||||||
in float vOpacity; \n
|
|
||||||
);
|
);
|
||||||
|
|
||||||
std::string STR_GRADIENT_FRAG_COMMON_FUNCTIONS = TVG_COMPOSE_SHADER(
|
std::string STR_GRADIENT_FRAG_COMMON_FUNCTIONS = TVG_COMPOSE_SHADER(
|
||||||
|
@ -155,7 +148,7 @@ layout(std140) uniform GradientInfo {
|
||||||
vec4 nStops; \n
|
vec4 nStops; \n
|
||||||
vec2 gradStartPos; \n
|
vec2 gradStartPos; \n
|
||||||
vec2 gradEndPos; \n
|
vec2 gradEndPos; \n
|
||||||
vec4 stopPoints[MAX_STOP_COUNT / 4]; \n
|
vec4 stopPoints[MAX_STOP_COUNT / 4]; \n
|
||||||
vec4 stopColors[MAX_STOP_COUNT]; \n
|
vec4 stopColors[MAX_STOP_COUNT]; \n
|
||||||
} uGradientInfo ; \n
|
} uGradientInfo ; \n
|
||||||
);
|
);
|
||||||
|
@ -178,7 +171,7 @@ void main()
|
||||||
\n
|
\n
|
||||||
vec3 noise = 8.0 * uGradientInfo.nStops[1] * ScreenSpaceDither(pos); \n
|
vec3 noise = 8.0 * uGradientInfo.nStops[1] * ScreenSpaceDither(pos); \n
|
||||||
vec4 finalCol = vec4(color.xyz + noise, color.w); \n
|
vec4 finalCol = vec4(color.xyz + noise, color.w); \n
|
||||||
FragColor = vec4(finalCol.xyz, finalCol.w* vOpacity); \n
|
FragColor = finalCol; \n
|
||||||
});
|
});
|
||||||
|
|
||||||
std::string STR_RADIAL_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER(
|
std::string STR_RADIAL_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER(
|
||||||
|
@ -207,7 +200,7 @@ void main()
|
||||||
\n
|
\n
|
||||||
vec3 noise = 8.0 * uGradientInfo.nStops[1] * ScreenSpaceDither(pos); \n
|
vec3 noise = 8.0 * uGradientInfo.nStops[1] * ScreenSpaceDither(pos); \n
|
||||||
vec4 finalCol = vec4(color.xyz + noise, color.w); \n
|
vec4 finalCol = vec4(color.xyz + noise, color.w); \n
|
||||||
FragColor = vec4(finalCol.xyz, finalCol.w * vOpacity); \n
|
FragColor = finalCol; \n
|
||||||
});
|
});
|
||||||
|
|
||||||
std::string STR_LINEAR_GRADIENT_FRAG_SHADER =
|
std::string STR_LINEAR_GRADIENT_FRAG_SHADER =
|
||||||
|
@ -228,19 +221,17 @@ const char* RADIAL_GRADIENT_FRAG_SHADER = STR_RADIAL_GRADIENT_FRAG_SHADER.c_str(
|
||||||
|
|
||||||
|
|
||||||
const char* IMAGE_VERT_SHADER = TVG_COMPOSE_SHADER(
|
const char* IMAGE_VERT_SHADER = TVG_COMPOSE_SHADER(
|
||||||
layout (location = 0) in vec3 aLocation; \n
|
layout (location = 0) in vec2 aLocation; \n
|
||||||
layout (location = 1) in vec2 aUV; \n
|
layout (location = 1) in vec2 aUV; \n
|
||||||
layout (std140) uniform Matrix { \n
|
layout (std140) uniform Matrix { \n
|
||||||
mat4 transform; \n
|
mat4 transform; \n
|
||||||
} uMatrix; \n
|
} uMatrix; \n
|
||||||
\n
|
\n
|
||||||
out float aOpacity; \n
|
|
||||||
out vec2 vUV; \n
|
out vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
void main() { \n
|
void main() { \n
|
||||||
aOpacity = aLocation.z; \n
|
|
||||||
vUV = aUV; \n
|
vUV = aUV; \n
|
||||||
gl_Position = uMatrix.transform * vec4(aLocation.xy, 0.0, 1.0); \n
|
gl_Position = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -253,7 +244,6 @@ const char* IMAGE_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
} uColorInfo; \n
|
} uColorInfo; \n
|
||||||
uniform sampler2D uTexture; \n
|
uniform sampler2D uTexture; \n
|
||||||
\n
|
\n
|
||||||
in float aOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -278,22 +268,20 @@ const char* IMAGE_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
result.a = color.a; \n
|
result.a = color.a; \n
|
||||||
} \n
|
} \n
|
||||||
float opacity = float(uColorInfo.opacity) / 255.0; \n
|
float opacity = float(uColorInfo.opacity) / 255.0; \n
|
||||||
FragColor = vec4(result.rgb, result.a * opacity * aOpacity); \n
|
FragColor = vec4(result.rgb, result.a * opacity); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
const char* MASK_VERT_SHADER = TVG_COMPOSE_SHADER(
|
const char* MASK_VERT_SHADER = TVG_COMPOSE_SHADER(
|
||||||
layout(location = 0) in vec3 aLocation; \n
|
layout(location = 0) in vec2 aLocation; \n
|
||||||
layout(location = 1) in vec2 aUV; \n
|
layout(location = 1) in vec2 aUV; \n
|
||||||
\n
|
\n
|
||||||
out float vOpacity; \n
|
|
||||||
out vec2 vUV; \n
|
out vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
void main() { \n
|
void main() { \n
|
||||||
vUV = aUV; \n
|
vUV = aUV; \n
|
||||||
vOpacity = aLocation.z; \n
|
|
||||||
\n
|
\n
|
||||||
gl_Position = vec4(aLocation.xy, 0.0, 1.0); \n
|
gl_Position = vec4(aLocation, 0.0, 1.0); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -302,7 +290,6 @@ const char* MASK_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -312,7 +299,7 @@ void main() { \n
|
||||||
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
||||||
\n
|
\n
|
||||||
FragColor = vec4(srcColor.rgb, \n
|
FragColor = vec4(srcColor.rgb, \n
|
||||||
srcColor.a * maskColor.a * vOpacity); \n
|
srcColor.a * maskColor.a); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -320,7 +307,6 @@ const char* MASK_INV_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -330,7 +316,7 @@ void main() { \n
|
||||||
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
||||||
\n
|
\n
|
||||||
FragColor = vec4(srcColor.rgb, \n
|
FragColor = vec4(srcColor.rgb, \n
|
||||||
srcColor.a * (1.0 - maskColor.a) * vOpacity); \n
|
srcColor.a * (1.0 - maskColor.a)); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -338,7 +324,6 @@ const char* MASK_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -347,7 +332,7 @@ void main() {
|
||||||
vec4 srcColor = texture(uSrcTexture, vUV); \n
|
vec4 srcColor = texture(uSrcTexture, vUV); \n
|
||||||
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
||||||
\n
|
\n
|
||||||
FragColor = srcColor * vOpacity * (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b); \n
|
FragColor = srcColor * (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -355,7 +340,6 @@ const char* MASK_INV_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -365,7 +349,7 @@ void main() {
|
||||||
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
vec4 maskColor = texture(uMaskTexture, vUV); \n
|
||||||
\n
|
\n
|
||||||
float luma = (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b); \n
|
float luma = (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b); \n
|
||||||
FragColor = srcColor * vOpacity * (1.0 - luma); \n
|
FragColor = srcColor * (1.0 - luma); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -373,7 +357,6 @@ const char* MASK_ADD_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -384,7 +367,7 @@ void main() { \n
|
||||||
\n
|
\n
|
||||||
vec4 color = srcColor + maskColor * (1.0 - srcColor.a); \n
|
vec4 color = srcColor + maskColor * (1.0 - srcColor.a); \n
|
||||||
\n
|
\n
|
||||||
FragColor = min(color, vec4(1.0, 1.0, 1.0, 1.0 * vOpacity)) ; \n
|
FragColor = min(color, vec4(1.0, 1.0, 1.0, 1.0)) ; \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -392,7 +375,6 @@ const char* MASK_SUB_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -405,7 +387,7 @@ void main() { \n
|
||||||
if (a <= 0.0) { \n
|
if (a <= 0.0) { \n
|
||||||
FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n
|
FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n
|
||||||
} else { \n
|
} else { \n
|
||||||
FragColor = vec4(srcColor.rgb, srcColor.a * vOpacity * a); \n
|
FragColor = vec4(srcColor.rgb, srcColor.a * a); \n
|
||||||
} \n
|
} \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
@ -414,7 +396,6 @@ const char* MASK_INTERSECT_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -425,7 +406,7 @@ void main() { \n
|
||||||
\n
|
\n
|
||||||
float intAlpha = srcColor.a * maskColor.a; \n
|
float intAlpha = srcColor.a * maskColor.a; \n
|
||||||
\n
|
\n
|
||||||
FragColor = vec4(maskColor.rgb, maskColor.a * vOpacity * intAlpha); \n
|
FragColor = vec4(maskColor.rgb, maskColor.a * intAlpha); \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -433,7 +414,6 @@ const char* MASK_DIFF_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
uniform sampler2D uSrcTexture; \n
|
uniform sampler2D uSrcTexture; \n
|
||||||
uniform sampler2D uMaskTexture; \n
|
uniform sampler2D uMaskTexture; \n
|
||||||
\n
|
\n
|
||||||
in float vOpacity; \n
|
|
||||||
in vec2 vUV; \n
|
in vec2 vUV; \n
|
||||||
\n
|
\n
|
||||||
out vec4 FragColor; \n
|
out vec4 FragColor; \n
|
||||||
|
@ -447,22 +427,22 @@ void main() { \n
|
||||||
if (da == 0.0) { \n
|
if (da == 0.0) { \n
|
||||||
FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n
|
FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n
|
||||||
} else if (da > 0.0) { \n
|
} else if (da > 0.0) { \n
|
||||||
FragColor = vec4(srcColor.rgb, srcColor.a * da * vOpacity); \n
|
FragColor = vec4(srcColor.rgb, srcColor.a * da); \n
|
||||||
} else { \n
|
} else { \n
|
||||||
FragColor = vec4(maskColor.rgb, maskColor.a * (-da) * vOpacity);\n
|
FragColor = vec4(maskColor.rgb, maskColor.a * (-da)); \n
|
||||||
} \n
|
} \n
|
||||||
} \n
|
} \n
|
||||||
);
|
);
|
||||||
|
|
||||||
const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER(
|
const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER(
|
||||||
layout(location = 0) in vec3 aLocation; \n
|
layout(location = 0) in vec2 aLocation; \n
|
||||||
layout(std140) uniform Matrix { \n
|
layout(std140) uniform Matrix { \n
|
||||||
mat4 transform; \n
|
mat4 transform; \n
|
||||||
} uMatrix; \n
|
} uMatrix; \n
|
||||||
void main() \n
|
void main() \n
|
||||||
{ \n
|
{ \n
|
||||||
gl_Position = \n
|
gl_Position = \n
|
||||||
uMatrix.transform * vec4(aLocation.xy, 0.0, 1.0); \n
|
uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
|
||||||
});
|
});
|
||||||
|
|
||||||
const char* STENCIL_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
const char* STENCIL_FRAG_SHADER = TVG_COMPOSE_SHADER(
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "tvgGlList.h"
|
#include "tvgGlList.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
@ -816,12 +815,11 @@ static float _downScaleFloat(float v)
|
||||||
return v / 1000.f;
|
return v / 1000.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t _pushVertex(Array<float> *array, float x, float y, float z)
|
static uint32_t _pushVertex(Array<float> *array, float x, float y)
|
||||||
{
|
{
|
||||||
array->push(x);
|
array->push(x);
|
||||||
array->push(y);
|
array->push(y);
|
||||||
array->push(z);
|
return (array->count - 2) / 2;
|
||||||
return (array->count - 3) / 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Orientation
|
enum class Orientation
|
||||||
|
@ -1628,11 +1626,11 @@ void Tessellator::emitTriangle(detail::Vertex *p1, detail::Vertex *p2, detail::V
|
||||||
{
|
{
|
||||||
// check if index is generated
|
// check if index is generated
|
||||||
if (p1->index == 0xFFFFFFFF)
|
if (p1->index == 0xFFFFFFFF)
|
||||||
p1->index = detail::_pushVertex(resGlPoints, detail::_downScaleFloat(p1->point.x), detail::_downScaleFloat(p1->point.y), 1.f);
|
p1->index = detail::_pushVertex(resGlPoints, detail::_downScaleFloat(p1->point.x), detail::_downScaleFloat(p1->point.y));
|
||||||
if (p2->index == 0xFFFFFFFF)
|
if (p2->index == 0xFFFFFFFF)
|
||||||
p2->index = detail::_pushVertex(resGlPoints, detail::_downScaleFloat(p2->point.x), detail::_downScaleFloat(p2->point.y), 1.f);
|
p2->index = detail::_pushVertex(resGlPoints, detail::_downScaleFloat(p2->point.x), detail::_downScaleFloat(p2->point.y));
|
||||||
if (p3->index == 0xFFFFFFFF)
|
if (p3->index == 0xFFFFFFFF)
|
||||||
p3->index = detail::_pushVertex(resGlPoints, detail::_downScaleFloat(p3->point.x), detail::_downScaleFloat(p3->point.y), 1.f);
|
p3->index = detail::_pushVertex(resGlPoints, detail::_downScaleFloat(p3->point.x), detail::_downScaleFloat(p3->point.y));
|
||||||
|
|
||||||
resIndices->push(p1->index);
|
resIndices->push(p1->index);
|
||||||
resIndices->push(p2->index);
|
resIndices->push(p2->index);
|
||||||
|
@ -1743,10 +1741,10 @@ void Stroker::strokeLineTo(const GlPoint &curr)
|
||||||
auto c = curr + normal * strokeRadius();
|
auto c = curr + normal * strokeRadius();
|
||||||
auto d = curr - normal * strokeRadius();
|
auto d = curr - normal * strokeRadius();
|
||||||
|
|
||||||
auto ia = detail::_pushVertex(mResGlPoints, a.x, a.y, 1.f);
|
auto ia = detail::_pushVertex(mResGlPoints, a.x, a.y);
|
||||||
auto ib = detail::_pushVertex(mResGlPoints, b.x, b.y, 1.f);
|
auto ib = detail::_pushVertex(mResGlPoints, b.x, b.y);
|
||||||
auto ic = detail::_pushVertex(mResGlPoints, c.x, c.y, 1.f);
|
auto ic = detail::_pushVertex(mResGlPoints, c.x, c.y);
|
||||||
auto id = detail::_pushVertex(mResGlPoints, d.x, d.y, 1.f);
|
auto id = detail::_pushVertex(mResGlPoints, d.x, d.y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a --------- c
|
* a --------- c
|
||||||
|
@ -1867,9 +1865,9 @@ void Stroker::strokeRound(const GlPoint &prev, const GlPoint &curr, const GlPoin
|
||||||
// Fixme: just use bezier curve to calculate step count
|
// Fixme: just use bezier curve to calculate step count
|
||||||
auto count = detail::_bezierCurveCount(detail::_bezFromArc(prev, curr, strokeRadius()));
|
auto count = detail::_bezierCurveCount(detail::_bezFromArc(prev, curr, strokeRadius()));
|
||||||
|
|
||||||
auto c = detail::_pushVertex(mResGlPoints, center.x, center.y, 1.f);
|
auto c = detail::_pushVertex(mResGlPoints, center.x, center.y);
|
||||||
|
|
||||||
auto pi = detail::_pushVertex(mResGlPoints, prev.x, prev.y, 1.f);
|
auto pi = detail::_pushVertex(mResGlPoints, prev.x, prev.y);
|
||||||
|
|
||||||
float step = 1.f / (count - 1);
|
float step = 1.f / (count - 1);
|
||||||
|
|
||||||
|
@ -1884,7 +1882,7 @@ void Stroker::strokeRound(const GlPoint &prev, const GlPoint &curr, const GlPoin
|
||||||
|
|
||||||
auto out = center + o_dir * strokeRadius();
|
auto out = center + o_dir * strokeRadius();
|
||||||
|
|
||||||
auto oi = detail::_pushVertex(mResGlPoints, out.x, out.y, 1.f);
|
auto oi = detail::_pushVertex(mResGlPoints, out.x, out.y);
|
||||||
|
|
||||||
this->mResIndices->push(c);
|
this->mResIndices->push(c);
|
||||||
this->mResIndices->push(pi);
|
this->mResIndices->push(pi);
|
||||||
|
@ -1912,12 +1910,12 @@ void Stroker::strokeMiter(const GlPoint &prev, const GlPoint &curr, const GlPoin
|
||||||
|
|
||||||
auto join = center + pe;
|
auto join = center + pe;
|
||||||
|
|
||||||
auto c = detail::_pushVertex(mResGlPoints, center.x, center.y, 1.f);
|
auto c = detail::_pushVertex(mResGlPoints, center.x, center.y);
|
||||||
|
|
||||||
auto cp1 = detail::_pushVertex(mResGlPoints, prev.x, prev.y, 1.f);
|
auto cp1 = detail::_pushVertex(mResGlPoints, prev.x, prev.y);
|
||||||
auto cp2 = detail::_pushVertex(mResGlPoints, curr.x, curr.y, 1.f);
|
auto cp2 = detail::_pushVertex(mResGlPoints, curr.x, curr.y);
|
||||||
|
|
||||||
auto e = detail::_pushVertex(mResGlPoints, join.x, join.y, 1.f);
|
auto e = detail::_pushVertex(mResGlPoints, join.x, join.y);
|
||||||
|
|
||||||
this->mResIndices->push(c);
|
this->mResIndices->push(c);
|
||||||
this->mResIndices->push(cp1);
|
this->mResIndices->push(cp1);
|
||||||
|
@ -1930,9 +1928,9 @@ void Stroker::strokeMiter(const GlPoint &prev, const GlPoint &curr, const GlPoin
|
||||||
|
|
||||||
void Stroker::strokeBevel(const GlPoint &prev, const GlPoint &curr, const GlPoint ¢er)
|
void Stroker::strokeBevel(const GlPoint &prev, const GlPoint &curr, const GlPoint ¢er)
|
||||||
{
|
{
|
||||||
auto a = detail::_pushVertex(mResGlPoints, prev.x, prev.y, 1.f);
|
auto a = detail::_pushVertex(mResGlPoints, prev.x, prev.y);
|
||||||
auto b = detail::_pushVertex(mResGlPoints, curr.x, curr.y, 1.f);
|
auto b = detail::_pushVertex(mResGlPoints, curr.x, curr.y);
|
||||||
auto c = detail::_pushVertex(mResGlPoints, center.x, center.y, 1.f);
|
auto c = detail::_pushVertex(mResGlPoints, center.x, center.y);
|
||||||
|
|
||||||
mResIndices->push(a);
|
mResIndices->push(a);
|
||||||
mResIndices->push(b);
|
mResIndices->push(b);
|
||||||
|
@ -2132,7 +2130,7 @@ void BWTessellator::tessellate(const RenderShape *rshape)
|
||||||
case PathCommand::MoveTo: {
|
case PathCommand::MoveTo: {
|
||||||
firstIndex = pushVertex(pts->x, pts->y);
|
firstIndex = pushVertex(pts->x, pts->y);
|
||||||
prevIndex = 0;
|
prevIndex = 0;
|
||||||
pts++;
|
pts++;
|
||||||
} break;
|
} break;
|
||||||
case PathCommand::LineTo: {
|
case PathCommand::LineTo: {
|
||||||
if (prevIndex == 0) {
|
if (prevIndex == 0) {
|
||||||
|
@ -2171,7 +2169,7 @@ void BWTessellator::tessellate(const RenderShape *rshape)
|
||||||
|
|
||||||
pts += 3;
|
pts += 3;
|
||||||
} break;
|
} break;
|
||||||
case PathCommand::Close:
|
case PathCommand::Close:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2180,7 +2178,7 @@ void BWTessellator::tessellate(const RenderShape *rshape)
|
||||||
|
|
||||||
uint32_t BWTessellator::pushVertex(float x, float y)
|
uint32_t BWTessellator::pushVertex(float x, float y)
|
||||||
{
|
{
|
||||||
return detail::_pushVertex(mResPoints, x, y, 1.f);
|
return detail::_pushVertex(mResPoints, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BWTessellator::pushTriangle(uint32_t a, uint32_t b, uint32_t c)
|
void BWTessellator::pushTriangle(uint32_t a, uint32_t b, uint32_t c)
|
||||||
|
|
Loading…
Add table
Reference in a new issue