From 360c190ef79673ed348e952dcfe860d876d97d20 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Sun, 15 May 2011 23:31:12 +0200 Subject: [PATCH] Move po2ifying to Image, Quads broken at the moment --- src/modules/graphics/opengl/Image.cpp | 22 +++++++++++++++++++++- src/modules/image/devil/ImageData.cpp | 25 +++++-------------------- src/modules/image/devil/ImageData.h | 4 ++-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 84620fdf9..1b6357b84 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -284,13 +284,33 @@ namespace opengl glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + float p2width = next_p2(width); + float p2height = next_p2(height); + float t = width/p2width; + float s = height/p2height; + + vertices[1].t = t; + vertices[2].t = t; + vertices[2].s = s; + vertices[3].s = s; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, + (GLsizei)p2width, + (GLsizei)p2height, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + 0); + + glTexSubImage2D(GL_TEXTURE_2D, + 0, + 0, + 0, (GLsizei)width, (GLsizei)height, - 0, GL_RGBA, GL_UNSIGNED_BYTE, data->getData()); diff --git a/src/modules/image/devil/ImageData.cpp b/src/modules/image/devil/ImageData.cpp index 2f2e5834c..e452985cf 100644 --- a/src/modules/image/devil/ImageData.cpp +++ b/src/modules/image/devil/ImageData.cpp @@ -35,7 +35,7 @@ namespace image { namespace devil { - void ImageData::createPo2(int width, int height, void * data) + void ImageData::create(int width, int height, void * data) { //create the image ilGenImages(1, &image); @@ -43,10 +43,6 @@ namespace devil //bind it ilBindImage(image); - //scale to nearest bigger po2 - width = next_p2(width); - height = next_p2(height); - //create and populate the image bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE); @@ -74,15 +70,11 @@ namespace devil void ImageData::load(Data * data) { - // Create a temporary image to store - // the decoded image in. - ILuint tempimage; - // Generate DevIL image. - ilGenImages(1, &tempimage); + ilGenImages(1, &image); // Bind the image. - ilBindImage(tempimage); + ilBindImage(image); // Try to load the image. ILboolean success = ilLoadL(IL_TYPE_UNKNOWN, (void*)data->getData(), data->getSize()); @@ -90,7 +82,6 @@ namespace devil // Check for errors if(!success) { - ilDeleteImages(1, &tempimage); throw love::Exception("Could not decode image!"); return; } @@ -107,15 +98,9 @@ namespace devil if(bpp != 4) { - ilDeleteImages(1, &tempimage); std::cerr << "Bits per pixel != 4" << std::endl; return; } - - // Create a new, PO2, image based on it - createPo2(width, height, ilGetData()); - // Delete the temporary image. - ilDeleteImages(1, &tempimage); } ImageData::ImageData(Data * data) @@ -133,7 +118,7 @@ namespace devil ImageData::ImageData(int width, int height) : width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4) { - createPo2(width, height); + create(width, height); // Set to black. memset((void*)ilGetData(), 0, width*height*4); @@ -142,7 +127,7 @@ namespace devil ImageData::ImageData(int width, int height, void *data) : width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4) { - createPo2(width, height, data); + create(width, height, data); } ImageData::~ImageData() diff --git a/src/modules/image/devil/ImageData.h b/src/modules/image/devil/ImageData.h index 055e7d864..20f9d379f 100644 --- a/src/modules/image/devil/ImageData.h +++ b/src/modules/image/devil/ImageData.h @@ -53,8 +53,8 @@ namespace devil // DevIL image identifier. ILuint image; - // Create PO2 imagedata. - void createPo2(int width, int height, void * data = 0); + // Create imagedata. + void create(int width, int height, void * data = 0); void load(Data * data);