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

opengl: VertexUtils, deferred flush update, remove unneeded calls

VertexUtils - collection of utils for working with Vertices.

Add deferred flush to some places directly where it is called
indirectly. This is to assure that we don't produce regressions
if we change the behavior in the future.

drawAlphaBitmap is the same as drawBitmap so when drawBitmap is
called just redirect to drawAlphaBitmap

Change-Id: Ibef1ba88865856d92d9e93734cf5d6561af785c0
üst f9bb1341
...@@ -15,16 +15,13 @@ ...@@ -15,16 +15,13 @@
#include <o3tl/make_unique.hxx> #include <o3tl/make_unique.hxx>
#include "opengl/texture.hxx" #include "opengl/texture.hxx"
#include "opengl/VertexUtils.hxx"
#include <memory> #include <memory>
struct TextureDrawParameters struct TextureDrawParameters
{ {
std::vector<GLfloat> maVertices; std::vector<GLfloat> maVertices;
std::vector<GLfloat> maTextureCoords; std::vector<GLfloat> maTextureCoords;
GLint getNumberOfVertices()
{
return maVertices.size() / 2;
}
}; };
struct AccumulatedTexturesEntry struct AccumulatedTexturesEntry
...@@ -41,29 +38,13 @@ struct AccumulatedTexturesEntry ...@@ -41,29 +38,13 @@ struct AccumulatedTexturesEntry
TextureDrawParameters& aDrawParameters = maColorTextureDrawParametersMap[aColor]; TextureDrawParameters& aDrawParameters = maColorTextureDrawParametersMap[aColor];
rTexture.FillCoords<GL_TRIANGLES>(aDrawParameters.maTextureCoords, r2Rect, false); rTexture.FillCoords<GL_TRIANGLES>(aDrawParameters.maTextureCoords, r2Rect, false);
GLfloat nX1 = r2Rect.mnDestX; GLfloat fX1 = r2Rect.mnDestX;
GLfloat nY1 = r2Rect.mnDestY; GLfloat fY1 = r2Rect.mnDestY;
GLfloat nX2 = r2Rect.mnDestX + r2Rect.mnDestWidth; GLfloat fX2 = fX1 + r2Rect.mnDestWidth;
GLfloat nY2 = r2Rect.mnDestY + r2Rect.mnDestHeight; GLfloat fY2 = fY1 + r2Rect.mnDestHeight;
auto& rVertices = aDrawParameters.maVertices;
rVertices.push_back(nX1);
rVertices.push_back(nY1);
rVertices.push_back(nX2);
rVertices.push_back(nY1);
rVertices.push_back(nX1);
rVertices.push_back(nY2);
rVertices.push_back(nX1);
rVertices.push_back(nY2);
rVertices.push_back(nX2);
rVertices.push_back(nY1);
rVertices.push_back(nX2); std::vector<GLfloat>& rVertices = aDrawParameters.maVertices;
rVertices.push_back(nY2); vcl::vertex::addRectangle<GL_TRIANGLES>(rVertices, fX1, fY1, fX2, fY2);
} }
}; };
...@@ -113,6 +94,6 @@ public: ...@@ -113,6 +94,6 @@ public:
} }
}; };
#endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H #endif // INCLUDED_VCL_INC_OPENGL_ACCUMULATEDTEXTURES_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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_VERTEXUTILS_H
#define INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
#include <glm/gtx/norm.hpp>
namespace vcl
{
namespace vertex
{
template<GLenum TYPE>
inline void addRectangle(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
template<>
inline void addRectangle<GL_TRIANGLES>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
{
rVertices.insert(rVertices.end(), {
x1, y1, x2, y1, x1, y2,
x1, y2, x2, y1, x2, y2
});
}
template<>
inline void addRectangle<GL_TRIANGLE_FAN>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
{
rVertices.insert(rVertices.end(), {
x1, y2, x1, y1,
x2, y1, x2, y2
});
}
inline void addLineVertex(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors, glm::vec2 point, glm::vec2 extrusionVector, float length)
{
rVertices.push_back(point.x);
rVertices.push_back(point.y);
rExtrusionVectors.push_back(extrusionVector.x);
rExtrusionVectors.push_back(extrusionVector.y);
rExtrusionVectors.push_back(length);
}
inline void addLineVertexPair(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors, const glm::vec2& point, const glm::vec2& extrusionVector, float length)
{
addLineVertex(rVertices, rExtrusionVectors, point, -extrusionVector, -length);
addLineVertex(rVertices, rExtrusionVectors, point, extrusionVector, length);
}
inline void addLinePointFirst(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors,
glm::vec2 point, glm::vec2 extrusionVector, float length)
{
addLineVertex(rVertices, rExtrusionVectors, point, -extrusionVector, -length);
addLineVertex(rVertices, rExtrusionVectors, point, extrusionVector, length);
}
inline void addLinePointNext(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors,
glm::vec2 prevPoint, glm::vec2 prevExtrusionVector, float prevLength,
glm::vec2 currPoint, glm::vec2 currExtrusionVector, float currLength)
{
addLineVertex(rVertices, rExtrusionVectors, currPoint, -currExtrusionVector, -currLength);
addLineVertex(rVertices, rExtrusionVectors, currPoint, -currExtrusionVector, -currLength);
addLineVertex(rVertices, rExtrusionVectors, prevPoint, prevExtrusionVector, prevLength);
addLineVertex(rVertices, rExtrusionVectors, currPoint, currExtrusionVector, currLength);
}
inline glm::vec2 normalize(const glm::vec2& vector)
{
if (glm::length(vector) > 0.0)
return glm::normalize(vector);
return vector;
}
}} // end vcl::vertex
#endif // INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
/* 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