|
@@ -12,7 +12,7 @@ using namespace mnd;
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
-Texture::Texture(QOpenGLFunctions_3_0& gl, const Bitmap<RGBColor>& bitmap, GLint param) :
|
|
|
+Texture::Texture(QOpenGLFunctions& gl, const Bitmap<RGBColor>& bitmap, GLint param) :
|
|
|
gl{ gl }
|
|
|
{
|
|
|
gl.glGenTextures(1, &id);
|
|
@@ -59,8 +59,47 @@ void Texture::bind(void) const
|
|
|
}
|
|
|
|
|
|
|
|
|
-void Texture::drawRect(float x, float y, float width, float height)
|
|
|
+void Texture::drawRect(QOpenGLShaderProgram* program,
|
|
|
+ float x, float y, float width, float height,
|
|
|
+ float tx, float ty, float tw, float th)
|
|
|
{
|
|
|
+#if 1
|
|
|
+ GLfloat const vertices[] = {
|
|
|
+ x, y, 0.0f,
|
|
|
+ x, y + height, 0.0f,
|
|
|
+ x + width, y + height, 0.0f,
|
|
|
+ x + width, y, 0.0f,
|
|
|
+ };
|
|
|
+
|
|
|
+ GLfloat const texCoords[] = {
|
|
|
+ tx, ty,
|
|
|
+ tx, ty + th,
|
|
|
+ tx + tw, ty + th,
|
|
|
+ tx + tw, ty,
|
|
|
+ };
|
|
|
+
|
|
|
+ QColor color(255, 255, 255);
|
|
|
+
|
|
|
+ int vertexLoc = program->attributeLocation("vertex");
|
|
|
+ int texCoordsLoc = program->attributeLocation("texCoord");
|
|
|
+ int colorLocation = program->uniformLocation("color");
|
|
|
+ int texLoc = program->uniformLocation("tex");
|
|
|
+ program->enableAttributeArray(vertexLoc);
|
|
|
+ program->enableAttributeArray(texCoordsLoc);
|
|
|
+ program->setAttributeArray(vertexLoc, vertices, 3);
|
|
|
+ program->setAttributeArray(texCoordsLoc, texCoords, 2);
|
|
|
+ program->setUniformValue(colorLocation, color);
|
|
|
+
|
|
|
+
|
|
|
+ auto& gl3 = *QOpenGLContext::currentContext()->functions();
|
|
|
+ gl3.glUniform1i(texLoc, 0);
|
|
|
+ gl3.glActiveTexture(GL_TEXTURE0 + 0);
|
|
|
+ gl3.glBindTexture(GL_TEXTURE_2D, id);
|
|
|
+ gl3.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
+
|
|
|
+ program->disableAttributeArray(vertexLoc);
|
|
|
+ program->disableAttributeArray(texCoordsLoc);
|
|
|
+#else
|
|
|
gl.glColor3ub(255, 255, 255);
|
|
|
gl.glEnable(GL_TEXTURE_2D);
|
|
|
bind();
|
|
@@ -75,6 +114,7 @@ void Texture::drawRect(float x, float y, float width, float height)
|
|
|
gl.glVertex2f(x + width, y + height);
|
|
|
gl.glEnd();
|
|
|
gl.glDisable(GL_TEXTURE_2D);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
@@ -88,7 +128,9 @@ TextureClip::~TextureClip(void)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-void TextureClip::drawRect(float x, float y, float width, float height)
|
|
|
+
|
|
|
+void TextureClip::drawRect(QOpenGLShaderProgram* program,
|
|
|
+ float x, float y, float width, float height)
|
|
|
{
|
|
|
/*
|
|
|
auto& gl = texture->gl;
|
|
@@ -106,17 +148,8 @@ void TextureClip::drawRect(float x, float y, float width, float height)
|
|
|
gl.glVertex2f(x + width, y + height);
|
|
|
gl.glEnd();
|
|
|
gl.glDisable(GL_TEXTURE_2D);*/
|
|
|
-
|
|
|
- int vertexLocation = program->attributeLocation("vertex");
|
|
|
- program->enableAttributeArray(vertexLocation);
|
|
|
- program->setAttributeArray(vertexLocation, triangleVertices, 3);
|
|
|
- program->setUniformValue(matrixLocation, pmvMatrix);
|
|
|
- program->setUniformValue(colorLocation, color);
|
|
|
-
|
|
|
- auto& gl3 = *QOpenGLContext::currentContext()->functions();
|
|
|
- gl3.glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
|
-
|
|
|
- program->disableAttributeArray(vertexLocation);
|
|
|
+ texture->drawRect(program, x, y, width, height,
|
|
|
+ tx, ty, tw, th);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -147,11 +180,13 @@ QuadImage::~QuadImage(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
-void QuadImage::drawRect(float x, float y, float width, float height)
|
|
|
+void QuadImage::drawRect(QOpenGLShaderProgram* program,
|
|
|
+ float x, float y, float width, float height)
|
|
|
{
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
- this->cells[i][j]->drawRect(x + i * 0.5f * width,
|
|
|
+ this->cells[i][j]->drawRect(program,
|
|
|
+ x + i * 0.5f * width,
|
|
|
y + j * 0.5f * height,
|
|
|
width * 0.5f,
|
|
|
height * 0.5f);
|
|
@@ -349,7 +384,7 @@ MandelView::MandelView(mnd::MandelGenerator* generator, MandelWidget& owner) :
|
|
|
}*/
|
|
|
Bitmap<RGBColor> emp(1, 1);
|
|
|
emp.get(0, 0) = RGBColor{ 0, 0, 0 };
|
|
|
- auto& gl = *QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
|
|
|
+ auto& gl = *QOpenGLContext::currentContext()->functions();
|
|
|
empty = std::make_unique<Texture>(gl, emp, GL_NEAREST);
|
|
|
connect(&calcer, &Calcer::done, this, &MandelView::cellReady);
|
|
|
}
|
|
@@ -503,7 +538,7 @@ GridElement* MandelView::searchUnder(int level, GridIndex i, GridIndex j, int re
|
|
|
}
|
|
|
|
|
|
|
|
|
-void MandelView::paint(const mnd::MandelViewport& mvp, QPainter& qp)
|
|
|
+void MandelView::paint(const mnd::MandelViewport& mvp)
|
|
|
{
|
|
|
mnd::Real dpp = mvp.width / width;
|
|
|
int level = getLevel(dpp) - 1;
|
|
@@ -541,7 +576,7 @@ void MandelView::paint(const mnd::MandelViewport& mvp, QPainter& qp)
|
|
|
}
|
|
|
|
|
|
if (t != nullptr) {
|
|
|
- t->img->drawRect(float(x), float(y), float(w), float(w));
|
|
|
+ t->img->drawRect(this->owner.program,float(x), float(y), float(w), float(w));
|
|
|
/*glBegin(GL_LINE_LOOP);
|
|
|
glVertex2f(float(x), float(y));
|
|
|
glVertex2f(float(x) + float(w), float(y));
|
|
@@ -555,7 +590,8 @@ void MandelView::paint(const mnd::MandelViewport& mvp, QPainter& qp)
|
|
|
}
|
|
|
else {
|
|
|
calcer.calc(grid, level, i, j, 1000);
|
|
|
- this->empty->drawRect(float(x), float(y), float(w), float(w));
|
|
|
+ this->empty->drawRect(this->owner.program,
|
|
|
+ float(x), float(y), float(w), float(w));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -563,7 +599,7 @@ void MandelView::paint(const mnd::MandelViewport& mvp, QPainter& qp)
|
|
|
|
|
|
void MandelView::cellReady(int level, GridIndex i, GridIndex j, Bitmap<RGBColor>* bmp)
|
|
|
{
|
|
|
- auto& gl = *QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_0>();
|
|
|
+ auto& gl = *QOpenGLContext::currentContext()->functions();
|
|
|
this->getGrid(level).setCell(i, j,
|
|
|
std::make_unique<GridElement>(true, std::make_shared<TextureClip>(std::make_shared<Texture>(gl, *bmp))));
|
|
|
delete bmp;
|
|
@@ -679,20 +715,28 @@ void MandelWidget::initializeGL(void)
|
|
|
program = new QOpenGLShaderProgram{ this->context() };
|
|
|
bool vert = program->addShaderFromSourceCode(QOpenGLShader::Vertex,
|
|
|
"attribute highp vec4 vertex;\n"
|
|
|
+ "attribute highp vec2 texCoord;\n"
|
|
|
"uniform highp mat4 matrix;\n"
|
|
|
+ "varying highp vec2 texc;\n"
|
|
|
"void main(void)\n"
|
|
|
"{\n"
|
|
|
" gl_Position = matrix * vertex;\n"
|
|
|
+ " texc = texCoord;\n"
|
|
|
"}");
|
|
|
bool frag = program->addShaderFromSourceCode(QOpenGLShader::Fragment,
|
|
|
"uniform mediump vec4 color;\n"
|
|
|
+ "varying highp vec2 texc;\n"
|
|
|
+ "uniform sampler2D tex;\n"
|
|
|
"void main(void)\n"
|
|
|
"{\n"
|
|
|
- " gl_FragColor = color;\n"
|
|
|
+ " gl_FragColor = color * texture2D(tex, texc);\n"
|
|
|
+// " gl_FragColor.g = 0.3;\n"
|
|
|
"}");
|
|
|
//program.link();
|
|
|
bool bound = program->bind();
|
|
|
|
|
|
+ //gl3.glBindSampler(0, id);
|
|
|
+
|
|
|
mandelView = nullptr;
|
|
|
requestRecalc();
|
|
|
}
|
|
@@ -744,7 +788,6 @@ void MandelWidget::paintGL(void)
|
|
|
|
|
|
gl.glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
- updateAnimations();
|
|
|
|
|
|
QPainter painter{ this };
|
|
|
|
|
@@ -756,6 +799,9 @@ void MandelWidget::paintGL(void)
|
|
|
drawInfo();
|
|
|
if (selectingPoint)
|
|
|
drawPoint();*/
|
|
|
+ //QPainter painter{ this };
|
|
|
+ updateAnimations();
|
|
|
+ mandelView->paint(this->currentViewport);
|
|
|
|
|
|
static GLfloat const triangleVertices[] = {
|
|
|
0.0, 20, 0.0f,
|