Quote: "
True memblocks are old
"
Not old really....Im not having a go at memblocks, i use them all the time and they are necessary for certain things like getting data into an image in a way that isnt covered by other commands....my point was that they aren't always needed to do easy jobs and are slower then GPU based rendering...which really is true
Quote: "
But Bengismo I have proof somewhere on my PC where you copy thousands of fullhd images in seconds using a memblocks. I agree it is slower then render to image but still fast enough even on low end mobiles so I am no entirely wrong."
Really??? you have code that copies thousands of HD images in seconds using memblocks in AppGameKit???


....im sure we would all like to see it
// Project: Memblockspeedtest
// Created: 2019-04-10
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Memblockspeedtest" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
blk = CreateMemblock(4*4096*2160)
do
offset = 0
Start# = Timer()
for x = 0 to 4095
for y = 0 to 2159
SetMemblockInt(blk,offset,0xffffffff)
inc offset,4
next y
next x
total# = Timer() - Start#
Print( "FPS: " + str(ScreenFPS()) )
Print( "Time to write 1 HD image: " +str(total#) )
Sync()
loop
This code is a simple test just to fill a HD memblock with black ...if you do set every pixel then it takes an age. More than half a second per image on old machines!!
Render to a render image and call clearscreen takes microseconds!! Its similar results when rendering parts of images too.
Anyway...rather than argue it.... (theres no point in that we are all here to help and learn)
Here is an example of using memblocks where you can literally make holes on an image. Its actually in 3d but obviously it would work in 2d too. It only makes 5 pixels at a time transparent with the F key pressed so it keeps the speed high by only processing a few pixels each frame. Its based on a little example I did ages ago and posted on here
// Project: 3D Painting
// Created: 2019-04-10
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Real time 3D image memblock editing" )
SetWindowSize( 800, 600, 0 )
SetWindowAllowResize( 0 ) // dont allow the user to resize the window
// set display properties
SetVirtualResolution( 800, 600 )
SetCameraPosition(1,0,5,-10)
SetSyncRate( 300, 0 ) // 300fps for speed testing
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global xw = 200
global yw = 200
// create a virtual backbuffer to draw on
Im = CreateImageMemblock(1, xw, yw)
// create a sprite that uses the image memblock created above
//CreateSprite(1,1)
// create the 3d objects
PlaneObj = CreateObjectPlane(10,10)
SetObjectImage(PlaneObj,1,0)
SetObjectTransparency(PlaneObj,1)
// Ground plane
GroundObj = CreateObjectPlane(100,100)
RotateObjectGlobalX(GroundObj,90)
SetObjectPosition(GroundObj, 0,-10,0)
SetObjectColor(GroundObj,5,120,5,255)
// skybox
SetSkyBoxVisible(1)
SetSkyBoxHorizonColor(10,10,100)
SetSkyBoxSkyColor(20,20,200)
// Make some legs for our painting sign
PostL = CreateObjectBox(0.8,15,0.8)
SetObjectColor(PostL,120,120,10,255)
SetObjectPosition(PostL,-4,-5,0.5)
PostR = CloneObject(PostL)
SetObjectPosition(PostR,4,-5,0.5)
SetPrintSize(20)
do
if GetPointerState() = 1
x = GetPointerX()
y = GetPointerY()
Camx# = GetCameraX(1)
Camy# = GetCameraY(1)
Camz# = GetCameraZ(1)
Dirx# = Camx# + (Get3DVectorXFromScreen( x, y )*100)
Diry# = Camy# + (Get3DVectorYFromScreen( x, y )*100)
Dirz# = Camz# + (Get3DVectorZFromScreen( x, y )*100)
ObjHit = ObjectRayCast(0,Camx#,Camy#,Camz#,Dirx#,Diry#,Dirz#)
if objhit = PlaneObj
xp# = (GetObjectRayCastX(0) +5)/10*xw
yp# = (-GetObjectRayCastY(0) + 5)/10*yw
Dot(xp#,yp#)
Dot(xp#-1,yp#)
Dot(xp#+1,yp#)
Dot(xp#,yp#+1)
Dot(xp#,yp#-1)
//Dot(xp#,yp#)
//Print ("Hit: X " + str(xp#) + " y " + str(yp#) )
endif
endif
if GetRawKeyState(70) = 1 // pressing "F" will create a hole in the canvas
x = GetPointerX()
y = GetPointerY()
Camx# = GetCameraX(1)
Camy# = GetCameraY(1)
Camz# = GetCameraZ(1)
Dirx# = Camx# + (Get3DVectorXFromScreen( x, y )*100)
Diry# = Camy# + (Get3DVectorYFromScreen( x, y )*100)
Dirz# = Camz# + (Get3DVectorZFromScreen( x, y )*100)
ObjHit = ObjectRayCast(0,Camx#,Camy#,Camz#,Dirx#,Diry#,Dirz#)
if objhit = PlaneObj
xp# = (GetObjectRayCastX(0) +5)/10*xw
yp# = (-GetObjectRayCastY(0) + 5)/10*yw
// Draw a crosss with alpha
DotA(xp#,yp#,0,0,0,0)
DotA(xp#-1,yp#,0,0,0,0)
DotA(xp#+1,yp#,0,0,0,0)
DotA(xp#,yp#+1,0,0,0,0)
DotA(xp#,yp#-1,0,0,0,0)
endif
endif
if getrawKeyPressed( 67) then ClearImageMemblock(0xffffffff)
// Create a new colour
SetDotColour(Random(20,255),Random(20,255),Random(20,255))
// update the image from the memblock
CreateImageFromMemblock(1,Im)
// If mouse is pressed - Clear the "backbuffer" (the memblock)
//if GetPointerPressed() then ClearImageMemblock()
FPSCamera()
Print( "FPS: " + str(ScreenFPS()) )
Print( "Press left mouse to draw colour onto the canvas" )
Print( "Use WSAD to fly around" )
Print( "Use right mouse to rotate camera" )
Print( "Press C to clear your canvas" )
Print( "Press F to create a hole in the canvas" )
Sync()
loop
// ALL THE REAL WORK IS DONE BELOW
// Variables to store the memblock and current colour
global Im
global Rv
global Bv
global Gv
// This sets the current plot colour
function SetDotColour(Red as integer, Green as integer, Blue as integer)
Rv = Red
Bv = Blue
Gv = Green
endfunction
// this plots a single pixel
function Dot(x as integer,y as integer)
if x<0 then exitfunction
if y<0 then exitfunction
if x>xw then exitfunction
if y>yw-1 then exitfunction
offset = 12 + (4*(x + (y*GetMemblockInt(Im,0))))
SetMemblockbyte(Im,offset,Rv) // red
SetMemblockbyte(Im,offset+1,Gv) // green
SetMemblockbyte(Im,offset+2,Bv) // blue
SetMemblockbyte(Im,offset+3,255) // alpha
endfunction
// version of DOt that includes alpha
function DotA(x as integer,y as integer,rt,gt,bt,at)
if x<0 then exitfunction
if y<0 then exitfunction
if x>xw then exitfunction
if y>yw-1 then exitfunction
offset = 12 + (4*(x + (y*GetMemblockInt(Im,0))))
SetMemblockbyte(Im,offset,Rt) // red
SetMemblockbyte(Im,offset+1,Gt) // green
SetMemblockbyte(Im,offset+2,Bt) // blue
SetMemblockbyte(Im,offset+3,at) // alpha
endfunction
// this clears the virtual backbuffer
function ClearImageMemblock(col as integer)
offset = 12
for ix = 0 to GetMemblockInt(Im,0)-1
for iy = 0 to GetMemblockInt(Im,4)-1
SetMemblockInt(Im,offset,col) // clears to white!
offset = offset + 4
next iy
next ix
// Theres a quicker way of doing this but I left it like this to show how it works
endfunction
function CreateImageMemblock(ID as integer, width as integer, height as integer)
Im = CreateMemblock(12 + (4 * width * height))
// Set the width and heights etc..
SetMemblockInt(Im,0,width)
SetMemblockInt(Im,4,height)
SetMemblockInt(Im,8,32)
pixels = width*height
bytes = pixels*4
for i=12 to bytes+11
SetMemblockByte(Im,i,255)
next i
// Create an image from the memblock
CreateImageFromMemblock(ID,Im)
endfunction Im
// this plots a single pixel
function GetPixel(x as integer,y as integer)
offset = 12 + (4*(x + (y*GetMemblockInt(Im,0))))
col = GetMemblockInt(Im,offset)
endfunction col
// camera starts in free mode
global cameraMode = 0
global startx#
global starty#
global angx#
global angy#
global pressed
Function FPSCamera()
// move the camera
speed# = GetFrameTime()*15
if ( GetRawKeyState( 16 ) ) then speed# = speed#*0.2
//if ( cameraMode = 1 ) then speed# = 0.05
if ( GetRawKeyState( 87 ) ) then MoveCameraLocalZ( 1, speed# )
if ( GetRawKeyState( 83 ) ) then MoveCameraLocalZ( 1, -speed# )
if ( GetRawKeyState( 65 ) ) then MoveCameraLocalX( 1, -speed# )
if ( GetRawKeyState( 68 ) ) then MoveCameraLocalX( 1, speed# )
if ( GetRawKeyState( 81 ) ) then MoveCameraLocalY( 1, -speed# )
if ( GetRawKeyState( 69 ) ) then MoveCameraLocalY( 1, speed# )
// rotate the camera
//if ( GetPointerPressed() )
if ( GetRawMouseRightPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
// if ( GetPointerState() = 1 )
if ( GetRawMouseRightState() = 1)
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
Endfunction