1
0

set_shader_texture_size

This commit is contained in:
Jon Michael Aanes 2023-10-22 13:08:52 +02:00
parent 89884e59c4
commit 2cd21d3608

View File

@ -72,11 +72,21 @@ function Sprite.new (quad, imagesheet)
return setmetatable({ quad = quad, imagesheet = imagesheet, is_sprite = true }, Sprite)
end
local function set_shader_texture_size(texture)
local currently_active_shader = love.graphics.getShader()
if currently_active_shader ~= nil and currently_active_shader:hasUniform('spritesheet_inverse_width') then
local width, height = texture:getDimensions()
currently_active_shader:send('spritesheet_inverse_width', {1/width, 0})
currently_active_shader:send('spritesheet_inverse_height', { 0, 1/height})
end
end
if define_love then
function Sprite:generateImage ()
local imagesheet, quad = self.imagesheet, self.quad
self.func = function (x, y)
set_shader_texture_size(imagesheet.image)
love.graphics.draw(imagesheet.image, quad, math.floor(x), math.floor(y), 0, 1, 1, imagesheet.origin_x, imagesheet.origin_y)
end
end
@ -138,6 +148,7 @@ function Animation:generateImage ()
if self.wrap then t = t % self.duration end
local quad = get_quad_based_on_time(self, t)
if not quad then error_internal('Could not determine quad when drawing animation. Time was %f.', t) end
set_shader_texture_size(self.imagesheet.image)
love.graphics.draw(self.imagesheet.image, quad, x, y, 0, 1, 1, self.imagesheet.origin_x, self.imagesheet.origin_y)
end
end