I have a texture atlas that contains many small pieces. I’d like to draw portions of this on the screen (in screen coordinates - not in the scene). How do I do this? I didn’t see anything in GuiTexture or Gui.DrawTexture, or Gui.label that supported specifying a source rectangle.
Yes, this is possible. I am not sure how.
I wonder why you don’t simply split the image instead though?
Splitting the image will result in numerous textures - I thought about this, but thought that so many renderstate changes would cause quite a slowdown. Maybe I’m too old-school, but I’d just like to set the material, and then draw a bunch of rectangles.
You can use BeginArea / BeginGroup
But that won’t help on state end. The UI does not batch at all, every single GUI / GUILayout command results in an own drawcall etc
Also the UI doesn’t affect render states, its not like you can use materials or affect the render state in any form during or for the UI draw
Hmmm - BeginArea/BeginGroup looks like its for screen layout, that’s not what I’m really after. What I’m looking for is to just draw a portion of a texture. Definitely the UI affects renderstate, after all it has to be rendered, and each texture swap is a renderstate change. Still, for what I’m doing, I guess it won’t be too bad. I’ll split up the texture and just make individual calls. The obvious choice is to just pony up the cash for the Pro version (and get access to the GL class, or Graphics.DrawTexture), but I was hoping to make some scripts to share with the community, many who don’t have the pro version.
Thanks, guys!
The might be looking as if they are for that but with these commands you also can clip other things and thats exactly what you want to do, clip part of the texture from rendering.
you can not draw a subarea directly, if you want to do that take a real mesh and use UV coordiantes …
As for the texture switch: will happen anyway as you will see. As mentioned, each GUI / GUILayout command is completely on its own and runs on its own (if I recall right, they under the hood result in an own DrawMesh call from Graphics class), they don’t batch to reduce state changes or alike, I doubt they even verify the current texture in use to not switch so even if you redraw the same texture 50 times, its likely 50 switches but definitely 50 drawcalls
Thanks, I didn’t think of that. I’ll time it both ways, and see if it makes any difference when drawing.