Were can I find information on best practices for generating graphics in textures? In GameMaker, it is so easy to just create a surface, set the surface target, draw to it (like a circle for example) and then reset surface target and clear the surface when I am done with it.

With godot, I am confused as to were I need to find guidence for things like this? So any links to things I should be reading into other than the godot docs would be apriciated thanks!

I have a TextureButton and have set the texture_normal to a new ViewportTexture resource. I have assigned this to a viewport. Works fine but this doesn't seem all that efficient because what if I do not need to modify the contents of the viewport any longer but also want to retain the image data.

So I tried removing the viewport node and its children at runtime (which updates the texture). But I only want to get rid of this for optimization (not to actually get rid of what can be viewed from the ViewportTexture. A solution I have thought of was to copy the texture from the ViewportTexture to a new texture and then use that as the texture for the TextureButton.

I am so baffled by the documentation, I just simply want to know how to copy textures and cannot even find a solution through search. What baffles me even more, is that I still do not know the best practice for a simple drawing to a texture. For example, I know you have functions like draw_circle, in the CanvasItem but my understanding is that you must use a viewport in order to capture those draws (similar to how you would using surfaces in GameMaker).

Is there a way to pause or lock updates to the ViewportTexture or do I need to use a copy of the texture to do that?

Thanks

You can set the Viewport to render only once by setting its flag to UPDATE_ONCE, which should retrain the texture data even if the nodes are deleted (not sure if the Viewport is deleted what will happen though). You could also set it to UPDATE_DISABLED, which might work if UPDATE_ONCE doesn't.

Another option is to take the ViewportTexture and get it's ImageTexture data, which is what the Screen Capture Demo does.

Getting a texture out of a Viewport isn't very well documented though, and while I've used it a few times, I haven't had too many cases where I needed a static texture out of it, so I'm not sure if there are better ways.

From what I remember using a Viewport is the recommended way to draw to a texture, as the draw functions in CanvasItem call the VisualServer to add each element, if I am remembering correctly, so it's not very efficient nor in a texture format, unfortunately.

If you just need simple drawing like lines or circles, you don't need a viewport. Viewports are fairly heavy, so I would not base a game around having a large amount of them. But if you need complex drawing (e.g. more than just lines) then it may be unavoidable.

@cybereality said: If you just need simple drawing like lines or circles, you don't need a viewport. Viewports are fairly heavy, so I would not base a game around having a large amount of them. But if you need complex drawing (e.g. more than just lines) then it may be unavoidable.

Wouldn't using a viewport be the only way to capture draw data from a CanvasItem?

Are you meaning to say it is more efficient to just draw to a CanvasItem directly and leave out the capturing data for a new texture all together?

Yes, you can draw directly on CanvasItems. I am not sure why you would need a Viewport or Texture.

a year later