IconDes: UHD issues, GLCtrl developing

git-svn-id: svn://ultimatepp.org/upp/trunk@12249 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-09-04 21:24:11 +00:00
parent 1f74724b35
commit 19b753c3dd
10 changed files with 56 additions and 18 deletions

View file

@ -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();

View file

@ -37,7 +37,7 @@ Vector<int> GLCtrl::GLPicking::Pick(int x, int y, Callback resizeCallback, Callb
if (hits == 0)
return Vector<int>();
else
else
return ParseHits(buffer, hits);
}

View file

@ -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);

View file

@ -16,8 +16,18 @@
#include <GL/gl.h>
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);

View file

@ -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()

View file

@ -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<ImageGLData, Tuple<uint64, uint64> > sTextureCache;
static LRUCache<ImageGLData, Tuple<uint64, uint64, dword> > sTextureCache;
static bool sReset;
ImageGLData::~ImageGLData()
@ -57,23 +63,25 @@ void GLDraw::ResetCache()
sReset = false;
}
struct ImageGLDataMaker : LRUCache<ImageGLData, Tuple2<uint64, uint64> >::Maker {
struct ImageGLDataMaker : LRUCache<ImageGLData, Tuple<uint64, uint64, dword> >::Maker {
Image img;
uint64 context;
dword flags;
virtual Tuple2<uint64, uint64> Key() const { return MakeTuple<uint64, uint64>(img.GetSerialId(), context); }
virtual int Make(ImageGLData& object) const { object.Init(img); return img.GetLength(); }
virtual Tuple<uint64, uint64, dword> 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;
}

View file

@ -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());

View file

@ -72,7 +72,10 @@ void IconDes::PrepareImageDlg(WithImageLayout<TopWindow>& 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);
}

View file

@ -3,7 +3,11 @@
#include <Draw/Draw.h>
#ifdef flagTIMING
#define PAINTER_TIMING(x) RTIMING(x)
#else
#define PAINTER_TIMING(x) // RTIMING(x)
#endif
namespace Upp {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After