Bundle a texture draw's placement, color, vertices and blur into TextureDraw
Most callers set only a transform and tint, by name now, in place of a nine-parameter call with positional defaults.
This commit is contained in:
1 parent
ae7dafaef6
commit
9aba726e85
5 files changed
+44
-19
No files matched your search
+11
-5
@@ -201,9 +201,9 @@ static void texture_uniforms_set(ShaderProgram& shader, Mat4 transform, Vec4 tin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::texture_render(ShaderProgram& shader, GLuint texture, Mat4 transform, Vec4 tint, Vec4 colorOffset,
|
void Canvas::texture_render(ShaderProgram& shader, GLuint texture, const TextureDraw& draw) const
|
||||||
float* vertices, Vec2 textureSize, float playbackTime, TextureBlur blur) const
|
|
||||||
{
|
{
|
||||||
|
auto& [transform, tint, colorOffset, vertices, textureSize, playbackTime, blur] = draw;
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
|
|
||||||
gl.UseProgram(shader.id);
|
gl.UseProgram(shader.id);
|
||||||
@@ -219,7 +219,7 @@ void Canvas::texture_render(ShaderProgram& shader, GLuint texture, Mat4 transfor
|
|||||||
gl.BindVertexArray(textureVAO);
|
gl.BindVertexArray(textureVAO);
|
||||||
|
|
||||||
gl.BindBuffer(GL_ARRAY_BUFFER, textureVBO);
|
gl.BindBuffer(GL_ARRAY_BUFFER, textureVBO);
|
||||||
gl.BufferData(GL_ARRAY_BUFFER, sizeof(TEXTURE_VERTICES), vertices, GL_DYNAMIC_DRAW);
|
gl.BufferData(GL_ARRAY_BUFFER, sizeof(TEXTURE_VERTICES), vertices ? vertices : TEXTURE_VERTICES, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
gl.ActiveTexture(GL_TEXTURE0);
|
gl.ActiveTexture(GL_TEXTURE0);
|
||||||
gl.BindTexture(GL_TEXTURE_2D, texture);
|
gl.BindTexture(GL_TEXTURE_2D, texture);
|
||||||
@@ -293,8 +293,14 @@ void Canvas::layer_render(ShaderProgram& shader, GLuint texture, Vec2 textureSiz
|
|||||||
frame.pivot += blur.radius;
|
frame.pivot += blur.radius;
|
||||||
}
|
}
|
||||||
auto vertices = uv_vertices_get(frame.crop / textureSize, (frame.crop + frame.size) / textureSize);
|
auto vertices = uv_vertices_get(frame.crop / textureSize, (frame.crop + frame.size) / textureSize);
|
||||||
texture_render(shader, texture, transform * blurred.parent * draw_quad_model_get(blurred), tint, colorOffset,
|
texture_render(shader, texture,
|
||||||
vertices.data(), textureSize, draw.time, blur);
|
{.transform = transform * blurred.parent * draw_quad_model_get(blurred),
|
||||||
|
.tint = tint,
|
||||||
|
.colorOffset = colorOffset,
|
||||||
|
.vertices = vertices.data(),
|
||||||
|
.textureSize = textureSize,
|
||||||
|
.time = draw.time,
|
||||||
|
.blur = blur});
|
||||||
}
|
}
|
||||||
|
|
||||||
// An animation's layers alone (no markers or helpers). Spritesheet images are looked up by draw, custom shaders by id.
|
// An animation's layers alone (no markers or helpers). Spritesheet images are looked up by draw, custom shaders by id.
|
||||||
|
|||||||
+14
-2
@@ -38,6 +38,19 @@ enum DashedShape
|
|||||||
DASHED_LINE
|
DASHED_LINE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// How a texture is drawn: placed by `transform`, colored, over `vertices` (the whole texture when null), with what a
|
||||||
|
// layer's shader reads (its texture size and playback time) and its blur.
|
||||||
|
struct TextureDraw
|
||||||
|
{
|
||||||
|
Mat4 transform = Mat4(1.0f);
|
||||||
|
Vec4 tint = Vec4(1.0f);
|
||||||
|
Vec4 colorOffset{};
|
||||||
|
const float* vertices = nullptr;
|
||||||
|
Vec2 textureSize{};
|
||||||
|
float time = 0;
|
||||||
|
TextureBlur blur = {};
|
||||||
|
};
|
||||||
|
|
||||||
class Canvas : public Framebuffer
|
class Canvas : public Framebuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -82,8 +95,7 @@ public:
|
|||||||
Mat4 transform_get(float = 100.0f, Vec2 = {}) const;
|
Mat4 transform_get(float = 100.0f, Vec2 = {}) const;
|
||||||
void axes_render(ShaderProgram&, float, Vec2, Vec4 = Vec4(1.0f)) const;
|
void axes_render(ShaderProgram&, float, Vec2, Vec4 = Vec4(1.0f)) const;
|
||||||
void grid_render(ShaderProgram&, float, Vec2, IVec2 = IVec2(32, 32), IVec2 = {}, Vec4 = Vec4(1.0f)) const;
|
void grid_render(ShaderProgram&, float, Vec2, IVec2 = IVec2(32, 32), IVec2 = {}, Vec4 = Vec4(1.0f)) const;
|
||||||
void texture_render(ShaderProgram&, GLuint, Mat4 = Mat4(1.0f), Vec4 = Vec4(1.0f), Vec4 = {},
|
void texture_render(ShaderProgram&, GLuint, const TextureDraw&) const;
|
||||||
float* = (float*)TEXTURE_VERTICES, Vec2 = {}, float = 0.0f, TextureBlur = {}) const;
|
|
||||||
void layer_render(ShaderProgram&, GLuint, Vec2, const Mat4&, const Draw&, Vec4, Vec4) const;
|
void layer_render(ShaderProgram&, GLuint, Vec2, const Mat4&, const Draw&, Vec4, Vec4) const;
|
||||||
void rect_fill_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4 = Vec4(1.0f)) const;
|
void rect_fill_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4 = Vec4(1.0f)) const;
|
||||||
void layers_render(ShaderProgram&, const Model&, const Animation&, const DrawOptions&, const Mat4&,
|
void layers_render(ShaderProgram&, const Model&, const Animation&, const DrawOptions&, const Mat4&,
|
||||||
|
|||||||
@@ -720,7 +720,7 @@ void AnimationPreview::update(Manager& manager, Settings& settings, Resources& r
|
|||||||
: ROOT_COLOR;
|
: ROOT_COLOR;
|
||||||
auto markerModel = isRootTransform ? quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
auto markerModel = isRootTransform ? quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
||||||
: marker_model_get(TARGET_SIZE);
|
: marker_model_get(TARGET_SIZE);
|
||||||
texture_render(shaderTexture, targetIcon, transform * markerModel, color);
|
texture_render(shaderTexture, targetIcon, {.transform = transform * markerModel, .tint = color});
|
||||||
}
|
}
|
||||||
else if (draw.type == DrawType::LAYER)
|
else if (draw.type == DrawType::LAYER)
|
||||||
{
|
{
|
||||||
@@ -748,7 +748,7 @@ void AnimationPreview::update(Manager& manager, Settings& settings, Resources& r
|
|||||||
rect_render(shaderLine, layerTransform, layerModel, color);
|
rect_render(shaderLine, layerTransform, layerModel, color);
|
||||||
if (isPivots && !isIsolated)
|
if (isPivots && !isIsolated)
|
||||||
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT),
|
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT),
|
||||||
transform * marker_model_get(PIVOT_SIZE), color);
|
{.transform = transform * marker_model_get(PIVOT_SIZE), .tint = color});
|
||||||
}
|
}
|
||||||
else if (!isViewOnlyLayers)
|
else if (!isViewOnlyLayers)
|
||||||
{
|
{
|
||||||
@@ -758,7 +758,7 @@ void AnimationPreview::update(Manager& manager, Settings& settings, Resources& r
|
|||||||
auto color = isOnion ? onionColor : isSelected ? COLOR_RED : NULL_RECT_COLOR;
|
auto color = isOnion ? onionColor : isSelected ? COLOR_RED : NULL_RECT_COLOR;
|
||||||
auto markerSize = isShowRect ? POINT_SIZE : TARGET_SIZE;
|
auto markerSize = isShowRect ? POINT_SIZE : TARGET_SIZE;
|
||||||
texture_render(shaderTexture, isShowRect ? resources.icon_id_get(ICON_POINT) : targetIcon,
|
texture_render(shaderTexture, isShowRect ? resources.icon_id_get(ICON_POINT) : targetIcon,
|
||||||
transform * marker_model_get(markerSize), color);
|
{.transform = transform * marker_model_get(markerSize), .tint = color});
|
||||||
if (!isShowRect)
|
if (!isShowRect)
|
||||||
continue;
|
continue;
|
||||||
auto rectModel = quad_model_get(frame.scale, frame.position, frame.scale * 0.5f, Vec2(1.0f),
|
auto rectModel = quad_model_get(frame.scale, frame.position, frame.scale * 0.5f, Vec2(1.0f),
|
||||||
@@ -834,9 +834,10 @@ void AnimationPreview::update(Manager& manager, Settings& settings, Resources& r
|
|||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
line_render(shaderDashed, baseTransform, path.points[i - 1], path.points[i], COLOR_RED);
|
line_render(shaderDashed, baseTransform, path.points[i - 1], path.points[i], COLOR_RED);
|
||||||
texture_render(shaderTexture, pointIcon,
|
texture_render(
|
||||||
baseTransform * quad_model_get(POINT_SIZE, path.points[i], POINT_SIZE * 0.5f),
|
shaderTexture, pointIcon,
|
||||||
COLOR_RED);
|
{.transform = baseTransform * quad_model_get(POINT_SIZE, path.points[i], POINT_SIZE * 0.5f),
|
||||||
|
.tint = COLOR_RED});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,11 @@ void GenerateAnimationFromGrid::update(Manager& manager, Document& document, Res
|
|||||||
percent_to_unit(frame.skew));
|
percent_to_unit(frame.skew));
|
||||||
auto vertices = uv_vertices_get(uvMin, uvMax);
|
auto vertices = uv_vertices_get(uvMin, uvMax);
|
||||||
|
|
||||||
texture_render(shaderTexture, texture_id_get(*sourceTexture), transform, frame.tint,
|
texture_render(shaderTexture, texture_id_get(*sourceTexture),
|
||||||
frame.colorOffset, vertices.data());
|
{.transform = transform,
|
||||||
|
.tint = frame.tint,
|
||||||
|
.colorOffset = frame.colorOffset,
|
||||||
|
.vertices = vertices.data()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources&
|
|||||||
if (baseTexture && baseTexture->is_valid())
|
if (baseTexture && baseTexture->is_valid())
|
||||||
texture_render(shaderTexture,
|
texture_render(shaderTexture,
|
||||||
texture_id_get(*document.vector_image_get(baseTexture, percent_to_unit(zoom))),
|
texture_id_get(*document.vector_image_get(baseTexture, percent_to_unit(zoom))),
|
||||||
spritesheetTransform);
|
{.transform = spritesheetTransform});
|
||||||
|
|
||||||
if (isGrid)
|
if (isGrid)
|
||||||
grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
|
grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
|
||||||
@@ -477,7 +477,8 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources&
|
|||||||
|
|
||||||
auto pivotTransform =
|
auto pivotTransform =
|
||||||
transform * quad_model_get(PIVOT_SIZE, region.crop + region.pivot, PIVOT_SIZE * 0.5f);
|
transform * quad_model_get(PIVOT_SIZE, region.crop + region.pivot, PIVOT_SIZE * 0.5f);
|
||||||
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT), pivotTransform, COLOR_WHITE);
|
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT),
|
||||||
|
{.transform = pivotTransform, .tint = COLOR_WHITE});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highlightedRegionId != -1)
|
if (highlightedRegionId != -1)
|
||||||
@@ -488,7 +489,8 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources&
|
|||||||
|
|
||||||
auto pivotTransform =
|
auto pivotTransform =
|
||||||
transform * quad_model_get(PIVOT_SIZE, region->crop + region->pivot, PIVOT_SIZE * 0.5f);
|
transform * quad_model_get(PIVOT_SIZE, region->crop + region->pivot, PIVOT_SIZE * 0.5f);
|
||||||
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT), pivotTransform, PIVOT_COLOR);
|
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT),
|
||||||
|
{.transform = pivotTransform, .tint = PIVOT_COLOR});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,7 +503,8 @@ void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources&
|
|||||||
|
|
||||||
auto pivotTransform =
|
auto pivotTransform =
|
||||||
transform * quad_model_get(PIVOT_SIZE, frame->crop + frame->pivot, PIVOT_SIZE * 0.5f);
|
transform * quad_model_get(PIVOT_SIZE, frame->crop + frame->pivot, PIVOT_SIZE * 0.5f);
|
||||||
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT), pivotTransform, PIVOT_COLOR);
|
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT),
|
||||||
|
{.transform = pivotTransform, .tint = PIVOT_COLOR});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user