I am going to write program for image manipulation. For drawing with pen and modifying images. So I need buffer for storing image peaces(layers for example). Later this peaces will be apply to image(just copyed or other methods(f.e. xor)). And yesterday I find out that color uses float for each color element so it takes 4 time more memory. 1) I suppoce it also takes much more time to process color than color 32. Am I right? Or in the end unity convert color32 to color before pass to opengl? 2) why? as I remember opengl support 4 byte color instance. So why Unity prefer floats? 3) Is it possible some how use GL library for my targets?
You assumed, that unity uses opengl. That's true, unless your preferred platform is windows, then it'll use directx (for some reason). I wouldn't suggest actually storing your layers or image pieces in an array of Color, that's exactly, why Texture2D exists. Opengl stores those values in floats too, because telling a led, how much dimmed it should be is way easier, than telling the cpu, that it should be 158/256 and leaving him calculate that value.
Dear gorbit99, Thank you for your answer. Lets consider real situation. I have pen with next pixels alpha data. 50, 100, 50 100, 200, 100 50, 100, 50 I have to draw line with this pen on image. As I understand first I have to create some buffer. Find each pixel of line and put this values around that pixels. And I have to save on pixel values with bigger alpha. so this 0,0,0 0,0,0 0,0,0 0,0,0 0,0,0 will become 50, 100, 50 100, 200, 100 50, 100, 50 0, 0, 0 0, 0, 0 then this 50, 100, 50 100, 200, 100 100, 200, 100 50, 100, 50 0, 0, 0 and so on. And then I have to merge this values with real image pixel values. Would it looks like this with Texture2D? Code (CSharp): Texture2D pen; Texture2D buffer; Texture2D image; Color[] penColors=pen.GetPixels(); Color[] bufferColors=buffer.GetPixels(); //copy penColors to bufferColors one by one with necessary logic. Color[] imageColors=image.GetPixels(); //copy bufferColors to imageColors one by one with necessary logic. Or there better solution for this? for example like OpenGL shaders.
Your answer is great. The reason why Unity uses Directx on Windows is because Directx is designed by Microsoft and gives better results on Windows than OpenGL. It just wouldn't make sense to use OpenGL on Windows. EDIT: As Erid5h5 said, if you really want to, you can use OpenGL on Windows. However, this probably will result in worse performance.
Don't use Color, use Color32, it's much faster and uses 4X less memory. Don't concern yourself with implementation details of OpenGL or whatever since Unity handles it. (Also, Unity uses OpenGL on Windows if you select that in the player settings.) --Eric
Unfortunately, there doesn't seem to be a GetPixels32 equivalent of GetPixels(int x, int y, int blockWidth, int blockHeight)
For most ordinary images, no. Almost all image formats only support 256 values per channel and that's also how the images are usually stored in GPU memory. However since HDR is a thing there may be cases where the underlying type has a higher precision than 8 bit per channel. In those cases you would have to use Color instead. edit: I'm not even sure which HDR image formats Unity can load. According to this wikipedia list there aren't many file formats that actually support HDR images.
Many years later, curious, is there a way to use native array of bytes? ex. Code (CSharp): var layout = new[] { new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3), new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.Byte,4) // <------- THIS ---------- }; UseCase = mesh.SetVertexBufferParams(xxxx)