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() function UIScrollBar:onSetup()
self.setupDone = true self.setupDone = true
--signalcall(self.onValueChange, self, self.value) --signalcall(self.onValueChange, self, self.value)
g_mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end) g_mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end, 300)
g_mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end) g_mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end, 300)
g_mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos) end) g_mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos) end)
updateSlider(self) updateSlider(self)
end end

View File

@ -61,6 +61,10 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
local localPlayerPos = g_game.getLocalPlayer():getPosition() local localPlayerPos = g_game.getLocalPlayer():getPosition()
local autoWalkPos = self:getPosition(mousePosition) 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 if autoWalkPos.z ~= localPlayerPos.z then
local dz = autoWalkPos.z - localPlayerPos.z local dz = autoWalkPos.z - localPlayerPos.z
autoWalkPos.x = autoWalkPos.x + dz autoWalkPos.x = autoWalkPos.x + dz

View File

@ -46,7 +46,7 @@ Texture::Texture(const Size& size)
setupFilters(); setupFilters();
} }
Texture::Texture(const ImagePtr& image, bool buildMipmaps) Texture::Texture(const ImagePtr& image, bool buildMipmaps, bool compress)
{ {
m_id = 0; m_id = 0;
@ -67,11 +67,11 @@ Texture::Texture(const ImagePtr& image, bool buildMipmaps)
if(buildMipmaps) { if(buildMipmaps) {
int level = 0; int level = 0;
do { do {
setupPixels(level++, glImage->getSize(), glImage->getPixelData(), glImage->getBpp()); setupPixels(level++, glImage->getSize(), glImage->getPixelData(), glImage->getBpp(), compress);
} while(glImage->nextMipmap()); } while(glImage->nextMipmap());
m_hasMipmaps = true; m_hasMipmaps = true;
} else } else
setupPixels(0, glImage->getSize(), glImage->getPixelData(), glImage->getBpp()); setupPixels(0, glImage->getSize(), glImage->getPixelData(), glImage->getBpp(), compress);
setupWrap(); setupWrap();
setupFilters(); 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; GLenum format = 0;
switch(channels) { switch(channels) {
@ -234,5 +234,9 @@ void Texture::setupPixels(int level, const Size& size, uchar* pixels, int channe
break; 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: public:
Texture(); Texture();
Texture(const Size& size); Texture(const Size& size);
Texture(const ImagePtr& image, bool buildMipmaps = false); Texture(const ImagePtr& image, bool buildMipmaps = false, bool compress = false);
virtual ~Texture(); virtual ~Texture();
void bind(); void bind();
@ -57,7 +57,7 @@ protected:
void setupWrap(); void setupWrap();
void setupFilters(); void setupFilters();
void setupTranformMatrix(); 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; uint m_id;
Size m_size; Size m_size;