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
New Textures aren't zeroed #194
Comments
If the doc doesn't explicitly says that it should be zeroed, then it's not a bug. Moreover, as you said, this behavior makes sense. So it's more a feature request actually 😉 But what's the point of defining the content of an uninitialized texture? Who's going to rely on that? If you want a black texture, then explicitly create one in your code. Uploading pixel data to every newly created texture would make texture creation slower, and then the 99.9% of people that don't need that would complain. |
The mentioned constructor simply calls the other mentioned constructor with the color black. SFML.Net/src/SFML.Graphics/Image.cs Lines 25 to 42 in 43926e9
|
@eXpl0it3r don't confuse between |
Ah, I had the feeling I was missing something, but somehow forgot that original code was about the texture. I'm also not sure what exactly the goal is of creating an empty texture. If you want to update the texture frequently, you'd probably want a RenderTexture, that you then can also clear with whatever color you want. If you just want a black rectangle, you could also use a RectangleShape. Otherwise you'd load an image replacing the texture content. So what exactly is the use case of a created "empty" texture? |
"[...] and then the 99.9% of people that don't need that would complain."
A simplified explanation of the use is a Paint-like program: A simple canvas, a pencil, brushes, a fill-option, and some other stuff.
|
There's already a way to do it, as you mentioned, and it can even be a one-liner:
So is it worth adding a new constructor, just to avoid typing |
Ah yes, that's a very logical one-liner, which I feel quite dumb for not thinking of. Imagine you're in the unfortunate position of having to create, say, a 10'000 by 10'000 empty Texture for whatever reason.
Kind regards, and many thanks for your time! |
I don't know any low-level way of "creating an empty texture" directly. As far as I know, creating a buffer in RAM and then uploading it to the GPU to initialize the texture, is the only way to do it. Even if the texture is full of the same color. |
Preface: I've never (knowingly) worked with code doing stuff with, on, or near the GPU. I always thought of the GPU as a tiny PC of its own, it has RAM, it has a processing unit. It's just clocked lower, but more parallel-capable. (And a different instruction-set) (If this idea is wildly incorrect, please do correct me.) If this idea is semi-correct, you might be able to tell it (the GPU) to grab an N-sized chunk of memory, and write a specific value (color) to each address in that chunk, possibly in parallel, to speed it along.
I am very much willing to settle for. But possibly to avoid future people walking into the "Why isn't this new Texture empty?"-thing, a note in the docs might be useful. |
Sure, an improvement to the documentation would not hurt 👍 However, you should never rely on implicit initialization states. Always make it explicit in your code. Especially when those are undocumented assumptions 😉 |
That is very sound advice, which I will be taking with me into the future, thank you. |
Anyone interested in providing an update to the documentation? |
* Addresses requests in SFML#194 and SFML#195 * Updated all [Obsolete] attributes to be less repetitive * Added a large number of quick reference links to existing summaries * Corrected various typos and unparsable markup(\a and \p) * Added additional formatting to numerous summaries, resulting in more readable tooltips * Added a suggestion to use TimeSpan over SFML's Time while working within a managed environment
* Addresses requests in SFML#194 and SFML#195 * Updated all [Obsolete] attributes to be less repetitive * Added a large number of quick reference links to existing summaries * Corrected various typos and unparsable markup(\a and \p) * Added additional formatting to numerous summaries, resulting in more readable tooltips * Added a suggestion to use TimeSpan over SFML's Time while working within a managed environment * Added a warning to `VertexBuffer.NativeHandle`'s getter informing the end-user that most people shouldn't need that property and to be cautious
* Addresses requests in SFML#194 and SFML#195 * Updated all [Obsolete] attributes to be less repetitive * Added a large number of quick reference links to existing summaries * Corrected various typos and unparsable markup(\a and \p) * Added additional formatting to numerous summaries, resulting in more readable tooltips * Added a suggestion to use TimeSpan over SFML's Time while working within a managed environment
* Addresses requests in #194 and #195 * Updated all [Obsolete] attributes to be less repetitive * Added a large number of quick reference links to existing summaries * Corrected various typos and unparsable markup(\a and \p) * Added additional formatting to numerous summaries, resulting in more readable tooltips * Added a suggestion to use TimeSpan over SFML's Time while working within a managed environment
Fixed in SFML.Net with #239 |
Hello!
I managed to stumble over a bug in a private project, and after quite a bit of digging and testing managed to conclude where it came from.
The bug was that generated images sometimes contained semi-random pixels/images, even though that shouldn't be there.
After bug-hunting I discovered that
Did not produce an image where all pixels were zero (or equivalent).
On one hand this makes sense, as it gets assigned a chunk of memory, and if there's still data-remnants in that chunk, well, that's now part of its data.
On the other hand, I'd expect a new Texture to be empty; to contain nothing!
TL;DR:
Texture(uint sizeX, uint sizeY)
does not create an empty Texture.This can be circumvented by doing:
But I'd argue that expecting a newly created Texture to be empty, is not unreasonable.
Here's a very small thingy to demonstrate that newly created Texures aren't empty. (Or possibly that
CopyToImage()
grabs data that should be zeroes.)Greetings, and kind regards!
~Sjaak
The text was updated successfully, but these errors were encountered: