GVovkiv wrote: ↑Mon Jun 21, 2021 9:56 am
What if, there was some sort of priority system?
For example:
I need draw rectangle with specific color, but i already have modified colors
<snip>
What about that?
love.graphics.setColor(1, 0.5, 1)
love.graphics.rectangle("fill", 200, 200, 100, 100)
love.graphics.push('all') -- saves most graphics state, including colors
love.graphics.setColor(0.4, 1, 0.5)
love.graphics.rectangle("fill", 0, 0, 100, 100)
love.graphics.pop() -- restore graphics state
Push/Pop can also be nested, of course, to some reasonable degree.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
GVovkiv wrote: ↑Mon Jun 21, 2021 9:56 am
What if, there was some sort of priority system?
For example:
I need draw rectangle with specific color, but i already have modified colors
<snip>
What about that?
love.graphics.setColor(1, 0.5, 1)
love.graphics.rectangle("fill", 200, 200, 100, 100)
love.graphics.push('all') -- saves most graphics state, including colors
love.graphics.setColor(0.4, 1, 0.5)
love.graphics.rectangle("fill", 0, 0, 100, 100)
love.graphics.pop() -- restore graphics state
Push/Pop can also be nested, of course, to some reasonable degree.
Yeah, but it still not that good, than just set "love.graphics.rectangle("line", 0, 0, 100, 100, {colors}), without need to wrap things inside another function
local lg_rectangle = love.graphics.rectangle
love.graphics.rectangle = function( mode, x, y, width, height, color )
if color then
local cur_r, cur_g, cur_b, cur_a = love.graphics.getColor()
love.graphics.setColor( color )
lg_rectangle( mode, x, y, width, height )
love.graphics.setColor( cur_r, cur_g, cur_b, cur_a )
else
lg_rectangle( mode, x, y, width, height )
end
end
GVovkiv wrote: ↑Fri Jul 02, 2021 9:12 am
Yeah, but it still not that good, than just set "love.graphics.rectangle("line", 0, 0, 100, 100, {colors}), without need to wrap things inside another function
It's not wrapped in another function; you just have 2+1 extra function calls.
Last edited by zorg on Sat Jul 03, 2021 4:41 am, edited 1 time in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
love.graphics.setColor(1, 1, 1)
love.graphics.setShader(shader)
*etc*
love.graphics.rectangle(...)
-- draw object with some specific colors, etc
love.graphics.push("all")
love.graphics.setColor(...)
love.graphics.setShader(...)
love.graphics.rectangle(...)
love.graphics.pop()
*OR if i want to draw that object again somewhere, i wrap it in*
function draw(...)
love.graphics.push("all")
love.graphics.setColor(...)
love.graphics.setShader(...)
love.graphics.rectangle(...)
love.graphics.pop()
end
love.graphics.setColor(1, 1, 1)
love.graphics.setShader(shader)
*etc*
love.graphics.rectangle(...)
-- draw object with some specific colors, etc
love.graphics.rectangle(drawMode, x, y, w, h, r, g, b, a, shader, etc)
Doing it your way would either involve a lot of branches, or a lot of potentially superfluous saving and restoring of graphics state. Both of those are bad for performance. The way it is implemented now is close to how the underlying OpenGL API works and what GPUs are optimized for. Engines and frameworks are specifically optimized to make use of batching, with the goal being to avoid these state changes as much as possible, because they are so slow.
A well programmed game sorts its primitives anyway, in a way that makes it easier for the framework to batch drawcalls and for the GPU to perform well. Your proposal would only make it easier to write bad/slow code, for no real benefit.
If you want things to work this way, you can easily write the code once on top of the existing API, and use it in your projects. It won't be very performant though.
grump wrote: ↑Fri Jul 02, 2021 1:59 pm
Doing it your way would either involve a lot of branches, or a lot of potentially superfluous saving and restoring of graphics state. Both of those are bad for performance. The way it is implemented now is close to how the underlying OpenGL API works and what GPUs are optimized for. Engines and frameworks are specifically optimized to make use of batching, with the goal being to avoid these state changes as much as possible, because they are so slow.
A well programmed game sorts its primitives anyway, in a way that makes it easier for the framework to batch drawcalls and for the GPU to perform well. Your proposal would only make it easier to write bad/slow code, for no real benefit.
If you want things to work this way, you can easily write the code once on top of the existing API, and use it in your projects. It won't be very performant though.