mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-12 14:22:22 -06:00
IconDes: UHD issues, GLCtrl developing
git-svn-id: svn://ultimatepp.org/upp/trunk@12249 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
09953c47ae
commit
00a11f2c47
10 changed files with 56 additions and 18 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue