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

请教 整数颜色到矢量 转换问题 #8

Open
chenxiayun opened this issue Apr 19, 2022 · 2 comments
Open

请教 整数颜色到矢量 转换问题 #8

chenxiayun opened this issue Apr 19, 2022 · 2 comments

Comments

@chenxiayun
Copy link

为什么转换代码是
inline static Vec4f vector_from_color(uint32_t rgba) { Vec4f out; out.r = ((rgba >> 16) & 0xff) / 255.0f; out.g = ((rgba >> 8) & 0xff) / 255.0f; out.b = ((rgba >> 0) & 0xff) / 255.0f; out.a = ((rgba >> 24) & 0xff) / 255.0f; return out; }

而不是
inline static Vec4f vector_from_color(uint32_t rgba) { Vec4f out; out.r = ((rgba >> 0) & 0xff) / 255.0f; out.g = ((rgba >> 8) & 0xff) / 255.0f; out.b = ((rgba >> 16) & 0xff) / 255.0f; out.a = ((rgba >> 24 & 0xff)) / 255.0f; return out; }

第一个字节不应该储存的是r吗,是我有哪部分知识遗漏了吗,望大佬赐教

@skywind3000
Copy link
Owner

你确实是知识有遗漏,谁说第一个字节就要是 r ?这个叫做 pixel format,光 32 位,就有:

A8R8G8B8
A8B8G8R8
P8R8G8B8
P8B8G8R8
R8G8B8A8
B8G8R8A8
R8G8B8P8
A2R10G10B10
A2B10G10R10
...

懒得给你写了,像素格式是由:rmask, gmask, bmask, amask 决定的,无穷无尽。

@chenxiayun
Copy link
Author

感谢大佬回答,图形学方面我确实有很多地方不知道从何学起。这几天学习了大佬代码,感觉对渲染的认知相比以往提升了很多,继续向大佬学习呀

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

No branches or pull requests

2 participants