diff --git a/uppsrc/GLDraw/GLDraw.cpp b/uppsrc/GLDraw/GLDraw.cpp index ff17509a5..43abcabe9 100644 --- a/uppsrc/GLDraw/GLDraw.cpp +++ b/uppsrc/GLDraw/GLDraw.cpp @@ -1,5 +1,7 @@ #include "GLDraw.h" +#define LTIMING(x) RTIMING(x) + #ifndef GL_USE_SHADERS #define LLOG(x) // LOG(x) @@ -8,6 +10,8 @@ namespace Upp { void GLDraw::PutImage(Point p, const Image& img, const Rect& src) { + LTIMING("PutImage"); + if(img.GetLength() == 0) return; @@ -63,6 +67,7 @@ void GLDraw::SetColor(Color c) void GLDraw::PutRect(const Rect& r, Color color) { + LTIMING("PutRect"); LLOG("PutRect " << r << " " << color); bool inv = color == InvertColor(); if(inv) @@ -112,6 +117,10 @@ void GLDraw::Init(Size sz, uint64 context_) */ } +void GLDraw::Finish() +{ +} + GLDraw::~GLDraw() { } diff --git a/uppsrc/GLDraw/GLDraw.h b/uppsrc/GLDraw/GLDraw.h index 335c0a299..3c1dea68c 100644 --- a/uppsrc/GLDraw/GLDraw.h +++ b/uppsrc/GLDraw/GLDraw.h @@ -11,6 +11,8 @@ #define GL_USE_SHADERS +#define GL_COMB_OPT + #include namespace Upp { @@ -58,6 +60,16 @@ class GLDraw : public SDraw { void SetColor(Color c); uint64 context; + +#ifdef GL_COMB_OPT + struct RectColor : Moveable { + Rect rect; + Color color; + }; + Vector put_rect; + + void FlushPutRect(); +#endif public: virtual void PutImage(Point p, const Image& img, const Rect& src); @@ -67,6 +79,7 @@ public: virtual void PutRect(const Rect& r, Color color); void Init(Size sz, uint64 context = 0); + void Finish(); static void ClearCache(); static void ResetCache(); diff --git a/uppsrc/GLDraw/GLDrawS.cpp b/uppsrc/GLDraw/GLDrawS.cpp index 2548401fa..0879fa2fe 100644 --- a/uppsrc/GLDraw/GLDrawS.cpp +++ b/uppsrc/GLDraw/GLDrawS.cpp @@ -1,15 +1,15 @@ #include "GLDraw.h" -#define LTIMING(x) // RTIMING(x) +#define LTIMING(x) RTIMING(x) #ifdef GL_USE_SHADERS namespace Upp { -int u_imagetexture; - GLProgram gl_image, gl_image_colored, gl_rect; +int u_color; + void CheckError() { /* Check for error conditions. */ @@ -83,7 +83,7 @@ void initializeGL() ); glUniform1i(gl_image_colored.GetUniform("s_texture"), 0); - +/* gl_rect.Create( "attribute vec4 a_position; \n" "attribute vec4 a_color; \n" @@ -107,6 +107,29 @@ void initializeGL() ATTRIB_VERTEX, "a_position", ATTRIB_COLOR, "a_color" ); +*/ + gl_rect.Create( + "attribute vec4 a_position; \n" + "attribute vec4 a_color; \n" + "uniform mat4 u_projection; \n" + "void main() \n" + "{ \n" + " gl_Position = u_projection * a_position; \n" + "}" + , + "#ifdef GL_ES\n" + "precision mediump float;\n" + "precision mediump int;\n" + "#endif\n" + "uniform vec4 u_color; \n" + "void main()\n" + "{\n" + " gl_FragColor = u_color;\n" + "}", + ATTRIB_VERTEX, "a_position" + ); + + u_color = gl_rect.GetUniform("u_color"); glEnableVertexAttribArray(ATTRIB_VERTEX); @@ -134,9 +157,100 @@ void GLOrtho(float left, float right, float bottom, float top, float near, float glUniformMatrix4fv(u_projection, 1, 0, ortho); } +void GLDraw::FlushPutRect() +{ + if(put_rect.GetCount() == 0) + return; + + LTIMING("FlushPutRect"); + + gl_rect.Use(); + + Buffer vertex(8 * put_rect.GetCount()); + Buffer color(12 * put_rect.GetCount()); + Buffer index(6 * put_rect.GetCount()); + GLshort *v = vertex; + GLubyte *c = color; + GLushort *n = index; + for(int i = 0; i < put_rect.GetCount(); i++) { + const RectColor& rc = put_rect[i]; + *v++ = rc.rect.left; *v++ = rc.rect.top; + *v++ = rc.rect.left; *v++ = rc.rect.bottom; + *v++ = rc.rect.right; *v++ = rc.rect.bottom, + *v++ = rc.rect.right; *v++ = rc.rect.top; + GLubyte r = rc.color.GetR(); + GLubyte g = rc.color.GetG(); + GLubyte b = rc.color.GetB(); + *c++ = r; *c++ = g; *c++ = b; + *c++ = r; *c++ = g; *c++ = b; + *c++ = r; *c++ = g; *c++ = b; + *c++ = r; *c++ = g; *c++ = b; + *n++ = 4 * i + 0; + *n++ = 4 * i + 1; + *n++ = 4 * i + 2; + *n++ = 4 * i + 0; + *n++ = 4 * i + 2; + *n++ = 4 * i + 3; + } + + glEnableVertexAttribArray(ATTRIB_COLOR); + glVertexAttribPointer(ATTRIB_COLOR, 3, GL_UNSIGNED_BYTE, GL_FALSE, 3 * sizeof(GLubyte), color); + glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_SHORT, GL_FALSE, 2 * sizeof(GLshort), vertex); + + glDrawElements(GL_TRIANGLES, 6 * put_rect.GetCount(), GL_UNSIGNED_SHORT, index); + + glDisableVertexAttribArray(ATTRIB_COLOR); + + put_rect.Clear(); +} + void GLDraw::PutRect(const Rect& rect, Color color) { LTIMING("PutRect"); + + gl_rect.Use(); + + GLshort vertex[] = { + rect.left, rect.top, + rect.left, rect.bottom, + rect.right, rect.bottom, + rect.right, rect.top, + }; + + bool inv = color == InvertColor(); + if(inv) { + glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR); + color = Color(255, 255, 255); + } + + GLubyte r = color.GetR(); + GLubyte g = color.GetG(); + GLubyte b = color.GetB(); + + glUniform4f(u_color, r / 255.0, g / 255.0, b / 255.0, 1.0); + + static GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + + glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_SHORT, GL_FALSE, 2 * sizeof(GLshort), vertex); + + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); + + if(inv) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + +#if 0 + LTIMING("PutRect"); +#ifdef GL_COMB_OPT + if(color != InvertColor()) { + RectColor& rc = put_rect.Add(); + rc.rect = rect; + rc.color = color; + if(put_rect.GetCount() > 100) + FlushPutRect(); + return; + } +#endif + gl_rect.Use(); GLshort vertex[] = { @@ -175,11 +289,14 @@ void GLDraw::PutRect(const Rect& rect, Color color) if(inv) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif } void GLDraw::PutImage(Point p, const Image& img, const Rect& src) { LTIMING("PutImage"); + FlushPutRect(); + gl_image.Use(); Rect s = src & img.GetSize(); @@ -233,6 +350,8 @@ void GLDraw::PutImage(Point p, const Image& img, const Rect& src) void GLDraw::PutImage(Point p, const Image& img, const Rect& src, Color color) { + FlushPutRect(); + RTIMING("PutImage colored"); gl_image_colored.Use(); @@ -317,6 +436,13 @@ void GLDraw::Init(Size sz, uint64 context_) GLOrtho(0, sz.cx, sz.cy, 0, 0.0f, 1.0f, gl_rect.GetUniform("u_projection")); } +void GLDraw::Finish() +{ +#ifdef GL_COMB_OPT + FlushPutRect(); +#endif +} + GLDraw::~GLDraw() { } diff --git a/uppsrc/ide/Builders/Builders.h b/uppsrc/ide/Builders/Builders.h index 27d021869..4ed853e88 100644 --- a/uppsrc/ide/Builders/Builders.h +++ b/uppsrc/ide/Builders/Builders.h @@ -53,6 +53,7 @@ struct CppBuilder : Builder { String Includes(const char *sep, const String& package, const Package& pkg); String IncludesShort(const char *sep, const String& package, const Package& pkg); + String DefinesTargetTime(const char *sep, const String& package, const Package& pkg); String IncludesDefinesTargetTime(const String& package, const Package& pkg); String GetMakePath(String fn) const; diff --git a/uppsrc/ide/Builders/CppBuilder.cpp b/uppsrc/ide/Builders/CppBuilder.cpp index 45113bf36..545287baa 100644 --- a/uppsrc/ide/Builders/CppBuilder.cpp +++ b/uppsrc/ide/Builders/CppBuilder.cpp @@ -381,19 +381,26 @@ String CppBuilder::IncludesShort(const char *sep, const String& package, const P return cc; } -String CppBuilder::IncludesDefinesTargetTime(const String& package, const Package& pkg) +String CppBuilder::DefinesTargetTime(const char *sep, const String& package, const Package& pkg) { - String cc = Includes(" -I", package, pkg); + String cc; for(int i = 0; i < config.GetCount(); i++) - cc << " -Dflag" << config[i]; + cc << sep << "flag" << config[i]; Time t = GetSysTime(); - cc << " -DbmYEAR=" << (int)t.year; - cc << " -DbmMONTH=" << (int)t.month; - cc << " -DbmDAY=" << (int)t.day; - cc << " -DbmHOUR=" << (int)t.hour; - cc << " -DbmMINUTE=" << (int)t.minute; - cc << " -DbmSECOND=" << (int)t.second; - cc << " -DMAIN_CONF"; + cc << sep << "bmYEAR=" << (int)t.year; + cc << sep << "bmMONTH=" << (int)t.month; + cc << sep << "bmDAY=" << (int)t.day; + cc << sep << "bmHOUR=" << (int)t.hour; + cc << sep << "bmMINUTE=" << (int)t.minute; + cc << sep << "bmSECOND=" << (int)t.second; + cc << sep << "MAIN_CONF"; targettime = GetFileTime(target); return cc; } + +String CppBuilder::IncludesDefinesTargetTime(const String& package, const Package& pkg) +{ + String cc = Includes(" -I", package, pkg); + cc << DefinesTargetTime(" -D", package, pkg); + return cc; +} diff --git a/uppsrc/ide/Builders/GccBuilder.icpp b/uppsrc/ide/Builders/GccBuilder.icpp index 134a8b56e..86dd1ec8a 100644 --- a/uppsrc/ide/Builders/GccBuilder.icpp +++ b/uppsrc/ide/Builders/GccBuilder.icpp @@ -164,7 +164,8 @@ bool GccBuilder::BuildPackage(const String& package, Vector& linkfile, if(rc) { String exec; exec << "windres -i " << GetHostPathQ(fn) - << " -o " << GetHostPathQ(objfile) << IncludesShort(" --include-dir=", package, pkg); + << " -o " << GetHostPathQ(objfile) << IncludesShort(" --include-dir=", package, pkg) + << DefinesTargetTime(" -D", package, pkg) + (HasFlag("DEBUG")?" -D_DEBUG":""); PutVerbose(exec); int slot = AllocSlot(); execerr = (slot < 0 || !Run(exec, slot, GetHostPath(objfile), 1)); diff --git a/uppsrc/ide/Builders/MscBuilder.icpp b/uppsrc/ide/Builders/MscBuilder.icpp index dfc854ea8..fc6243f15 100644 --- a/uppsrc/ide/Builders/MscBuilder.icpp +++ b/uppsrc/ide/Builders/MscBuilder.icpp @@ -286,6 +286,7 @@ bool MscBuilder::BuildPackage(const String& package, Vector& linkfile, S PutConsole(GetFileNamePos(fn)); int slot = AllocSlot(); if(slot < 0 || !Run("rc /fo" + GetHostPathQ(objfile) + Includes(" /i", package, pkg) + + DefinesTargetTime(" /d", package, pkg) + (HasFlag("DEBUG")?" /d_DEBUG":"") + ' ' + GetHostPathQ(fn), slot, GetHostPath(objfile), 1)) execerr = true; } diff --git a/uppsrc/ide/Builders/OwcBuilder.icpp b/uppsrc/ide/Builders/OwcBuilder.icpp index 354841681..5a14ed17e 100644 --- a/uppsrc/ide/Builders/OwcBuilder.icpp +++ b/uppsrc/ide/Builders/OwcBuilder.icpp @@ -118,6 +118,7 @@ bool OwcBuilder::BuildPackage(const String& package, Vector& linkfile, S objfile = ForceExt(objfile, ".res"); int slot = AllocSlot(); if (slot < 0 || !Run("wrc -q -r -x -fo=" + GetHostPathQ(objfile) + Includes(" -i=", package, pkg) + + DefinesTargetTime(" -d", package, pkg) + (HasFlag("DEBUG")?" -d_DEBUG":"") + ' ' + GetHostPathQ(fn), slot, GetHostPath(objfile), 1)) execerr = true; }