Kaydet (Commit) 18260a0d authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

opengl: deferred texture drawing in RenderList, add drawAlphaRect

Drawing accumulated textures (in Accumulatedtextures) is independent
of drawing with render list which causes problems with rendering
order when render list and accumulated textures are flushed. To
solve this we need to combine both so we can check for overlapped
drawing.

Previously drawRect was using RenderList batch drawing but not
drawAlphaRect which is essentially the same as drawRect but
additionally supports alpha value. This adds support to draw
alpha rectangles to RenderList and converts drawAlphaRect.

Change-Id: I82bf0b410e5ebabb13bab7b29a2e53a6fdaa404f
üst bb157523
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#ifndef INCLUDED_VCL_INC_OPENGL_ACCUMULATEDTEXTURES_H
#define INCLUDED_VCL_INC_OPENGL_ACCUMULATEDTEXTURES_H
#include <vcl/opengl/OpenGLHelper.hxx>
#include <o3tl/make_unique.hxx>
#include "opengl/texture.hxx"
#include "opengl/VertexUtils.hxx"
#include <memory>
struct TextureDrawParameters
{
std::vector<GLfloat> maVertices;
std::vector<GLfloat> maTextureCoords;
};
struct AccumulatedTexturesEntry
{
OpenGLTexture maTexture;
std::unordered_map<SalColor, TextureDrawParameters> maColorTextureDrawParametersMap;
AccumulatedTexturesEntry(const OpenGLTexture& rTexture)
: maTexture(rTexture)
{}
void insert(const OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect)
{
TextureDrawParameters& aDrawParameters = maColorTextureDrawParametersMap[aColor];
rTexture.FillCoords<GL_TRIANGLES>(aDrawParameters.maTextureCoords, r2Rect, false);
GLfloat fX1 = r2Rect.mnDestX;
GLfloat fY1 = r2Rect.mnDestY;
GLfloat fX2 = fX1 + r2Rect.mnDestWidth;
GLfloat fY2 = fY1 + r2Rect.mnDestHeight;
std::vector<GLfloat>& rVertices = aDrawParameters.maVertices;
vcl::vertex::addRectangle<GL_TRIANGLES>(rVertices, fX1, fY1, fX2, fY2);
}
};
class AccumulatedTextures
{
private:
typedef std::unordered_map<GLuint, std::unique_ptr<AccumulatedTexturesEntry>> AccumulatedTexturesMap;
AccumulatedTexturesMap maEntries;
public:
AccumulatedTextures()
{}
bool empty()
{
return maEntries.empty();
}
void clear()
{
maEntries.clear();
}
bool insert(OpenGLTexture& rTexture, const SalColor& aColor, const SalTwoRect& r2Rect)
{
if (!rTexture)
return false;
GLuint nTextureId = rTexture.Id();
if (maEntries.find(nTextureId) == maEntries.end())
{
OpenGLTexture aWholeTexture(rTexture.GetWholeTexture());
maEntries[nTextureId] = o3tl::make_unique<AccumulatedTexturesEntry>(aWholeTexture);
}
std::unique_ptr<AccumulatedTexturesEntry>& rEntry = maEntries[nTextureId];
rEntry->insert(rTexture, aColor, r2Rect);
return true;
}
AccumulatedTexturesMap& getAccumulatedTexturesMap()
{
return maEntries;
}
};
#endif // INCLUDED_VCL_INC_OPENGL_ACCUMULATEDTEXTURES_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -11,12 +11,16 @@
#ifndef INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
#define INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
#include <unordered_map>
#include <glm/glm.hpp>
#include <vcl/opengl/OpenGLHelper.hxx>
#include <vcl/salgtype.hxx>
#include <basegfx/range/b2drange.hxx>
#include "opengl/texture.hxx"
struct RenderParameters
{
std::vector<GLfloat> maVertices;
......@@ -24,12 +28,22 @@ struct RenderParameters
std::vector<glm::vec4> maColors;
};
struct RenderTextureParameters
{
std::vector<GLfloat> maVertices;
std::vector<glm::vec4> maColors;
std::vector<GLfloat> maTextureCoords;
OpenGLTexture maTexture;
};
struct RenderEntry
{
RenderParameters maTriangleParameters;
RenderParameters maLineParameters;
RenderParameters maLineAAParameters;
std::unordered_map<GLuint, RenderTextureParameters> maTextureParametersMap;
bool hasTriangles()
{
return !maTriangleParameters.maVertices.empty();
......@@ -44,6 +58,11 @@ struct RenderEntry
{
return !maLineAAParameters.maVertices.empty();
}
bool hasTextures()
{
return !maTextureParametersMap.empty();
}
};
class RenderList
......@@ -85,9 +104,11 @@ public:
return maRenderEntries;
}
bool addDrawTextureWithMaskColor(OpenGLTexture& rTexture, const SalColor& rColor, const SalTwoRect& r2Rect);
void addDrawPixel(long nX, long nY, const SalColor& rColor);
void addDrawRectangle(long nX, long nY, long nWidth, long nHeight,
void addDrawRectangle(long nX, long nY, long nWidth, long nHeight, double fTransparency,
const SalColor& rLineColor, const SalColor& rFillColor);
void addDrawLine(long nX1, long nY1, long nX2, long nY2, const SalColor& rLineColor, bool bUseAA);
......
......@@ -29,7 +29,6 @@
#include "opengl/framebuffer.hxx"
#include "opengl/program.hxx"
#include "opengl/texture.hxx"
#include "opengl/AccumulatedTextures.hxx"
#include "opengl/RenderList.hxx"
#include <memory>
......@@ -101,7 +100,6 @@ protected:
SalColor mProgramSolidColor;
double mProgramSolidTransparency;
std::unique_ptr<AccumulatedTextures> mpAccumulatedTextures;
std::unique_ptr<RenderList> mpRenderList;
void ImplInitClipRegion();
......
......@@ -52,10 +52,13 @@ void RenderList::addDrawPixel(long nX, long nY, const SalColor& rColor)
vcl::vertex::addQuadEmptyExtrusionVectors<GL_TRIANGLES>(rRenderParameter.maExtrusionVectors);
}
void RenderList::addDrawRectangle(long nX, long nY, long nWidth, long nHeight, const SalColor& rLineColor, const SalColor& rFillColor)
void RenderList::addDrawRectangle(long nX, long nY, long nWidth, long nHeight, double fTransparency,
const SalColor& rLineColor, const SalColor& rFillColor)
{
if (rLineColor == SALCOLOR_NONE && rFillColor == SALCOLOR_NONE)
return;
if (fTransparency == 1.0f)
return;
GLfloat fX1(nX);
GLfloat fY1(nY);
......@@ -74,10 +77,10 @@ void RenderList::addDrawRectangle(long nX, long nY, long nWidth, long nHeight, c
vcl::vertex::addRectangle<GL_TRIANGLES>(rRenderParameter.maVertices, fX2 - 0.5f, fY1 - 0.5f, fX2 + 0.5f, fY2 + 0.5f);
vcl::vertex::addRectangle<GL_TRIANGLES>(rRenderParameter.maVertices, fX1 - 0.5f, fY2 - 0.5f, fX2 + 0.5f, fY2 + 0.5f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, fTransparency);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, fTransparency);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, fTransparency);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rLineColor, fTransparency);
vcl::vertex::addQuadEmptyExtrusionVectors<GL_TRIANGLES>(rRenderParameter.maExtrusionVectors);
vcl::vertex::addQuadEmptyExtrusionVectors<GL_TRIANGLES>(rRenderParameter.maExtrusionVectors);
......@@ -95,10 +98,10 @@ void RenderList::addDrawRectangle(long nX, long nY, long nWidth, long nHeight, c
vcl::vertex::addRectangle<GL_TRIANGLES>(rRenderParameter.maVertices, fX2 - 0.5f, fY1 - 0.5f, fX2 + 0.5f, fY2 + 0.5f);
vcl::vertex::addRectangle<GL_TRIANGLES>(rRenderParameter.maVertices, fX1 - 0.5f, fY2 - 0.5f, fX2 + 0.5f, fY2 + 0.5f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, fTransparency);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, fTransparency);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, fTransparency);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, fTransparency);
vcl::vertex::addQuadEmptyExtrusionVectors<GL_TRIANGLES>(rRenderParameter.maExtrusionVectors);
vcl::vertex::addQuadEmptyExtrusionVectors<GL_TRIANGLES>(rRenderParameter.maExtrusionVectors);
......@@ -107,7 +110,7 @@ void RenderList::addDrawRectangle(long nX, long nY, long nWidth, long nHeight, c
}
// Draw rectangle fill with fill color
vcl::vertex::addRectangle<GL_TRIANGLES>(rRenderParameter.maVertices, fX1 + 0.5f, fY1 + 0.5f, fX2 - 0.5f, fY2 - 0.5f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, 0.0f);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rRenderParameter.maColors, rFillColor, fTransparency);
vcl::vertex::addQuadEmptyExtrusionVectors<GL_TRIANGLES>(rRenderParameter.maExtrusionVectors);
}
}
......@@ -213,4 +216,29 @@ void RenderList::addDrawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon,
}
}
bool RenderList::addDrawTextureWithMaskColor(OpenGLTexture& rTexture, const SalColor& rColor, const SalTwoRect& r2Rect)
{
if (!rTexture)
return false;
GLfloat fX1 = r2Rect.mnDestX;
GLfloat fY1 = r2Rect.mnDestY;
GLfloat fX2 = fX1 + r2Rect.mnDestWidth;
GLfloat fY2 = fY1 + r2Rect.mnDestHeight;
checkOverlapping(basegfx::B2DRange(fX1, fY1, fX2, fY2));
GLuint nTextureId = rTexture.Id();
RenderTextureParameters& rTextureParameter = maRenderEntries.back().maTextureParametersMap[nTextureId];
rTextureParameter.maTexture = rTexture;
rTexture.FillCoords<GL_TRIANGLES>(rTextureParameter.maTextureCoords, r2Rect, false);
vcl::vertex::addRectangle<GL_TRIANGLES>(rTextureParameter.maVertices, fX1, fY1, fX2, fY2);
vcl::vertex::addQuadColors<GL_TRIANGLES>(rTextureParameter.maColors, rColor, 0.0f);
return true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -10,6 +10,9 @@
varying vec2 tex_coord;
varying vec2 alpha_coord;
varying vec2 mask_coord;
#ifdef USE_VERTEX_COLORS
varying vec4 vertex_color;
#endif
uniform sampler2D texture;
uniform sampler2D mask;
......@@ -56,7 +59,11 @@ void main()
}
else if (type == TYPE_MASKED_COLOR)
{
#ifdef USE_VERTEX_COLORS
gl_FragColor = vertex_color;
#else
gl_FragColor = color;
#endif
gl_FragColor.a = 1.0 - texelTexture.r;
}
}
......
......@@ -11,10 +11,16 @@ attribute vec4 position;
attribute vec2 tex_coord_in;
attribute vec2 mask_coord_in;
attribute vec2 alpha_coord_in;
#ifdef USE_VERTEX_COLORS
attribute vec4 vertex_color_in;
#endif
varying vec2 tex_coord;
varying vec2 mask_coord;
varying vec2 alpha_coord;
#ifdef USE_VERTEX_COLORS
varying vec4 vertex_color;
#endif
uniform mat4 mvp;
uniform mat4 transform;
......@@ -27,6 +33,9 @@ void main()
tex_coord = tex_coord_in;
mask_coord = mask_coord_in;
alpha_coord = alpha_coord_in;
#ifdef USE_VERTEX_COLORS
vertex_color = vertex_color_in;
#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment