Support for compressed textures

This commit is contained in:
Eduardo Bart 2012-08-21 08:09:48 -03:00
parent 01a8e57a3c
commit ea4dd2f8e6
4 changed files with 17 additions and 9 deletions

View File

@ -102,8 +102,8 @@ end
function UIScrollBar:onSetup()
self.setupDone = true
--signalcall(self.onValueChange, self, self.value)
g_mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end)
g_mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end)
g_mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end, 300)
g_mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end, 300)
g_mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos) end)
updateSlider(self)
end

View File

@ -61,6 +61,10 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
local localPlayerPos = g_game.getLocalPlayer():getPosition()
local autoWalkPos = self:getPosition(mousePosition)
-- happens when clicking outside of map boundaries
if not autoWalkPos then return false end
if autoWalkPos.z ~= localPlayerPos.z then
local dz = autoWalkPos.z - localPlayerPos.z
autoWalkPos.x = autoWalkPos.x + dz

View File

@ -46,7 +46,7 @@ Texture::Texture(const Size& size)
setupFilters();
}
Texture::Texture(const ImagePtr& image, bool buildMipmaps)
Texture::Texture(const ImagePtr& image, bool buildMipmaps, bool compress)
{
m_id = 0;
@ -67,11 +67,11 @@ Texture::Texture(const ImagePtr& image, bool buildMipmaps)
if(buildMipmaps) {
int level = 0;
do {
setupPixels(level++, glImage->getSize(), glImage->getPixelData(), glImage->getBpp());
setupPixels(level++, glImage->getSize(), glImage->getPixelData(), glImage->getBpp(), compress);
} while(glImage->nextMipmap());
m_hasMipmaps = true;
} else
setupPixels(0, glImage->getSize(), glImage->getPixelData(), glImage->getBpp());
setupPixels(0, glImage->getSize(), glImage->getPixelData(), glImage->getBpp(), compress);
setupWrap();
setupFilters();
@ -216,7 +216,7 @@ void Texture::setupTranformMatrix()
}
}
void Texture::setupPixels(int level, const Size& size, uchar* pixels, int channels)
void Texture::setupPixels(int level, const Size& size, uchar* pixels, int channels, bool compress)
{
GLenum format = 0;
switch(channels) {
@ -234,5 +234,9 @@ void Texture::setupPixels(int level, const Size& size, uchar* pixels, int channe
break;
}
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size.width(), size.height(), 0, format, GL_UNSIGNED_BYTE, pixels);
GLenum internalFormat = GL_RGBA;
if(compress)
internalFormat = GL_COMPRESSED_RGBA;
glTexImage2D(GL_TEXTURE_2D, level, internalFormat, size.width(), size.height(), 0, format, GL_UNSIGNED_BYTE, pixels);
}

View File

@ -30,7 +30,7 @@ class Texture : public stdext::shared_object
public:
Texture();
Texture(const Size& size);
Texture(const ImagePtr& image, bool buildMipmaps = false);
Texture(const ImagePtr& image, bool buildMipmaps = false, bool compress = false);
virtual ~Texture();
void bind();
@ -57,7 +57,7 @@ protected:
void setupWrap();
void setupFilters();
void setupTranformMatrix();
void setupPixels(int level, const Size& size, uchar *pixels, int channels = 4);
void setupPixels(int level, const Size& size, uchar *pixels, int channels = 4, bool compress = false);
uint m_id;
Size m_size;