GLDraw: TextureDraw fixes

git-svn-id: svn://ultimatepp.org/upp/trunk@12428 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-10-29 18:15:12 +00:00
parent c046f91915
commit 7748be1778
11 changed files with 39 additions and 32 deletions

View file

@ -110,7 +110,7 @@ LRESULT GLCtrl::GLPane::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
HDC hDC = ps.hdc;
wglMakeCurrent(hDC, s_openGLContext);
glClearDepth(1);
// glClearColor(0, 0, 0, 0);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glEnable(GL_MULTISAMPLE);
Size sz = GetSize();

View file

@ -16,7 +16,6 @@ file
Code.cpp,
VertexData.cpp,
GLTexture.cpp,
DrawTexture.cpp,
Polygon.cpp,
Line.cpp,
Ellipse.cpp,
@ -28,5 +27,6 @@ file
Tpolygon.cpp,
TDrawGL.cpp,
PainterGL.cpp,
TextureDraw.cpp,
todo.txt;

View file

@ -16,11 +16,12 @@ namespace Upp {
struct GLContext2D { // TODO: This should be changed to regular matrix (later)
Sizef vs;
Sizef off = Sizef(-1, 1);
double alpha = 1;
void Set(Size sz) { vs = Sizef(2.0 / sz.cx, -2.0 / sz.cy); }
GLContext2D(Size sz) { Set(sz); }
GLContext2D(Size sz) { Set(vs); }
GLContext2D() {}
};
@ -93,31 +94,12 @@ public:
void GLBind(const Image& img, dword style = TEXTURE_LINEAR|TEXTURE_MIPMAP);
void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, int textureid, Size tsz, const Rect& src);
void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, const GLTexture& img, const Rect& src);
void GLDrawImage(const GLContext2D& dd, const Rectf& rect, const Image& img, const Rect& src);
void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, const GLTexture& img);
void GLDrawImage(const GLContext2D& dd, const Rectf& rect, const Image& img);
class GLTextureDraw {
GLuint framebuffer = 0;
GLuint texture = 0;
GLuint rbo = 0;
Size sz;
int msaa = 0;
public:
void Clear();
void Create(Size sz, int msaa = 0);
GLTexture GetResult();
operator GLTexture() { return GetResult(); }
GLTextureDraw() {}
GLTextureDraw(Size sz, int msaa = 0) { Create(sz, msaa); }
~GLTextureDraw() { Clear(); }
};
class GLVertexData {
struct Data {
int refcount = 1;
@ -284,6 +266,8 @@ private:
void ApplyDash(Vector<Vector<Pointf>>& polyline, int& width);
void DoDrawPolylines(Vector<Vector<Pointf>>& poly, int width, Color color, bool close = false);
void DoDrawPolygons(const Vector<Vector<Pointf>>& path, Color color);
friend class GLTextureDraw;
public:
using Draw::Clip;
@ -299,6 +283,24 @@ public:
~DrawGL();
};
class GLTextureDraw : public DrawGL {
GLuint framebuffer = 0;
GLuint texture = 0;
GLuint rbo = 0;
Size sz;
int msaa = 0;
public:
void Clear();
void Create(Size sz, int msaa = 0);
GLTexture GetResult();
operator GLTexture() { return GetResult(); }
GLTextureDraw() {}
GLTextureDraw(Size sz, int msaa = 0) { Create(sz, msaa); }
~GLTextureDraw() { Clear(); }
};
};
#endif

View file

@ -95,7 +95,7 @@ void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, int textureid, Size
if(tsz.cx * tsz.cy == 0)
return;
static int ioffset = program["offset"];
static int iscale = program["scale"];
static int ialpha = program["alpha"];
@ -107,7 +107,7 @@ void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, int textureid, Size
glBindTexture(GL_TEXTURE_2D, textureid);
GLRectMesh().Draw(
program(ioffset, dd.vs * rect.TopLeft() + Sizef(-1, 1))
program(ioffset, dd.vs * rect.TopLeft() + dd.off)
(iscale, dd.vs * rect.GetSize())
(ialpha, dd.alpha)
(itoffset, Sizef((float)src.left / tsz.cx, (float)src.top / tsz.cy))

View file

@ -36,7 +36,7 @@ void GLDrawPolylines(const GLContext2D& dd, Pointf at, const GLVertexData& mesh,
static int iwidth = program["width"];
static int icolor = program["color"];
program(ioffset, Pointf(dd.vs) * at + Sizef(-1, 1))
program(ioffset, Pointf(dd.vs) * at + dd.off)
(iscale, dd.vs)
(iscale2, scale)
(iwidth, Sizef(width / 2, width / 2))

View file

@ -57,7 +57,7 @@ void GLDrawPolygons(const GLContext2D& dd, bool generic, Pointf at, const GLVert
static int iscale = program["scale"];
static int icolor = program["color"];
program(ioffset, Pointf(dd.vs) * at + Sizef(-1, 1))
program(ioffset, Pointf(dd.vs) * at + dd.off)
(iscale, dd.vs * scale);
if(generic) {

View file

@ -18,7 +18,7 @@ void Ellipse(GLTriangles& tr, Pointf center, Sizef radius, Color color,
step[i] = 256 / min(s, 256);
}
}
int rmin = min(radius.cx, radius.cy);
double rmin = min(radius.cx, radius.cy);
if(rmin <= 1e-100)
return;

View file

@ -22,6 +22,7 @@ void GLTextureDraw::Clear()
GLTexture GLTextureDraw::GetResult()
{
ASSERT(texture);
Flush();
GLTexture t;
if(msaa > 1) {
GLuint framebuffer2, texture2, rbo2;
@ -31,7 +32,7 @@ GLTexture GLTextureDraw::GetResult()
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sz.cx, sz.cy, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sz.cx, sz.cy, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -80,13 +81,13 @@ void GLTextureDraw::Create(Size sz_, int msaa_)
if(msaa > 1) {
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, msaa, GL_RGBA, sz.cx, sz.cy, GL_TRUE);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, msaa, GL_RGB, sz.cx, sz.cy, GL_TRUE);
glEnable(GL_MULTISAMPLE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
}
else {
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sz.cx, sz.cy, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sz.cx, sz.cy, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -109,6 +110,10 @@ void GLTextureDraw::Create(Size sz_, int msaa_)
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, sz.cx, sz.cy);
DrawGL::Init(sz, 1);
dd.vs.cy *= -1;
dd.off = Sizef(-1, -1);
}
};

View file

@ -43,7 +43,7 @@ void GLTriangles::Draw(const GLContext2D& dd)
glDisable(GL_DEPTH_TEST);
// glDepthFunc(GL_LEQUAL);
program(ioffset, Sizef(-1, 1))
program(ioffset, dd.off)
(iscale, dd.vs)
;

View file

@ -79,7 +79,6 @@ GLVertexData& GLVertexData::Index(const int *indices, int count)
void GLVertexData::Draw(int mode) const
{
if(data) {
// RTIMING("GLVertexData::Draw");
GL_TIMING("GLVertexData::Draw");
glBindVertexArray(data->VAO);
glDrawElements(mode, data->elements, GL_UNSIGNED_INT, 0);

View file

@ -2,6 +2,7 @@
- colored texture paints (optimize text)
- colored alpha texture paints
- unify texture draw code
- GLTextureDraw - correct RGBA handling
- make banded glyphs
- make alpha textures