Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am seeing an issue with LargeTexture and draw_texture_rect_region() #36445

Closed
ThreeMileJump opened this issue Feb 22, 2020 · 2 comments · Fixed by #48269
Closed

I am seeing an issue with LargeTexture and draw_texture_rect_region() #36445

ThreeMileJump opened this issue Feb 22, 2020 · 2 comments · Fixed by #48269

Comments

@ThreeMileJump
Copy link

Godot version: 3.2

Linux Mint 19.1 i5 6500 CPU nvidia GPU

LargeTexture and draw_texture_rect_region()

Src offset from 0,0 results in gaps between the textures that comprise the LargeTexture.

I am making a tiled array of ImageTextures and adding them to a LargeTexture. The idea then is to use draw_texture_rect_region() to draw a sub rectangle from the LargeTexture to the screen. Every tile can then be updated from its Image.

Mostly the draw_texture_rect_region() works. The first Rect2 parameter is the destination and the second is the source in the LargeTexture. However, if the offset of the source rect is other than (0,0) then the draw does not work correctly. The offset is added to each of the pieces of the LargeTexture and you get a space in the result. The gap in the x dimension is the x offset, and the y offset is larger suggesting a product of the offsets.
I managed to get a result by putting the LargeTexture in a viewport and then faking the result by changing the scaling and offset - which results in correct windowing of the LargeTexture. That seems to indicate that drawing a sub rect of a LargeTexture is possible, but the draw_texture_rect_region() has a problem when applied to LargeTexture. Also verified this error when using a a LargeTexture in a sprite node.

I am putting together 4 256x256 textures and then using a sprite (with rect enabled) to display a region. It isn't Sprite, because I get the same thing with draw_texture_rect_region as well. (which must be what the Sprite node is using). Picture worth a 1000 words ...

https://cdn.discordapp.com/attachments/212250894228652034/674544132164812811/Rect_Region_offset_0_0.jpg
https://cdn.discordapp.com/attachments/212250894228652034/674544215547445248/Rect_Region_offset_10_0.jpg
https://cdn.discordapp.com/attachments/212250894228652034/674544278080585728/Rect_Region_offset_10_10.jpg

Steps to reproduce: Create a LargeTexture of 4 256x256 pixels textures and attempt to to copy a region from the LargeTexture using draw_texture_rect_region() with a non zero source offset

@themangomago
Copy link

themangomago commented Apr 11, 2020

I've run into the same issue.

Stripped down project (3.2.1):
LargeTexture.zip

This is an ugly workaround based on the code from Texture.c
`
func drawRectRegion(texture: LargeTexture, view : Rect2, textureRect : Rect2):
var scale = view.size / textureRect.size

var offset = Vector2(0, 0)

for i in range(texture.get_piece_count()):
	var rect = Rect2(texture.get_piece_offset(i), texture.get_piece_texture(i).get_size())
	if textureRect.intersects(rect):
		var local = textureRect.clip(rect)
		var target = local
		target.size *= scale
		
		target.position = view.position + (textureRect.position + rect.position) * scale;
		local.position -= rect.position

		var tex = texture.get_piece_texture(i)
		
		if target.position.x < tex.get_size().x:
			offset.x = target.position.x
			target.position.x *= 2
		if target.position.y < tex.get_size().y:
			offset.y = target.position.y
			target.position.y *= 2
		

		target.position -= offset * 2
		
		draw_texture_rect_region(tex, target, local)

`

@ThreeMileJump
Copy link
Author

My guess is that not many people use large textures and hopefully it will be addressed in the new 4.0 code. There is not a lot of point in patching obscure problems when such a big graphics update is being developed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants