Skip to content

Commit

Permalink
let matrix be handled by qt scenegraph or by the opengl engine, remov…
Browse files Browse the repository at this point in the history
…ed engine class from scenegraph, get context from m_waveformRenderer, various cleanups
  • Loading branch information
m0dB authored and m0dB committed Oct 19, 2024
1 parent bf7ed15 commit 1e57aae
Show file tree
Hide file tree
Showing 57 changed files with 487 additions and 466 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,6 @@ if(QOPENGL)
src/shaders/vinylqualityshader.cpp
src/util/opengltexture2d.cpp
src/waveform/renderers/allshader/digitsrenderer.cpp
src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp
src/waveform/renderers/allshader/waveformrenderbackground.cpp
src/waveform/renderers/allshader/waveformrenderbeat.cpp
src/waveform/renderers/allshader/waveformrenderer.cpp
Expand Down
16 changes: 0 additions & 16 deletions src/rendergraph/common/engine.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/rendergraph/common/rendergraph/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Texture;

class rendergraph::Texture {
public:
Texture(Context& context, const QImage& image);
Texture(Context* pContext, const QImage& image);

BaseTexture* backendTexture() const {
return m_pTexture.get();
Expand Down
13 changes: 0 additions & 13 deletions src/rendergraph/common/rendergraph/treenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,11 @@ class rendergraph::TreeNode {
return m_pBackendNode;
}

virtual void initialize() {
}
virtual void resize(int, int) {
}

void setEngine(Engine* pEngine) {
m_pEngine = pEngine;
}
Engine* engine() const {
return m_pEngine;
}

private:
void onAppendChildNode(TreeNode* pChild);
void onRemoveAllChildNodes();
void onRemoveChildNode(TreeNode* pChild);

Engine* m_pEngine{};
rendergraph::BaseNode* m_pBackendNode;
TreeNode* m_pParent{};
std::unique_ptr<TreeNode> m_pFirstChild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,48 @@ class rendergraph::RGBAVertexUpdater {
rgbar.z(),
rgbar.w());
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}
void addTriangle(QVector2D p1, QVector2D p2, QVector2D p3, QVector4D rgba) {
addTriangle(p1.x(),
p1.y(),
p2.x(),
p2.y(),
p3.x(),
p3.y(),
rgba.x(),
rgba.y(),
rgba.z(),
rgba.w());
}
void addTriangle(QVector2D p1,
QVector2D p2,
QVector2D p3,
QVector4D rgba1,
QVector4D rgba2,
QVector4D rgba3) {
addTriangle(p1.x(),
p1.y(),
p2.x(),
p2.y(),
p3.x(),
p3.y(),
rgba1.x(),
rgba1.y(),
rgba1.z(),
rgba1.w(),
rgba2.x(),
rgba2.y(),
rgba2.z(),
rgba2.w(),
rgba3.x(),
rgba3.y(),
rgba3.z(),
rgba3.w());
}

private:
void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b, float a) {
addTriangle(x1, y1, x2, y1, x1, y2, r, g, b, a);
addTriangle(x1, y2, x2, y2, x2, y1, r, g, b, a);
Expand Down Expand Up @@ -127,11 +169,6 @@ class rendergraph::RGBAVertexUpdater {
*m_pWrite++ = Geometry::RGBAColoredPoint2D{x2, y2, r2, g2, b2, a2};
*m_pWrite++ = Geometry::RGBAColoredPoint2D{x3, y3, r3, g3, b3, a3};
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
Geometry::RGBAColoredPoint2D* const m_pData;
Geometry::RGBAColoredPoint2D* m_pWrite;
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ class rendergraph::RGBVertexUpdater {
rgbr.y(),
rgbr.z());
}
void addTriangle(QVector2D p1, QVector2D p2, QVector2D p3, QVector3D rgb) {
addTriangle(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y(), rgb.x(), rgb.y(), rgb.z());
}
void addTriangle(QVector2D p1,
QVector2D p2,
QVector2D p3,
QVector3D rgb1,
QVector3D rgb2,
QVector3D rgb3) {
addTriangle(p1.x(),
p1.y(),
p2.x(),
p2.y(),
p3.x(),
p3.y(),
rgb1.x(),
rgb1.y(),
rgb1.z(),
rgb2.x(),
rgb2.y(),
rgb2.z(),
rgb3.x(),
rgb3.y(),
rgb3.z());
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b) {
addTriangle(x1, y1, x2, y1, x1, y2, r, g, b);
addTriangle(x1, y2, x2, y2, x2, y1, r, g, b);
Expand All @@ -66,8 +96,8 @@ class rendergraph::RGBVertexUpdater {
float r2,
float g2,
float b2) {
addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r2, g2, b2, r1, g1, b1);
addTriangle(x1, y2, x2, y2, x2, y1, r1, g1, b1, r2, g2, b2, r2, g2, b2);
addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r1, g1, b1, r2, g2, b2);
addTriangle(x1, y2, x2, y2, x2, y1, r2, g2, b2, r2, g2, b2, r1, g1, b1);
}
void addRectangleHGradient(
float x1,
Expand Down Expand Up @@ -105,23 +135,16 @@ class rendergraph::RGBVertexUpdater {
float r1,
float g1,
float b1,

float r2,
float g2,
float b2,

float r3,
float g3,
float b3) {
*m_pWrite++ = Geometry::RGBColoredPoint2D{x1, y1, r1, g1, b1};
*m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r2, g2, b2};
*m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r3, g3, b3};
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
Geometry::RGBColoredPoint2D* const m_pData;
Geometry::RGBColoredPoint2D* m_pWrite;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,38 @@ class rendergraph::TexturedVertexUpdater {
: m_pData(pData),
m_pWrite(pData) {
}
void addRectangle(
QVector2D lt, QVector2D rb) {
addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), 0.f, 0.f, 1.f, 1.f);
}
void addRectangle(
QVector2D lt, QVector2D rb, QVector2D tlr, QVector2D trb) {
addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), tlr.x(), tlr.y(), trb.x(), trb.y());
}
void addTriangle(QVector2D p1,
QVector2D p2,
QVector2D p3,
QVector2D tp1,
QVector2D tp2,
QVector2D tp3) {
addTriangle(p1.x(),
p1.y(),
p2.x(),
p2.y(),
p3.x(),
p3.y(),
tp1.x(),
tp1.y(),
tp2.x(),
tp2.y(),
tp3.x(),
tp3.y());
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
void addRectangle(
float x1, float y1, float x2, float y2, float tx1, float ty1, float tx2, float ty2) {
addTriangle(x1, y1, x2, y1, x1, y2, tx1, ty1, tx2, ty1, tx1, ty2);
Expand All @@ -37,11 +65,6 @@ class rendergraph::TexturedVertexUpdater {
*m_pWrite++ = Geometry::TexturedPoint2D{x2, y2, tx2, ty2};
*m_pWrite++ = Geometry::TexturedPoint2D{x3, y3, tx3, ty3};
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
Geometry::TexturedPoint2D* const m_pData;
Geometry::TexturedPoint2D* m_pWrite;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class rendergraph::VertexUpdater {
QVector2D lt, QVector2D rb) {
addRectangle(lt.x(), lt.y(), rb.x(), rb.y());
}
void addTriangle(QVector2D p1, QVector2D p2, QVector2D p3) {
addTriangle(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y());
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
void addRectangle(
float x1,
float y1,
Expand All @@ -27,11 +35,6 @@ class rendergraph::VertexUpdater {
*m_pWrite++ = Geometry::Point2D{x2, y2};
*m_pWrite++ = Geometry::Point2D{x3, y3};
}
int index() const {
return static_cast<int>(m_pWrite - m_pData);
}

private:
Geometry::Point2D* const m_pData;
Geometry::Point2D* m_pWrite;
};
52 changes: 52 additions & 0 deletions src/rendergraph/examples/common/examplenode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "examplenode.h"

#include <QColor>
#include <QMatrix4x4>
#include <QVector2D>

#include "rendergraph/geometry.h"
#include "rendergraph/material/rgbmaterial.h"
#include "rendergraph/material/texturematerial.h"
#include "rendergraph/material/unicolormaterial.h"
#include "rendergraph/vertexupdaters/rgbvertexupdater.h"
#include "rendergraph/vertexupdaters/texturedvertexupdater.h"
#include "rendergraph/vertexupdaters/vertexupdater.h"

using namespace rendergraph;

ExampleNode::ExampleNode(rendergraph::Context* pContext) {
{
TreeNode::appendChildNode(std::make_unique<GeometryNode>());
auto pNode = static_cast<GeometryNode*>(TreeNode::lastChild());
pNode->initForRectangles<TextureMaterial>(1);
auto& material = dynamic_cast<TextureMaterial&>(pNode->material());
material.setTexture(std::make_unique<Texture>(
pContext, QImage(":/example/images/test.png")));
TexturedVertexUpdater vertexUpdater{
pNode->geometry().vertexDataAs<Geometry::TexturedPoint2D>()};
vertexUpdater.addRectangle({0, 0}, {100, 100}, {0.f, 0.f}, {1.f, 1.f});
}
{
TreeNode::appendChildNode(std::make_unique<GeometryNode>());
auto pNode = static_cast<GeometryNode*>(TreeNode::lastChild());
pNode->initForRectangles<rendergraph::UniColorMaterial>(2);
pNode->material().setUniform(1, QColor(255, 127, 0));
pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles);
rendergraph::VertexUpdater vertexUpdater{
pNode->geometry()
.vertexDataAs<rendergraph::Geometry::Point2D>()};
vertexUpdater.addRectangle({100, 100}, {160, 160});
vertexUpdater.addRectangle({200, 160}, {240, 190});
}
{
TreeNode::appendChildNode(std::make_unique<GeometryNode>());
auto pNode = static_cast<GeometryNode*>(TreeNode::lastChild());
pNode->initForRectangles<rendergraph::RGBMaterial>(2);
pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles);
rendergraph::RGBVertexUpdater vertexUpdater{
pNode->geometry().vertexDataAs<Geometry::RGBColoredPoint2D>()};
vertexUpdater.addRectangle({300, 100}, {340, 140}, {1.f, 0.f, 0.5f});
vertexUpdater.addRectangleHGradient(
{340, 100}, {440, 130}, {0.f, 1.f, 0.5f}, {0.5f, 0.f, 1.f});
}
}
12 changes: 12 additions & 0 deletions src/rendergraph/examples/common/examplenode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "rendergraph/geometrynode.h"
#include "rendergraph/node.h"
#include "rendergraph/texture.h"

namespace rendergraph {
class ExampleNode;
} // namespace rendergraph

class rendergraph::ExampleNode : public rendergraph::Node {
public:
ExampleNode(rendergraph::Context* pContext);
};
Loading

0 comments on commit 1e57aae

Please sign in to comment.