diff --git a/uppsrc/Core/Util.h b/uppsrc/Core/Util.h index 38f1969e3..bc28d2f14 100644 --- a/uppsrc/Core/Util.h +++ b/uppsrc/Core/Util.h @@ -134,43 +134,6 @@ INITBLOCK { AddIniInfo(#var, AsStringIniCurrent_##var, AsStringIniDefault_##var, #define INI_STRING(var, def, info) String& DefRef_##var() { static String x; return x; }\ INI_TYPE(var, def, info, String, IniString, DefRef_##var); -/* -#define INI_BOOL(var, def, info)\ -bool DefIni_##var() { return def; }\ -IniBool var = { #var, DefIni_##var };\ -String AsStringIniCurrent_##var() { return AsString(var); } \ -String AsStringIniDefault_##var() { return AsString(DefIni_##var()); } \ -INITBLOCK { AddIniInfo(#var, AsStringIniCurrent_##var, AsStringIniDefault_##var, info); } - -#define INI_STRING(var, def, info)\ -String DefIni_##var() { return def; }\ -IniString var = { #var, DefIni_##var };\ -String AsStringIniCurrent_##var() { return AsString(var); } \ -String AsStringIniDefault_##var() { return AsString(DefIni_##var()); } \ -INITBLOCK { AddIniInfo(#var, AsStringIniCurrent_##var, AsStringIniDefault_##var, info); } - -#define INI_INT(var, def, info)\ -int DefIni_##var() { return def; }\ -IniInt var = { #var, DefIni_##var };\ -String AsStringIniCurrent_##var() { return AsString(var); } \ -String AsStringIniDefault_##var() { return AsString(DefIni_##var()); } \ -INITBLOCK { AddIniInfo(#var, AsStringIniCurrent_##var, AsStringIniDefault_##var, info); } - -#define INI_INT64(var, def, info)\ -int64 DefIni_##var() { return def; }\ -Ini64Int var = { #var, DefIni_##var };\ -String AsStringIniCurrent_##var() { return AsString(var); } \ -String AsStringIniDefault_##var() { return AsString(DefIni_##var()); } \ -INITBLOCK { AddIniInfo(#var, AsStringIniCurrent_##var, AsStringIniDefault_##var, info); } - -#define INI_DOUBLE(var, def, info)\ -double DefIni_##var() { return def; }\ -IniDouble var = { #var, DefIni_##var };\ -String AsStringIniCurrent_##var() { return AsString(var); } \ -String AsStringIniDefault_##var() { return AsString(DefIni_##var()); } \ -INITBLOCK { AddIniInfo(#var, AsStringIniCurrent_##var, AsStringIniDefault_##var, info); } -*/ - VectorMap LoadIniStream(Stream &in); VectorMap LoadIniFile(const char *filename); diff --git a/uppsrc/Draw/SDrawPut.cpp b/uppsrc/Draw/SDrawPut.cpp index 6e8da9522..7d5ee89a7 100644 --- a/uppsrc/Draw/SDrawPut.cpp +++ b/uppsrc/Draw/SDrawPut.cpp @@ -22,14 +22,10 @@ struct sColorize : public ImageMaker void SDraw::PutImage(Point p, const Image& img, const Rect& src, Color color) { - if(!IsNull(color)) { - sColorize m; - m.img = img; - m.color = color; - PutImage(p, MakeImage(m), src); - } - else - PutImage(p, img, src); + sColorize m; + m.img = img; + m.color = color; + PutImage(p, MakeImage(m), src); } void SDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color) @@ -38,8 +34,14 @@ void SDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Colo const Vector& clip = cloff.Top().clip; for(int i = 0; i < clip.GetCount(); i++) { Rect cr = clip[i] & sr; - if(!cr.IsEmpty()) - PutImage(cr.TopLeft(), img, Rect(cr.TopLeft() - sr.TopLeft() + src.TopLeft(), cr.GetSize()), color); + if(!cr.IsEmpty()) { + Point p = cr.TopLeft(); + Rect r(cr.TopLeft() - sr.TopLeft() + src.TopLeft(), cr.GetSize()); + if(IsNull(color)) + PutImage(p, img, r); + else + PutImage(p, img, r, color); + } } } diff --git a/uppsrc/Draw/SDrawText.cpp b/uppsrc/Draw/SDrawText.cpp index 16812eef9..7a96d9fed 100644 --- a/uppsrc/Draw/SDrawText.cpp +++ b/uppsrc/Draw/SDrawText.cpp @@ -41,7 +41,7 @@ void SDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Co { sMakeTextGlyph g; g.font = font; - g.color = ink; + g.color = White(); g.angle = angle; g.draw = this; for(int i = 0; i < n; i++) { @@ -52,14 +52,14 @@ void SDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Co int n = at.x + at.y; Size bandsz(2 * n, 32); for(int yy = 0; yy < n; yy += bandsz.cy) { - Image m = RenderGlyph(Point(0, -yy), angle, g.chr, font, ink, bandsz); - SysDrawImageOp(x, y + yy, m, m.GetSize(), Null); + Image m = RenderGlyph(Point(0, -yy), angle, g.chr, font, White(), bandsz); + SysDrawImageOp(x, y + yy, m, m.GetSize(), ink); } } else { Image m = MakeImage(g); Point h = m.GetHotSpot(); - SysDrawImageOp(x - h.x, y - h.y, m, m.GetSize(), Null); + SysDrawImageOp(x - h.x, y - h.y, m, m.GetSize(), ink); } x += dx ? *dx++ : font[g.chr]; } diff --git a/uppsrc/GLDraw/GLDraw.h b/uppsrc/GLDraw/GLDraw.h index 593772c30..335c0a299 100644 --- a/uppsrc/GLDraw/GLDraw.h +++ b/uppsrc/GLDraw/GLDraw.h @@ -60,7 +60,10 @@ class GLDraw : public SDraw { uint64 context; public: - virtual void PutImage(Point p, const Image& m, const Rect& src); + virtual void PutImage(Point p, const Image& img, const Rect& src); +#ifdef GL_USE_SHADERS + virtual void PutImage(Point p, const Image& img, const Rect& src, Color color); +#endif virtual void PutRect(const Rect& r, Color color); void Init(Size sz, uint64 context = 0); diff --git a/uppsrc/GLDraw/GLDrawS.cpp b/uppsrc/GLDraw/GLDrawS.cpp index 8100fd866..2548401fa 100644 --- a/uppsrc/GLDraw/GLDrawS.cpp +++ b/uppsrc/GLDraw/GLDrawS.cpp @@ -1,12 +1,14 @@ #include "GLDraw.h" +#define LTIMING(x) // RTIMING(x) + #ifdef GL_USE_SHADERS namespace Upp { int u_imagetexture; -GLProgram gl_image, gl_rect; +GLProgram gl_image, gl_image_colored, gl_rect; void CheckError() { @@ -30,8 +32,8 @@ void initializeGL() "{ \n" " gl_Position = u_projection * a_position; \n" " v_texCoord = a_texCoord; \n" - "} \n", - + "} \n" + , "#ifdef GL_ES\n" "precision mediump float; \n" "precision mediump int; \n" @@ -48,6 +50,40 @@ void initializeGL() glUniform1i(gl_image.GetUniform("s_texture"), 0); + gl_image_colored.Create( + "attribute vec4 a_position; \n" + "attribute vec2 a_texCoord; \n" + "attribute vec4 a_color; \n" + "uniform mat4 u_projection; \n" + "varying vec2 v_texCoord; \n" + "varying vec4 v_color; \n" + "void main() \n" + "{ \n" + " gl_Position = u_projection * a_position; \n" + " v_texCoord = a_texCoord; \n" + " v_color = a_color * vec4((1.0 / 255.0), (1.0 / 255.0), (1.0 / 255.0), 1); \n" + "} \n" + , + "#ifdef GL_ES\n" + "precision mediump float; \n" + "precision mediump int; \n" + "#endif\n" + "varying vec2 v_texCoord; \n" + "varying vec4 v_color; \n" + "uniform sampler2D s_texture; \n" + "void main() \n" + "{ \n" + " gl_FragColor = texture2D(s_texture, v_texCoord); \n" + " gl_FragColor = v_color;\n" + " gl_FragColor[3] = texture2D(s_texture, v_texCoord)[3]; \n" + "} \n", + ATTRIB_VERTEX, "a_position", + ATTRIB_TEXPOS, "a_texCoord", + ATTRIB_COLOR, "a_color" + ); + + glUniform1i(gl_image_colored.GetUniform("s_texture"), 0); + gl_rect.Create( "attribute vec4 a_position; \n" "attribute vec4 a_color; \n" @@ -57,14 +93,13 @@ void initializeGL() "{ \n" " gl_Position = u_projection * a_position; \n" " v_color = a_color * vec4((1.0 / 255.0), (1.0 / 255.0), (1.0 / 255.0), 1); \n" - "}", - + "}" + , "#ifdef GL_ES\n" "precision mediump float;\n" "precision mediump int;\n" "#endif\n" "varying vec4 v_color;\n" - "\n" "void main()\n" "{\n" " gl_FragColor = v_color;\n" @@ -101,6 +136,7 @@ void GLOrtho(float left, float right, float bottom, float top, float near, float void GLDraw::PutRect(const Rect& rect, Color color) { + LTIMING("PutRect"); gl_rect.Use(); GLshort vertex[] = { @@ -143,12 +179,13 @@ void GLDraw::PutRect(const Rect& rect, Color color) void GLDraw::PutImage(Point p, const Image& img, const Rect& src) { + LTIMING("PutImage"); gl_image.Use(); Rect s = src & img.GetSize(); Rect r(p, s.GetSize()); - GLshort vertexCoords[] = { + GLshort vertex[] = { r.left, r.top, r.left, r.bottom, r.right, r.bottom, @@ -186,7 +223,7 @@ void GLDraw::PutImage(Point p, const Image& img, const Rect& src) glEnableVertexAttribArray(ATTRIB_TEXPOS); glVertexAttribPointer(ATTRIB_TEXPOS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), tc); - glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_SHORT, GL_FALSE, 2 * sizeof(GLshort), vertexCoords); + glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_SHORT, GL_FALSE, 2 * sizeof(GLshort), vertex); glBindTexture(GL_TEXTURE_2D, GetTextureForImage(img)); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); @@ -194,6 +231,74 @@ void GLDraw::PutImage(Point p, const Image& img, const Rect& src) glDisableVertexAttribArray(ATTRIB_TEXPOS); } +void GLDraw::PutImage(Point p, const Image& img, const Rect& src, Color color) +{ + RTIMING("PutImage colored"); + gl_image_colored.Use(); + + Rect s = src & img.GetSize(); + Rect rect(p, s.GetSize()); + + GLshort vertex[] = { + rect.left, rect.top, + rect.left, rect.bottom, + rect.right, rect.bottom, + rect.right, rect.top, + }; + + GLubyte r = color.GetR(); + GLubyte g = color.GetG(); + GLubyte b = color.GetB(); + + GLubyte colors[] = { + r, g, b, + r, g, b, + r, g, b, + r, g, b, + }; + + static GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + + const float *tc; + + if(src == img.GetSize()) { + static float fixed[] = { + 0.0, 0.0, + 0.0, 1.0, + 1.0, 1.0, + 1.0, 0.0, + }; + tc = fixed; + } + else { + Sizef iszf = img.GetSize(); + Rectf h; + h.left = s.left / iszf.cx; + h.right = s.right / iszf.cx; + h.top = s.top / iszf.cy; + h.bottom = s.bottom / iszf.cy; + float partial[] = { + h.left, h.top, + h.left, h.bottom, + h.right, h.bottom, + h.right, h.top, + }; + tc = partial; + } + + glEnableVertexAttribArray(ATTRIB_TEXPOS); + glVertexAttribPointer(ATTRIB_TEXPOS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), tc); + glEnableVertexAttribArray(ATTRIB_COLOR); + glVertexAttribPointer(ATTRIB_COLOR, 3, GL_UNSIGNED_BYTE, GL_FALSE, 3 * sizeof(GLubyte), colors); + glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_SHORT, GL_FALSE, 2 * sizeof(GLshort), vertex); + glBindTexture(GL_TEXTURE_2D, GetTextureForImage(img)); + + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); + + glDisableVertexAttribArray(ATTRIB_COLOR); + glDisableVertexAttribArray(ATTRIB_TEXPOS); +} + void GLDraw::Init(Size sz, uint64 context_) { SDraw::Init(sz); @@ -205,6 +310,9 @@ void GLDraw::Init(Size sz, uint64 context_) gl_image.Use(); GLOrtho(0, sz.cx, sz.cy, 0, 0.0f, 1.0f, gl_image.GetUniform("u_projection")); + gl_image_colored.Use(); + GLOrtho(0, sz.cx, sz.cy, 0, 0.0f, 1.0f, gl_image.GetUniform("u_projection")); + gl_rect.Use(); GLOrtho(0, sz.cx, sz.cy, 0, 0.0f, 1.0f, gl_rect.GetUniform("u_projection")); } diff --git a/uppsrc/GLDraw/GLShaders.cpp b/uppsrc/GLDraw/GLShaders.cpp index 180336a66..978b2a59a 100644 --- a/uppsrc/GLDraw/GLShaders.cpp +++ b/uppsrc/GLDraw/GLShaders.cpp @@ -64,6 +64,8 @@ void GLProgram::Create(const char *vertex_shader_, const char *fragment_shader_, Panic("Failed to link"); Clear(); } + + Use(); } void GLProgram::Create(const char *vertex_shader, const char *fragment_shader, diff --git a/uppsrc/GLDraw/Texture.cpp b/uppsrc/GLDraw/Texture.cpp index d3644ed51..6613d0429 100644 --- a/uppsrc/GLDraw/Texture.cpp +++ b/uppsrc/GLDraw/Texture.cpp @@ -1,5 +1,7 @@ #include "GLDraw.h" +#define LTIMING(x) // RTIMING(x) + #define LLOG(x) // DLOG(x) namespace Upp { @@ -14,6 +16,7 @@ struct ImageGLData { void ImageGLData::Init(const Image& img) { + LTIMING("CreateTexture"); Size sz = img.GetSize(); glGenTextures(1, &texture_id);