Some drawing refactoring

This commit is contained in:
Henrik Rydgard 2013-03-30 19:23:02 +01:00
parent 36a6c179a0
commit 7ec766a980
5 changed files with 19 additions and 5 deletions

View File

@ -83,7 +83,7 @@ bool Texture::Load(const char *filename) {
// Currently here are a bunch of project-specific workarounds.
// They shouldn't really hurt anything else very much though.
int len = strlen(filename);
size_t len = strlen(filename);
char fn[1024];
strncpy(fn, filename, sizeof(fn));
fn[1023] = 0;
@ -290,3 +290,11 @@ void Texture::Bind(int stage) {
glBindTexture(GL_TEXTURE_2D, id_);
GL_CHECK();
}
void Texture::Unbind(int stage) {
GL_CHECK();
if (stage != -1)
glActiveTexture(GL_TEXTURE0 + stage);
glBindTexture(GL_TEXTURE_2D, 0);
GL_CHECK();
}

View File

@ -34,6 +34,8 @@ public:
virtual void GLLost();
std::string filename() const { return filename_; }
static void Unbind(int stage = -1);
private:
bool LoadXOR(); // Loads a placeholder texture.

View File

@ -36,7 +36,7 @@ int pngLoad(const char *file, int *pwidth, int *pheight, unsigned char **image_d
return 1;
}
int pngLoadPtr(const unsigned char *input_ptr, const int input_len, int *pwidth, int *pheight, unsigned char **image_data_ptr,
int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth, int *pheight, unsigned char **image_data_ptr,
bool flip) {
if (flip)
{
@ -44,7 +44,7 @@ int pngLoadPtr(const unsigned char *input_ptr, const int input_len, int *pwidth,
}
int x,y,n;
unsigned char *data = stbi_load_from_memory(input_ptr,input_len, &x, &y, &n, 4); // 4 = force RGBA
unsigned char *data = stbi_load_from_memory(input_ptr,(int)input_len, &x, &y, &n, 4); // 4 = force RGBA
if (!data)
return 0;

View File

@ -6,7 +6,7 @@
int pngLoad(const char *file, int *pwidth,
int *pheight, unsigned char **image_data_ptr, bool flip);
int pngLoadPtr(const unsigned char *input_ptr, const int input_len, int *pwidth,
int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth,
int *pheight, unsigned char **image_data_ptr, bool flip);
#endif // _PNG_LOAD_H

View File

@ -275,7 +275,11 @@ int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w
ui_draw2d.DrawImage2GridH(theme.buttonImage, x, y, x + w);
ui_draw2d.Flush();
texture->Bind(0);
if (texture) {
texture->Bind(0);
} else {
Texture::Unbind();
}
ui_draw2d.DrawTexRect(x, y, x+w, y+h, 0, 0, 1, 1, 0xFFFFFFFF);
ui_draw2d.Flush();