From 00a11f2c478e1f8746a3cdc234694e55abbc1955 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 4 Sep 2018 21:24:11 +0000 Subject: [PATCH] IconDes: UHD issues, GLCtrl developing git-svn-id: svn://ultimatepp.org/upp/trunk@12249 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CodeEditor/CodeEditor.cpp | 2 +- uppsrc/GLCtrl/GLPicking.cpp | 2 +- uppsrc/GLCtrl/Win32GLCtrl.cpp | 1 + uppsrc/GLDraw/GLDraw.h | 18 ++++++++++++++++-- uppsrc/GLDraw/GLDrawS.cpp | 10 ++++++---- uppsrc/GLDraw/Texture.cpp | 26 +++++++++++++++++--------- uppsrc/IconDes/Bar.cpp | 6 ++++++ uppsrc/IconDes/List.cpp | 5 ++++- uppsrc/Painter/Painter.h | 4 ++++ uppsrc/ide/icon.ico | Bin 2862 -> 2862 bytes 10 files changed, 56 insertions(+), 18 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index 55ad52c17..3241815cd 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -1111,7 +1111,7 @@ void CodeEditor::Zoom(int d) Font f = GetFont(); int h = f.GetCy(); int q = f.GetHeight(); - while(f.GetCy() == h && (d < 0 ? f.GetCy() > 5 : f.GetCy() < 40)) + while(f.GetCy() == h && (d < 0 ? f.GetCy() > 5 : f.GetCy() < 80)) f.Height(q += d); SetFont(f); EditorBarLayout(); diff --git a/uppsrc/GLCtrl/GLPicking.cpp b/uppsrc/GLCtrl/GLPicking.cpp index 6b6ce6e12..3cf2f0f6a 100644 --- a/uppsrc/GLCtrl/GLPicking.cpp +++ b/uppsrc/GLCtrl/GLPicking.cpp @@ -37,7 +37,7 @@ Vector GLCtrl::GLPicking::Pick(int x, int y, Callback resizeCallback, Callb if (hits == 0) return Vector(); - else + else return ParseHits(buffer, hits); } diff --git a/uppsrc/GLCtrl/Win32GLCtrl.cpp b/uppsrc/GLCtrl/Win32GLCtrl.cpp index 92ad8cf6e..8fee84896 100644 --- a/uppsrc/GLCtrl/Win32GLCtrl.cpp +++ b/uppsrc/GLCtrl/Win32GLCtrl.cpp @@ -92,6 +92,7 @@ LRESULT GLCtrl::GLPane::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) PAINTSTRUCT ps; BeginPaint(GetHWND(), &ps); ActivateContext(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); ctrl->GLPaint(); if(ctrl->doubleBuffering) SwapBuffers(hDC); diff --git a/uppsrc/GLDraw/GLDraw.h b/uppsrc/GLDraw/GLDraw.h index b13b929a3..aeca05ee6 100644 --- a/uppsrc/GLDraw/GLDraw.h +++ b/uppsrc/GLDraw/GLDraw.h @@ -16,8 +16,18 @@ #include namespace Upp { - -GLuint GetTextureForImage(const Image& img, uint64 context = 0); + +enum { + TEXTURE_LINEAR = 0x01, + TEXTURE_MIPMAP = 0x02, +}; + +GLuint GetTextureForImage(dword flags, const Image& img, uint64 context = 0); + +inline +GLuint GetTextureForImage(const Image& img, uint64 context = 0) { + return GetTextureForImage(0, img, context); +} #ifdef GL_USE_SHADERS @@ -55,6 +65,8 @@ public: GLProgram(); }; +extern GLProgram gl_image, gl_image_colored, gl_rect; + #endif class GLDraw : public SDraw { @@ -73,6 +85,8 @@ class GLDraw : public SDraw { void FlushPutRect(); public: + void Flush() { FlushPutRect(); } + 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); diff --git a/uppsrc/GLDraw/GLDrawS.cpp b/uppsrc/GLDraw/GLDrawS.cpp index d7c4e9408..15b6ccc5b 100644 --- a/uppsrc/GLDraw/GLDrawS.cpp +++ b/uppsrc/GLDraw/GLDrawS.cpp @@ -419,13 +419,15 @@ void GLDraw::Init(Size sz, uint64 context_) } gl_image.Use(); - GLOrtho(0, (float)sz.cx, (float)sz.cy, 0, 0.0f, 1.0f, gl_image.GetUniform("u_projection")); + static int uni1 = gl_image.GetUniform("u_projection"); + GLOrtho(0, (float)sz.cx, (float)sz.cy, 0, 0.0f, 1.0f, uni1); gl_image_colored.Use(); - GLOrtho(0, (float)sz.cx, (float)sz.cy, 0, 0.0f, 1.0f, gl_image_colored.GetUniform("u_projection")); - + static int uni2 = gl_image_colored.GetUniform("u_projection"); + GLOrtho(0, (float)sz.cx, (float)sz.cy, 0, 0.0f, 1.0f, uni2); gl_rect.Use(); - GLOrtho(0, (float)sz.cx, (float)sz.cy, 0, 0.0f, 1.0f, gl_rect.GetUniform("u_projection")); + static int uni3 = gl_rect.GetUniform("u_projection"); + GLOrtho(0, (float)sz.cx, (float)sz.cy, 0, 0.0f, 1.0f, uni3); } void GLDraw::Finish() diff --git a/uppsrc/GLDraw/Texture.cpp b/uppsrc/GLDraw/Texture.cpp index 5f2ce635a..6149a9126 100644 --- a/uppsrc/GLDraw/Texture.cpp +++ b/uppsrc/GLDraw/Texture.cpp @@ -10,21 +10,27 @@ struct ImageGLData { Image img; GLuint texture_id; - void Init(const Image& img); + void Init(const Image& img, dword flags); ~ImageGLData(); }; -void ImageGLData::Init(const Image& img) +void ImageGLData::Init(const Image& img_, dword flags) { LTIMING("CreateTexture"); + Image img = img_; Size sz = img.GetSize(); glGenTextures(1, &texture_id); glBindTexture(GL_TEXTURE_2D, texture_id); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sz.cx, sz.cy, 0, GL_BGRA, GL_UNSIGNED_BYTE, ~img); + if(flags & TEXTURE_MIPMAP) + glGenerateMipmap(GL_TEXTURE_2D); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, flags & TEXTURE_LINEAR ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, flags & TEXTURE_LINEAR ? + flags & TEXTURE_MIPMAP ? GL_LINEAR_MIPMAP_LINEAR + : GL_LINEAR + : GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -33,7 +39,7 @@ void ImageGLData::Init(const Image& img) SysImageRealized(img); } -static LRUCache > sTextureCache; +static LRUCache > sTextureCache; static bool sReset; ImageGLData::~ImageGLData() @@ -57,23 +63,25 @@ void GLDraw::ResetCache() sReset = false; } -struct ImageGLDataMaker : LRUCache >::Maker { +struct ImageGLDataMaker : LRUCache >::Maker { Image img; uint64 context; + dword flags; - virtual Tuple2 Key() const { return MakeTuple(img.GetSerialId(), context); } - virtual int Make(ImageGLData& object) const { object.Init(img); return img.GetLength(); } + virtual Tuple Key() const { return MakeTuple(img.GetSerialId(), context, flags); } + virtual int Make(ImageGLData& object) const { object.Init(img, flags); return img.GetLength(); } }; int max_texture_memory = 4 * 1024 * 768; int max_texture_count = 1000; -GLuint GetTextureForImage(const Image& img, uint64 context) +GLuint GetTextureForImage(dword flags, const Image& img, uint64 context) { sTextureCache.Shrink(max_texture_memory, max_texture_count); ImageGLDataMaker m; m.img = img; m.context = context; + m.flags = flags; return sTextureCache.Get(m).texture_id; } diff --git a/uppsrc/IconDes/Bar.cpp b/uppsrc/IconDes/Bar.cpp index 484394859..2f3c6f8ba 100644 --- a/uppsrc/IconDes/Bar.cpp +++ b/uppsrc/IconDes/Bar.cpp @@ -241,10 +241,16 @@ struct CachedIconImage : public Display { Image m = q; if(IsNull(m)) return; + Size rsz = r.GetSize(); Size isz = m.GetSize(); if(isz.cx > 200 || isz.cy > 200) m = IconDesImg::LargeImage(); else + if(2 * isz.cx <= rsz.cx && 2 * isz.cy < rsz.cy) { + int n = min(rsz.cx / isz.cx, rsz.cy / isz.cy); + m = Magnify(m, n, n); // TODO: Cached! + } + else if(isz.cx > r.GetWidth() || isz.cy > r.GetHeight()) m = CachedRescale(m, GetFitSize(m.GetSize(), r.GetSize())); Point p = r.CenterPos(m.GetSize()); diff --git a/uppsrc/IconDes/List.cpp b/uppsrc/IconDes/List.cpp index 60a99a199..86973c4ef 100644 --- a/uppsrc/IconDes/List.cpp +++ b/uppsrc/IconDes/List.cpp @@ -72,7 +72,10 @@ void IconDes::PrepareImageDlg(WithImageLayout& dlg) int resolution = IMAGE_RESOLUTION_STANDARD; if(IsCurrent()) resolution = Current().image.GetResolution(); - dlg.resolution <<= decode(resolution, IMAGE_RESOLUTION_STANDARD, 0, IMAGE_RESOLUTION_UHD, 1, 2); + dlg.resolution.Set(0, IMAGE_RESOLUTION_STANDARD); + dlg.resolution.Set(1, IMAGE_RESOLUTION_UHD); + dlg.resolution.Set(2, IMAGE_RESOLUTION_NONE); + dlg.resolution <<= resolution; } dlg.name.SetFilter(sCharFilterCid); } diff --git a/uppsrc/Painter/Painter.h b/uppsrc/Painter/Painter.h index 399d0398d..92515bb35 100644 --- a/uppsrc/Painter/Painter.h +++ b/uppsrc/Painter/Painter.h @@ -3,7 +3,11 @@ #include +#ifdef flagTIMING +#define PAINTER_TIMING(x) RTIMING(x) +#else #define PAINTER_TIMING(x) // RTIMING(x) +#endif namespace Upp { diff --git a/uppsrc/ide/icon.ico b/uppsrc/ide/icon.ico index 15ae7b5c16d5ccb3a800f17ebb7abe421f16ff96..2044dab4f2c29afca0fb0f910f4e07fc7e88c9a7 100644 GIT binary patch delta 41 ocmZ1{woYtA5SP>rMg|6l!#)fkdck=Jop2mPPYe{D+{m>S00*25(f|Me delta 41 ocmZ1{woYtA5SNr769a?7yIKYio$v%gJG=+c69YvjH*&270NJt%wEzGB