GML Quick question (surfaces/draw events)

HNM

Member
If I use the 3 different draw events to manipulate a surface, is it enough to check if it exists just in the Draw Begin event?
 

Zhanghua

Member
no. you should push the surface to buffer after finishing all draw operation.
and pop it back from buffer when the surface vanishing before painting.
 

HNM

Member
no. you should push the surface to buffer after finishing all draw operation.
and pop it back from buffer when the surface vanishing before painting.
Sorry, I don't know what push to buffer/pop back from buffer means. I'm drawing a bunch of sprites on a surface using a shader, then drawing the surface with a different shader. I thought it would be "cleaner" to use Draw Begin and Draw.
 
Should be, the Draw Begin, Draw and Draw End all execute within a single frame, so I can't imagine a situation where it exists in one and not the others.

EDIT: I think @Zhanghua was thinking that you were setting the surface target in the Draw Begin and then trying to draw to it in the Draw event. I assume you're not. If you're just checking if the surface exists and creating it if it doesn't in the Draw Begin, and setting the target and drawing to it in the Draw, that's fine. If you're setting the target in the Draw Begin and then trying to draw to it in the Draw event, that's not a good idea.
 
  • Like
Reactions: HNM

HNM

Member
EDIT: I think @Zhanghua was thinking that you were setting the surface target in the Draw Begin and then trying to draw to it in the Draw event. I assume you're not. If you're just checking if the surface exists and creating it if it doesn't in the Draw Begin, and setting the target and drawing to it in the Draw, that's fine. If you're setting the target in the Draw Begin and then trying to draw to it in the Draw event, that's not a good idea.
Cause when you set the target, all things are drawn to it until you reset, right? I'm setting it only in the main draw, right before I need to clear/draw on it and then immediately resetting. Thanks for clearing it up, it's all much more organised now.
 

NightFrost

Member
I don't think GMS could lose access to a memory allocation in the middle of a step. It would require some other process to request it, but since GMS process is being presently executed, I'm not sure that could happen. Don't know how multithreading would affect this. Depends on how the OS handles requests for and reservations of the memory and what gets priority and what gets its request denied and on what grounds. But I think a reasonable assumption is a program can't lose its reservations when it is executing, as it would create a host of problems, and no problems are created by not doing this. It seems it would be wiser to wait for a process to finish its cycle before mucking about with its memory reservations.
 
  • Like
Reactions: HNM
Top