Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Pixel vs. Bitmap — Gideros Forum

Pixel vs. Bitmap

Is there a difference in performance using Pixel instead of Bitmap, when frequently changing the texture?

Likes: oleg

My Gideros games: www.totebo.com
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • how exactly do you use it? let's benchmark it with Profiler :smile:
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • I was hoping there was a clear winner here! :)

    I'm planning to replace the texture every five frames or so, to create a looping frame based animation.
    My Gideros games: www.totebo.com
  • Apollo14Apollo14 Member
    edited August 2018 Accepted Answer
    Okay Sprite is 20% faster :D
    Number of tests:	10000000
    testTexturing1	8.2692814178721 --sprite
    testTexturing2	10.279621433833 --pixel
    application:setBackgroundColor(0); application:setKeepAwake(true)
     
    maxIterations@1000000
    local randomSeed,random=Core.randomSeed,Core.random
    randomSeed(1,1)
     
    local texturesArr={
    	Texture.new("1.jpg",true),
    	Texture.new("2.jpg",true),
    	Texture.new("3.jpg",true)
    }
     
    local sprite1 = Bitmap.new(texturesArr[1])
    local pix1=Pixel.new(0xffffff,1,280,280)
     
    function testTexturing1()
    	stage:addChild(sprite1)
    	randomSeed(1,1)
    	for i=1,maxIterations do
    		sprite1:setTexture(texturesArr[random(1,3)])
    	end
    	stage:removeChild(sprite1)
    end
     
    function testTexturing2()
    	stage:addChild(pix1)
    	randomSeed(1,1)
    	for i=1,maxIterations do
    		pix1:setTexture(texturesArr[random(1,3)])
    	end
    	stage:removeChild(pix1)
    end
     
    --Start testing:
    Core.profilerReset()
    Core.profilerStart()
    for loop=1,10 do
    	testTexturing1()
    	testTexturing2()
    end
    Core.profilerStop()
     
    --Print results:
    result=Core.profilerReport()
    print("Number of tests:",maxIterations*10)
     
    for k,v in pairs(result) do
    	local found=false
     
    	for k2,v2 in pairs(v) do
    		if found and k2=="time" then print(v1,v2) end
    		if k2=="name" and string.sub(v2,1,4)=="test" then v1=v2 found=true end
    	end
    end
    zip
    zip
    benchmarkTexturePerfomance.zip
    82K
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • Probably there's a room for optimization, I don't know how {transparentColor} options affect perfomance, if we can disable them totally.

    P. S. WIth disabled texture filtering perfomance is the same.
    local texturesArr={
    	Texture.new("1.jpg"), --no 'true' flag for filtering
    	Texture.new("2.jpg"),
    	Texture.new("3.jpg")
    }
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • Great! By "sprite" you mean bitmap, right?
    My Gideros games: www.totebo.com
  • It could be though that gpu drawing of pixel is faster than bitmap depending on how opengl draws it and how the list is arranged.

    To profile 'drawing' you need to draw x amount and see when they go over a frame, the x count is the effective speed - the higher the better.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • totebo said:

    Great! By "sprite" you mean bitmap, right?

    yep, bitmap
    (sorry, I usually call all the pictures 'sprites', though term 'bitmap' should've been used in this case)

    It could be though that gpu drawing of pixel is faster than bitmap depending on how opengl draws it and how the list is arranged.

    To profile 'drawing' you need to draw x amount and see when they go over a frame, the x count is the effective speed - the higher the better.

    So question is not answered then. :/
    Can you pls provide quick example how to test it properly?
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • Something like this (untested) might work for bitmaps...
    local random = math.random
     
    -- number of bitmaps to change each iteration
    local count = 500
     
    -- a texturepack containing 6 multicolored 64x64 tiles
    local pack = TexturePack.new("tiles.txt", "tiles.png")
     
    -- some debug text
    local info = TextField.new(nil, '')
    info:setTextColor(0xa0b0c0)
    info:setScale(3)
    info:setPosition(8, 24)
     
    -- somewhere to hang the bitmaps
    local objects = Sprite.new()
     
    -- create a bunch of bitmaps
    local bitmaps = {}
    for i = 1, 10000 do
      local bitmap = Bitmap.new(pack:getTextureRegion('t' .. random(1, 6) .. '.png'))
      bitmap:setPosition(random(1, 320 - 64), random(1, 480 - 64))
      bitmaps[#bitmaps + 1] = bitmap
    end
     
    -- add 100 bitmaps to the next iteration
    local function onTouchBegin(e)
      count += 100
    end
     
    -- retexture bitmaps
    local function onEnterFrame(e)
      local random = math.random
     
      objects:removeFromParent()
      objects = nil
     
      objects = Sprite.new()
      for i = 1, count do
        objects:addChild(bitmaps[i])
      end
      objects:addChild(info)
      stage:addChild(objects)
     
      local start = os.timer()
      for i = 1, count do
        local bitmap = bitmaps[i]
        bitmap:setTextureRegion(pack:getTextureRegion('t' .. random(1, 6) .. '.png'))
      end
      local elapsed = math.floor((os.timer() - start) * 1000)
      info:setText(count .. ' bitmaps in ' .. elapsed .. 'ms')
    end
     
    -- add listeners
    stage:addEventListener(Event.TOUCHES_BEGIN, onTouchBegin)
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
    I guess you want to be aiming to see how many will draw in about 16ms which is one frame? I dunno but it's a starting point ;)

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited August 2018
    antix said:

    Something like this (untested) might work for bitmaps...

    local random = math.random
     
    -- number of bitmaps to change each iteration
    local count = 500
     
    -- a texturepack containing 6 multicolored 64x64 tiles
    local pack = TexturePack.new("tiles.txt", "tiles.png")
     
    -- some debug text
    local info = TextField.new(nil, '')
    info:setTextColor(0xa0b0c0)
    info:setScale(3)
    info:setPosition(8, 24)
     
    -- somewhere to hang the bitmaps
    local objects = Sprite.new()
     
    -- create a bunch of bitmaps
    local bitmaps = {}
    for i = 1, 10000 do
      local bitmap = Bitmap.new(pack:getTextureRegion('t' .. random(1, 6) .. '.png'))
      bitmap:setPosition(random(1, 320 - 64), random(1, 480 - 64))
      bitmaps[#bitmaps + 1] = bitmap
    end
     
    -- add 100 bitmaps to the next iteration
    local function onTouchBegin(e)
      count += 100
    end
     
    -- retexture bitmaps
    local function onEnterFrame(e)
      local random = math.random
     
      objects:removeFromParent()
      objects = nil
     
      objects = Sprite.new()
      for i = 1, count do
        objects:addChild(bitmaps[i])
      end
      objects:addChild(info)
      stage:addChild(objects)
     
      local start = os.timer()
      for i = 1, count do
        local bitmap = bitmaps[i]
        bitmap:setTextureRegion(pack:getTextureRegion('t' .. random(1, 6) .. '.png'))
      end
      local elapsed = math.floor((os.timer() - start) * 1000)
      info:setText(count .. ' bitmaps in ' .. elapsed .. 'ms')
    end
     
    -- add listeners
    stage:addEventListener(Event.TOUCHES_BEGIN, onTouchBegin)
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

    I guess you want to be aiming to see how many will draw in about 16ms which is one frame? I dunno but it's a starting point ;)
    Good idea, Thx! :smile:
    I've tested your code as it is, and with Pixel instead of bitmap:
    --local bitmap = Bitmap.new(pack:getTextureRegion('t' .. random(1, 6) .. '.png')) --antix' original line
    local bitmap = Pixel.new(0xffffff,1,280,280) --make it pixel instead of bitmap
    If I got it right, it seems that Bitmap without doubt perfoms better, maybe even more than 20%.
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • Nice one, thanks guys!
    My Gideros games: www.totebo.com
Sign In or Register to comment.