Core/Color: Switch formal from RGBA8 to RGBA32F
This commit is contained in:
parent
de53c88c01
commit
e7274b24e9
|
|
@ -338,7 +338,7 @@ int main()
|
|||
|
||||
std::random_device rng;
|
||||
std::mt19937 randomEngine(rng());
|
||||
std::uniform_int_distribution<unsigned int> colorDis(0, 255);
|
||||
std::uniform_real_distribution<float> colorDis(0.f, 1.f);
|
||||
std::uniform_real_distribution<float> heightDis(0.15f, 1.f);
|
||||
std::uniform_real_distribution<float> posDis(-10.f, 10.f);
|
||||
std::uniform_real_distribution<float> dirDis(-1.f, 1.f);
|
||||
|
|
@ -1174,11 +1174,11 @@ int main()
|
|||
{
|
||||
float rotationSpeed = ComputeLightAnimationSpeed(viewerPos);
|
||||
|
||||
auto& whiteLight = spotLights.emplace_back();
|
||||
whiteLight.color = Nz::Color(100, 100, 255);
|
||||
whiteLight.radius = 5.f;
|
||||
whiteLight.position = AnimateLightPosition(viewerPos, rotationSpeed, -elapsedTime);
|
||||
whiteLight.direction = AnimateLightDirection(camQuat * Nz::Vector3f::Forward(), rotationSpeed, -elapsedTime);
|
||||
auto& spotLight = spotLights.emplace_back();
|
||||
spotLight.color = Nz::Color(0.4f, 0.4f, 1.f);
|
||||
spotLight.radius = 5.f;
|
||||
spotLight.position = AnimateLightPosition(viewerPos, rotationSpeed, -elapsedTime);
|
||||
spotLight.direction = AnimateLightDirection(camQuat * Nz::Vector3f::Forward(), rotationSpeed, -elapsedTime);
|
||||
|
||||
lightUpdate = true;
|
||||
}
|
||||
|
|
@ -1524,7 +1524,7 @@ int main()
|
|||
Nz::Vector3f position = AnimateLightPosition(spotLight.position, rotationSpeed, elapsedTime);
|
||||
Nz::Vector3f direction = AnimateLightDirection(spotLight.direction, rotationSpeed, elapsedTime);
|
||||
|
||||
Nz::AccessByOffset<Nz::Vector3f&>(lightDataPtr, colorOffset) = Nz::Vector3f(spotLight.color.r / 255.f, spotLight.color.g / 255.f, spotLight.color.b / 255.f);
|
||||
Nz::AccessByOffset<Nz::Vector3f&>(lightDataPtr, colorOffset) = Nz::Vector3f(spotLight.color.r, spotLight.color.g, spotLight.color.b);
|
||||
Nz::AccessByOffset<Nz::Vector3f&>(lightDataPtr, positionOffset) = position;
|
||||
Nz::AccessByOffset<Nz::Vector3f&>(lightDataPtr, directionOffset) = direction;
|
||||
Nz::AccessByOffset<float&>(lightDataPtr, radiusOffset) = spotLight.radius;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ int main()
|
|||
registry.emplace<Nz::NodeComponent>(viewer);
|
||||
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(viewer, window.GetRenderTarget(), Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateRenderMask(1);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(127, 127, 127));
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
|
||||
std::shared_ptr<Nz::Material> material = std::make_shared<Nz::Material>();
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ int main()
|
|||
registry.emplace<Nz::NodeComponent>(viewer);
|
||||
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(viewer, window.GetRenderTarget());
|
||||
cameraComponent.UpdateRenderMask(1);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(127, 127, 127));
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
|
||||
auto shipCollider = std::make_shared<Nz::ConvexCollider3D>(vertices, vertexMapper.GetVertexCount(), 0.01f);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ int main()
|
|||
{
|
||||
registry.emplace<Nz::NodeComponent>(cameraEntity);
|
||||
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(cameraEntity, mainWindow.GetRenderTarget(), Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(117, 122, 214, 255));
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
|
||||
}
|
||||
|
||||
Nz::SimpleTextDrawer textDrawer;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ int main()
|
|||
{
|
||||
registry.emplace<Nz::NodeComponent>(cameraEntity);
|
||||
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(cameraEntity, mainWindow.GetRenderTarget(), Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(117, 122, 214, 255));
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
|
||||
}
|
||||
|
||||
Nz::SimpleTextDrawer textDrawer;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ int main()
|
|||
{
|
||||
registry.emplace<Nz::NodeComponent>(viewer2D);
|
||||
auto& cameraComponent = registry.emplace<Nz::CameraComponent>(viewer2D, window.GetRenderTarget(), Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(173, 216, 230, 255));
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.678f, 0.847f, 0.9f, 1.f));
|
||||
}
|
||||
|
||||
window.EnableEventPolling(true);
|
||||
|
|
|
|||
|
|
@ -19,9 +19,8 @@ namespace Nz
|
|||
{
|
||||
public:
|
||||
inline Color();
|
||||
inline Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha = 255);
|
||||
inline explicit Color(UInt8 lightness);
|
||||
inline Color(UInt8 color[3], UInt8 alpha = 255);
|
||||
inline Color(float red, float green, float blue, float alpha = 1.f);
|
||||
inline explicit Color(float lightness);
|
||||
inline Color(const Color& color) = default;
|
||||
inline Color(Color&& color) = default;
|
||||
inline ~Color() = default;
|
||||
|
|
@ -46,16 +45,20 @@ namespace Nz
|
|||
static inline Color FromCMYK(float cyan, float magenta, float yellow, float black);
|
||||
static inline Color FromHSL(float hue, float saturation, float lightness);
|
||||
static inline Color FromHSV(float hue, float saturation, float value);
|
||||
static inline Color FromRGB8(UInt8 r, UInt8 g, UInt8 b);
|
||||
static inline Color FromRGBA8(UInt8 r, UInt8 g, UInt8 b, UInt8 a);
|
||||
static inline Color FromXYZ(const Vector3f& vec);
|
||||
static inline Color FromXYZ(float x, float y, float z);
|
||||
static inline void ToCMY(const Color& color, float* cyan, float* magenta, float* yellow);
|
||||
static inline void ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black);
|
||||
static inline void ToHSL(const Color& color, float* hue, float* saturation, float* lightness);
|
||||
static inline void ToHSV(const Color& color, float* hue, float* saturation, float* value);
|
||||
static inline void ToRGB8(const Color& color, UInt8* r, UInt8* g, UInt8* b);
|
||||
static inline void ToRGBA8(const Color& color, UInt8* r, UInt8* g, UInt8* b, UInt8* a = nullptr);
|
||||
static inline void ToXYZ(const Color& color, Vector3f* vec);
|
||||
static inline void ToXYZ(const Color& color, float* x, float* y, float* z);
|
||||
|
||||
UInt8 r, g, b, a;
|
||||
float r, g, b, a;
|
||||
|
||||
static NAZARA_CORE_API const Color Black;
|
||||
static NAZARA_CORE_API const Color Blue;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ namespace Nz
|
|||
/*!
|
||||
* \brief Constructs a Color object by default
|
||||
*/
|
||||
|
||||
inline Color::Color()
|
||||
{
|
||||
}
|
||||
|
|
@ -33,7 +32,7 @@ namespace Nz
|
|||
* \param alpha Alpha value
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha) :
|
||||
inline Color::Color(float red, float green, float blue, float alpha) :
|
||||
r(red),
|
||||
g(green),
|
||||
b(blue),
|
||||
|
|
@ -47,26 +46,11 @@ namespace Nz
|
|||
* \param lightness Value for r, g and b
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 lightness) :
|
||||
inline Color::Color(float lightness) :
|
||||
r(lightness),
|
||||
g(lightness),
|
||||
b(lightness),
|
||||
a(255)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with values
|
||||
*
|
||||
* \param vec[3] vec[0] = red value, vec[1] = green value, vec[2] = blue value
|
||||
* \param alpha Alpha value
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 vec[3], UInt8 alpha) :
|
||||
r(vec[0]),
|
||||
g(vec[1]),
|
||||
b(vec[2]),
|
||||
a(alpha)
|
||||
a(1.f)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +60,7 @@ namespace Nz
|
|||
*/
|
||||
inline bool Color::IsOpaque() const
|
||||
{
|
||||
return a == 255;
|
||||
return a >= 1.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -87,10 +71,10 @@ namespace Nz
|
|||
inline std::string Color::ToString() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
|
||||
ss << "Color(" << r << ", " << g << ", " << b;
|
||||
|
||||
if (a != 255)
|
||||
ss << ", " << static_cast<int>(a);
|
||||
if (!IsOpaque())
|
||||
ss << ", " << a;
|
||||
|
||||
ss << ')';
|
||||
|
||||
|
|
@ -106,12 +90,11 @@ namespace Nz
|
|||
|
||||
inline Color Color::operator+(const Color& color) const
|
||||
{
|
||||
///TODO: Improve this shit
|
||||
Color c;
|
||||
c.r = static_cast<UInt8>(std::min(static_cast<unsigned int>(r) + static_cast<unsigned int>(color.r), 255U));
|
||||
c.g = static_cast<UInt8>(std::min(static_cast<unsigned int>(g) + static_cast<unsigned int>(color.g), 255U));
|
||||
c.b = static_cast<UInt8>(std::min(static_cast<unsigned int>(b) + static_cast<unsigned int>(color.b), 255U));
|
||||
c.a = static_cast<UInt8>(std::min(static_cast<unsigned int>(a) + static_cast<unsigned int>(color.a), 255U));
|
||||
c.r = r + color.r;
|
||||
c.g = g + color.g;
|
||||
c.b = b + color.b;
|
||||
c.a = a + color.a;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
|
@ -125,12 +108,11 @@ namespace Nz
|
|||
|
||||
inline Color Color::operator*(const Color& color) const
|
||||
{
|
||||
///TODO: Improve this shit
|
||||
Color c;
|
||||
c.r = static_cast<UInt8>((static_cast<unsigned int>(r) * static_cast<unsigned int>(color.r)) / 255U);
|
||||
c.g = static_cast<UInt8>((static_cast<unsigned int>(g) * static_cast<unsigned int>(color.g)) / 255U);
|
||||
c.b = static_cast<UInt8>((static_cast<unsigned int>(b) * static_cast<unsigned int>(color.b)) / 255U);
|
||||
c.a = static_cast<UInt8>((static_cast<unsigned int>(a) * static_cast<unsigned int>(color.a)) / 255U);
|
||||
c.r = r * color.r;
|
||||
c.g = g * color.g;
|
||||
c.b = b * color.b;
|
||||
c.a = a * color.a;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
|
@ -168,7 +150,10 @@ namespace Nz
|
|||
|
||||
inline bool Color::operator==(const Color& color) const
|
||||
{
|
||||
return r == color.r && g == color.g && b == color.b && a == color.a;
|
||||
return NumberEquals(r, color.r) &&
|
||||
NumberEquals(g, color.g) &&
|
||||
NumberEquals(b, color.b) &&
|
||||
NumberEquals(a, color.a);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -193,10 +178,9 @@ namespace Nz
|
|||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline Color Color::FromCMY(float cyan, float magenta, float yellow)
|
||||
{
|
||||
return Color(static_cast<UInt8>((1.f-cyan)*255.f), static_cast<UInt8>((1.f-magenta)*255.f), static_cast<UInt8>((1.f-yellow)*255.f));
|
||||
return Color(1.f - cyan, 1.f - magenta, 1.f - yellow);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -208,7 +192,6 @@ namespace Nz
|
|||
* \param yellow Yellow component
|
||||
* \param black Black component
|
||||
*/
|
||||
|
||||
inline Color Color::FromCMYK(float cyan, float magenta, float yellow, float black)
|
||||
{
|
||||
return FromCMY(cyan * (1.f - black) + black,
|
||||
|
|
@ -224,14 +207,10 @@ namespace Nz
|
|||
* \param saturation Saturation component [0, 1]
|
||||
* \param lightness Lightness component [0, 1]
|
||||
*/
|
||||
|
||||
inline Color Color::FromHSL(float hue, float saturation, float lightness)
|
||||
{
|
||||
if (NumberEquals(saturation, 0.f))
|
||||
{
|
||||
// RGB results from 0 to 255
|
||||
return Color(static_cast<UInt8>(lightness * 255.f));
|
||||
}
|
||||
return Color(lightness);
|
||||
else
|
||||
{
|
||||
float v2;
|
||||
|
|
@ -243,9 +222,9 @@ namespace Nz
|
|||
float v1 = 2.f * lightness - v2;
|
||||
|
||||
float h = hue / 360.f;
|
||||
return Color(static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
|
||||
return Color(Hue2RGB(v1, v2, h + (1.f/3.f)),
|
||||
Hue2RGB(v1, v2, h),
|
||||
Hue2RGB(v1, v2, h - (1.f/3.f)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -257,11 +236,10 @@ namespace Nz
|
|||
* \param saturation Saturation component in [0, 1]
|
||||
* \param value Value component in [0, 1]
|
||||
*/
|
||||
|
||||
inline Color Color::FromHSV(float hue, float saturation, float value)
|
||||
{
|
||||
if (NumberEquals(saturation, 0.f))
|
||||
return Color(static_cast<UInt8>(value * 255.f));
|
||||
return Color(value);
|
||||
else
|
||||
{
|
||||
float h = (hue / 360.f) * 6.f;
|
||||
|
|
@ -314,18 +292,43 @@ namespace Nz
|
|||
break;
|
||||
}
|
||||
|
||||
// RGB results from 0 to 255
|
||||
return Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
return Color(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB8 representation to Color (RGBA32F)
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param r Red value
|
||||
* \param g Green value
|
||||
* \param b Blue value
|
||||
*/
|
||||
inline Color Color::FromRGB8(UInt8 r, UInt8 g, UInt8 b)
|
||||
{
|
||||
return Color(r / 255.f, g / 255.f, b / 255.f);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGBA8 representation to Color (RGBA32F)
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param r Red value
|
||||
* \param g Green value
|
||||
* \param b Blue value
|
||||
* \param a Alpha value
|
||||
*/
|
||||
inline Color Color::FromRGBA8(UInt8 r, UInt8 g, UInt8 b, UInt8 a)
|
||||
{
|
||||
return Color(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts XYZ representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param vec Vector3 representing the space color
|
||||
*/
|
||||
|
||||
inline Color Color::FromXYZ(const Vector3f& vec)
|
||||
{
|
||||
return FromXYZ(vec.x, vec.y, vec.z);
|
||||
|
|
@ -339,7 +342,6 @@ namespace Nz
|
|||
* \param y Y component
|
||||
* \param z Z component
|
||||
*/
|
||||
|
||||
inline Color Color::FromXYZ(float x, float y, float z)
|
||||
{
|
||||
x /= 100.f; // X from 0 to 95.047
|
||||
|
|
@ -365,7 +367,7 @@ namespace Nz
|
|||
else
|
||||
b *= 12.92f;
|
||||
|
||||
return Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
return Color(r, g, b);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -376,12 +378,11 @@ namespace Nz
|
|||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline void Color::ToCMY(const Color& color, float* cyan, float* magenta, float* yellow)
|
||||
{
|
||||
*cyan = 1.f - color.r/255.f;
|
||||
*magenta = 1.f - color.g/255.f;
|
||||
*yellow = 1.f - color.b/255.f;
|
||||
*cyan = 1.f - color.r;
|
||||
*magenta = 1.f - color.g;
|
||||
*yellow = 1.f - color.b;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -425,12 +426,11 @@ namespace Nz
|
|||
* \param saturation Saturation component in [0, 1]
|
||||
* \param lightness Lightness component in [0, 1]
|
||||
*/
|
||||
|
||||
inline void Color::ToHSL(const Color& color, float* hue, float* saturation, float* lightness)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
float g = color.g / 255.f;
|
||||
float b = color.b / 255.f;
|
||||
float r = color.r;
|
||||
float g = color.g;
|
||||
float b = color.b;
|
||||
|
||||
float min = std::min({r, g, b}); // Min. value of RGB
|
||||
float max = std::max({r, g, b}); // Max. value of RGB
|
||||
|
|
@ -483,12 +483,11 @@ namespace Nz
|
|||
* \param saturation Saturation component
|
||||
* \param value Value component
|
||||
*/
|
||||
|
||||
inline void Color::ToHSV(const Color& color, float* hue, float* saturation, float* value)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
float g = color.g / 255.f;
|
||||
float b = color.b / 255.f;
|
||||
float r = color.r;
|
||||
float g = color.g;
|
||||
float b = color.b;
|
||||
|
||||
float min = std::min({r, g, b}); //Min. value of RGB
|
||||
float max = std::max({r, g, b}); //Max. value of RGB
|
||||
|
|
@ -530,13 +529,48 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts Color representation (RGBA32F) to RGB8
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param r Red component
|
||||
* \param g Green component
|
||||
* \param b Blue component
|
||||
*
|
||||
* \remark Values are clamped to [0;255]
|
||||
*/
|
||||
static inline void ToRGB8(const Color& color, UInt8* r, UInt8* g, UInt8* b)
|
||||
{
|
||||
*r = static_cast<UInt8>(Clamp(color.r * 255.f, 0.f, 255.f));
|
||||
*g = static_cast<UInt8>(Clamp(color.g * 255.f, 0.f, 255.f));
|
||||
*b = static_cast<UInt8>(Clamp(color.b * 255.f, 0.f, 255.f));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts Color representation (RGBA32F) to RGBA8
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param r Red component
|
||||
* \param g Green component
|
||||
* \param b Blue component
|
||||
* \param a Alpha component
|
||||
*
|
||||
* \remark Values are clamped to [0;255]
|
||||
*/
|
||||
static inline void ToRGBA8(const Color& color, UInt8* r, UInt8* g, UInt8* b, UInt8* a)
|
||||
{
|
||||
*r = static_cast<UInt8>(Clamp(color.r * 255.f, 0.f, 255.f));
|
||||
*g = static_cast<UInt8>(Clamp(color.g * 255.f, 0.f, 255.f));
|
||||
*b = static_cast<UInt8>(Clamp(color.b * 255.f, 0.f, 255.f));
|
||||
*a = static_cast<UInt8>(Clamp(color.a * 255.f, 0.f, 255.f));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to XYZ
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param vec Vector3 representing the space color
|
||||
*/
|
||||
|
||||
inline void Color::ToXYZ(const Color& color, Vector3f* vec)
|
||||
{
|
||||
return ToXYZ(color, &vec->x, &vec->y, &vec->z);
|
||||
|
|
@ -550,12 +584,11 @@ namespace Nz
|
|||
* \param y Y component
|
||||
* \param z Z component
|
||||
*/
|
||||
|
||||
inline void Color::ToXYZ(const Color& color, float* x, float* y, float* z)
|
||||
{
|
||||
float r = color.r/255.f; //R from 0 to 255
|
||||
float g = color.g/255.f; //G from 0 to 255
|
||||
float b = color.b/255.f; //B from 0 to 255
|
||||
float r = color.r; //< R from 0 to 255
|
||||
float g = color.g; //< G from 0 to 255
|
||||
float b = color.b; //< B from 0 to 255
|
||||
|
||||
if (r > 0.04045f)
|
||||
r = std::pow((r + 0.055f)/1.055f, 2.4f);
|
||||
|
|
@ -590,7 +623,6 @@ namespace Nz
|
|||
* \param v2 V2 component
|
||||
* \param vH VH component
|
||||
*/
|
||||
|
||||
inline float Color::Hue2RGB(float v1, float v2, float vH)
|
||||
{
|
||||
if (vH < 0.f)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ namespace Nz
|
|||
template<> constexpr ComponentType ComponentTypeId<Vector2i>() { return ComponentType::Int2; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector3i>() { return ComponentType::Int3; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector4i>() { return ComponentType::Int4; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Quaternionf>() { return ComponentType::Quaternion; }
|
||||
|
||||
template<typename T>
|
||||
constexpr ComponentType GetComponentTypeOf()
|
||||
|
|
|
|||
|
|
@ -100,9 +100,8 @@ namespace Nz
|
|||
Int2,
|
||||
Int3,
|
||||
Int4,
|
||||
Quaternion,
|
||||
|
||||
Max = Quaternion
|
||||
Max = Int4
|
||||
};
|
||||
|
||||
constexpr std::size_t ComponentTypeCount = static_cast<std::size_t>(ComponentType::Max) + 1;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ namespace Nz
|
|||
{
|
||||
switch (componentType)
|
||||
{
|
||||
case ComponentType::Color: return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case ComponentType::Color: return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
case ComponentType::Double1: return VK_FORMAT_R64_SFLOAT;
|
||||
case ComponentType::Double2: return VK_FORMAT_R64G64_SFLOAT;
|
||||
case ComponentType::Double3: return VK_FORMAT_R64G64B64_SFLOAT;
|
||||
|
|
@ -123,7 +123,6 @@ namespace Nz
|
|||
case ComponentType::Int2: return VK_FORMAT_R32G32_SINT;
|
||||
case ComponentType::Int3: return VK_FORMAT_R32G32B32_SINT;
|
||||
case ComponentType::Int4: return VK_FORMAT_R32G32B32A32_SINT;
|
||||
case ComponentType::Quaternion: return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled ComponentType 0x" + NumberToString(UnderlyingCast(componentType), 16));
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace Nz
|
|||
|
||||
inline void CommandBuffer::BeginDebugRegion(const char* label)
|
||||
{
|
||||
return BeginDebugRegion(label, Color(0, 0, 0, 0));
|
||||
return BeginDebugRegion(label, Color::Black);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BeginDebugRegion(const char* label, Color color)
|
||||
|
|
@ -133,10 +133,10 @@ namespace Nz
|
|||
nullptr,
|
||||
label,
|
||||
{
|
||||
color.r / 255.f,
|
||||
color.g / 255.f,
|
||||
color.b / 255.f,
|
||||
color.a / 255.f
|
||||
color.r,
|
||||
color.g,
|
||||
color.b,
|
||||
color.a
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -374,7 +374,7 @@ namespace Nz
|
|||
|
||||
inline void CommandBuffer::InsertDebugLabel(const char* label)
|
||||
{
|
||||
return InsertDebugLabel(label, Color(0, 0, 0, 0));
|
||||
return InsertDebugLabel(label, Color::Black);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::InsertDebugLabel(const char* label, Color color)
|
||||
|
|
@ -387,10 +387,10 @@ namespace Nz
|
|||
nullptr,
|
||||
label,
|
||||
{
|
||||
color.r / 255.f,
|
||||
color.g / 255.f,
|
||||
color.b / 255.f,
|
||||
color.a / 255.f
|
||||
color.r,
|
||||
color.g,
|
||||
color.b,
|
||||
color.a
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Nz
|
|||
m_theme(std::move(theme)),
|
||||
m_registry(nullptr),
|
||||
m_canvas(nullptr),
|
||||
m_backgroundColor(Color(230, 230, 230, 255)),
|
||||
m_backgroundColor(Color(0.9f, 0.9f, 0.9f, 1.f)),
|
||||
m_renderingRect(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()),
|
||||
m_cursor(SystemCursor::Default),
|
||||
m_maximumSize(std::numeric_limits<float>::infinity()),
|
||||
|
|
|
|||
|
|
@ -376,7 +376,7 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||
aiColor4D color;
|
||||
if (aiGetMaterialColor(aiMat, aiKey, aiType, aiIndex, &color) == aiReturn_SUCCESS)
|
||||
{
|
||||
matData.SetParameter(colorKey, Color(static_cast<UInt8>(color.r * 255), static_cast<UInt8>(color.g * 255), static_cast<UInt8>(color.b * 255), static_cast<UInt8>(color.a * 255)));
|
||||
matData.SetParameter(colorKey, Color(color.r, color.g, color.b, color.a));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -555,7 +555,7 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||
for (unsigned int vertexIdx = 0; vertexIdx < vertexCount; ++vertexIdx)
|
||||
{
|
||||
aiColor4D color = iMesh->mColors[0][vertexIdx];
|
||||
*colorPtr++ = Color(UInt8(color.r * 255.f), UInt8(color.g * 255.f), UInt8(color.b * 255.f), UInt8(color.a * 255.f));
|
||||
*colorPtr++ = Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -586,7 +586,7 @@ std::shared_ptr<Mesh> LoadMesh(Stream& stream, const MeshParams& parameters)
|
|||
aiColor4D color;
|
||||
if (aiGetMaterialColor(aiMat, aiKey, aiType, aiIndex, &color) == aiReturn_SUCCESS)
|
||||
{
|
||||
matData.SetParameter(colorKey, Color(static_cast<UInt8>(color.r * 255), static_cast<UInt8>(color.g * 255), static_cast<UInt8>(color.b * 255), static_cast<UInt8>(color.a * 255)));
|
||||
matData.SetParameter(colorKey, Color(color.r, color.g, color.b, color.a));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
const Color Color::Black(0, 0, 0);
|
||||
const Color Color::Blue(0, 0, 255);
|
||||
const Color Color::Cyan(0, 255, 255);
|
||||
const Color Color::Gray(80, 80, 80);
|
||||
const Color Color::Green(0, 255, 0);
|
||||
const Color Color::Magenta(255, 0, 255);
|
||||
const Color Color::Orange(255, 165, 0);
|
||||
const Color Color::Red(255, 0, 0);
|
||||
const Color Color::Yellow(255, 255, 0);
|
||||
const Color Color::White(255, 255, 255);
|
||||
const Color Color::Black(0.f, 0.f, 0.f);
|
||||
const Color Color::Blue(0.f, 0.f, 1.f);
|
||||
const Color Color::Cyan(0.f, 1.f, 1.f);
|
||||
const Color Color::Gray(80.f / 255.f, 80.f / 255.f, 80.f / 255.f);
|
||||
const Color Color::Green(0.f, 1.f, 0.f);
|
||||
const Color Color::Magenta(1.f, 0.f, 1.f);
|
||||
const Color Color::Orange(1.f, 165.f / 255.f, 0.f);
|
||||
const Color Color::Red(1.f, 0.f, 0.f);
|
||||
const Color Color::Yellow(1.f, 1.f, 0.f);
|
||||
const Color Color::White(1.f, 1.f, 1.f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ namespace Nz
|
|||
const std::vector<UInt8>& bufferData = m_material.GetUniformBufferConstData(m_uniformBlockIndex);
|
||||
|
||||
const float* colorPtr = AccessByOffset<const float*>(bufferData.data(), m_basicUniformOffsets.diffuseColor);
|
||||
return Color(colorPtr[0] * 255, colorPtr[1] * 255, colorPtr[2] * 255, colorPtr[3] * 255); //< TODO: Make color able to use float
|
||||
return Color(colorPtr[0], colorPtr[1], colorPtr[2], colorPtr[3]);
|
||||
}
|
||||
|
||||
void BasicMaterial::SetAlphaTestThreshold(float alphaThreshold)
|
||||
|
|
@ -86,10 +86,10 @@ namespace Nz
|
|||
std::vector<UInt8>& bufferData = m_material.GetUniformBufferData(m_uniformBlockIndex);
|
||||
|
||||
float* colorPtr = AccessByOffset<float*>(bufferData.data(), m_basicUniformOffsets.diffuseColor);
|
||||
colorPtr[0] = diffuse.r / 255.f;
|
||||
colorPtr[1] = diffuse.g / 255.f;
|
||||
colorPtr[2] = diffuse.b / 255.f;
|
||||
colorPtr[3] = diffuse.a / 255.f;
|
||||
colorPtr[0] = diffuse.r;
|
||||
colorPtr[1] = diffuse.g;
|
||||
colorPtr[2] = diffuse.b;
|
||||
colorPtr[3] = diffuse.a;
|
||||
}
|
||||
|
||||
MaterialSettings::Builder BasicMaterial::Build(BasicBuildOptions& options)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
auto lightOffset = PredefinedLightData::GetOffsets();
|
||||
|
||||
AccessByOffset<UInt32&>(data, lightOffset.lightMemberOffsets.type) = UnderlyingCast(BasicLightType::Directional);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r / 255.f, m_color.g / 255.f, m_color.b / 255.f, m_color.a / 255.f);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r, m_color.g, m_color.b, m_color.a);
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.factor) = Vector2f(m_ambientFactor, m_diffuseFactor);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter1) = Vector4f(m_direction.x, m_direction.y, m_direction.z, 0.f);
|
||||
AccessByOffset<UInt8&>(data, lightOffset.lightMemberOffsets.shadowMappingFlag) = 0;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ namespace Nz
|
|||
const std::vector<UInt8>& bufferData = GetMaterial().GetUniformBufferConstData(m_uniformBlockIndex);
|
||||
|
||||
const float* colorPtr = AccessByOffset<const float*>(bufferData.data(), m_phongUniformOffsets.ambientColor);
|
||||
return Color(colorPtr[0] * 255, colorPtr[1] * 255, colorPtr[2] * 255, colorPtr[3] * 255); //< TODO: Make color able to use float
|
||||
return Color(colorPtr[0], colorPtr[1], colorPtr[2], colorPtr[3]);
|
||||
}
|
||||
|
||||
float Nz::PhongLightingMaterial::GetShininess() const
|
||||
|
|
@ -98,7 +98,7 @@ namespace Nz
|
|||
const std::vector<UInt8>& bufferData = GetMaterial().GetUniformBufferConstData(m_uniformBlockIndex);
|
||||
|
||||
const float* colorPtr = AccessByOffset<const float*>(bufferData.data(), m_phongUniformOffsets.specularColor);
|
||||
return Color(colorPtr[0] * 255, colorPtr[1] * 255, colorPtr[2] * 255, colorPtr[3] * 255); //< TODO: Make color able to use float
|
||||
return Color(colorPtr[0], colorPtr[1], colorPtr[2], colorPtr[3]);
|
||||
}
|
||||
|
||||
void PhongLightingMaterial::SetAmbientColor(const Color& ambient)
|
||||
|
|
@ -107,10 +107,10 @@ namespace Nz
|
|||
|
||||
std::vector<UInt8>& bufferData = GetMaterial().GetUniformBufferData(m_uniformBlockIndex);
|
||||
float* colorPtr = AccessByOffset<float*>(bufferData.data(), m_phongUniformOffsets.ambientColor);
|
||||
colorPtr[0] = ambient.r / 255.f;
|
||||
colorPtr[1] = ambient.g / 255.f;
|
||||
colorPtr[2] = ambient.b / 255.f;
|
||||
colorPtr[3] = ambient.a / 255.f;
|
||||
colorPtr[0] = ambient.r;
|
||||
colorPtr[1] = ambient.g;
|
||||
colorPtr[2] = ambient.b;
|
||||
colorPtr[3] = ambient.a;
|
||||
}
|
||||
|
||||
void PhongLightingMaterial::SetShininess(float shininess)
|
||||
|
|
@ -127,10 +127,10 @@ namespace Nz
|
|||
|
||||
std::vector<UInt8>& bufferData = GetMaterial().GetUniformBufferData(m_uniformBlockIndex);
|
||||
float* colorPtr = AccessByOffset<float*>(bufferData.data(), m_phongUniformOffsets.specularColor);
|
||||
colorPtr[0] = diffuse.r / 255.f;
|
||||
colorPtr[1] = diffuse.g / 255.f;
|
||||
colorPtr[2] = diffuse.b / 255.f;
|
||||
colorPtr[3] = diffuse.a / 255.f;
|
||||
colorPtr[0] = diffuse.r;
|
||||
colorPtr[1] = diffuse.g;
|
||||
colorPtr[2] = diffuse.b;
|
||||
colorPtr[3] = diffuse.a;
|
||||
}
|
||||
|
||||
const std::shared_ptr<MaterialSettings>& PhongLightingMaterial::GetSettings()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
auto lightOffset = PredefinedLightData::GetOffsets();
|
||||
|
||||
AccessByOffset<UInt32&>(data, lightOffset.lightMemberOffsets.type) = UnderlyingCast(BasicLightType::Point);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r / 255.f, m_color.g / 255.f, m_color.b / 255.f, m_color.a / 255.f);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r, m_color.g, m_color.b, m_color.a);
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.factor) = Vector2f(m_ambientFactor, m_diffuseFactor);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter1) = Vector4f(m_position.x, m_position.y, m_position.z, m_invRadius);
|
||||
AccessByOffset<UInt8&>(data, lightOffset.lightMemberOffsets.shadowMappingFlag) = 0;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
auto lightOffset = PredefinedLightData::GetOffsets();
|
||||
|
||||
AccessByOffset<UInt32&>(data, lightOffset.lightMemberOffsets.type) = UnderlyingCast(BasicLightType::Spot);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r / 255.f, m_color.g / 255.f, m_color.b / 255.f, m_color.a / 255.f);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r, m_color.g, m_color.b, m_color.a);
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.factor) = Vector2f(m_ambientFactor, m_diffuseFactor);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter1) = Vector4f(m_position.x, m_position.y, m_position.z, m_invRadius);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter2) = Vector4f(m_direction.x, m_direction.y, m_direction.z, 0.f);
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ namespace Nz
|
|||
switch (component)
|
||||
{
|
||||
case ComponentType::Color:
|
||||
attrib.normalized = GL_TRUE;
|
||||
attrib.normalized = GL_FALSE;
|
||||
attrib.size = 4;
|
||||
attrib.type = GL_UNSIGNED_BYTE;
|
||||
attrib.type = GL_FLOAT;
|
||||
return;
|
||||
|
||||
case ComponentType::Float1:
|
||||
|
|
@ -49,7 +49,6 @@ namespace Nz
|
|||
case ComponentType::Double2:
|
||||
case ComponentType::Double3:
|
||||
case ComponentType::Double4:
|
||||
case ComponentType::Quaternion:
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +181,7 @@ namespace Nz
|
|||
std::size_t attachmentIndex = colorIndexes[i];
|
||||
|
||||
Color color = command.clearValues[attachmentIndex].color;
|
||||
std::array<GLfloat, 4> clearColor = { color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f };
|
||||
std::array<GLfloat, 4> clearColor = { color.r, color.g, color.b, color.a };
|
||||
|
||||
const auto& attachmentInfo = command.renderpass->GetAttachment(attachmentIndex);
|
||||
if (attachmentInfo.loadOp == AttachmentLoadOp::Clear)
|
||||
|
|
@ -253,7 +252,7 @@ namespace Nz
|
|||
context->ResetColorWriteMasks();
|
||||
|
||||
Color color = command.clearValues[colorAttachmentIndex].color;
|
||||
context->glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f);
|
||||
context->glClearColor(color.r, color.g, color.b, color.a);
|
||||
|
||||
clearFields |= GL_COLOR_BUFFER_BIT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ namespace Nz
|
|||
{
|
||||
Color CpDebugColorToColor(cpSpaceDebugColor c)
|
||||
{
|
||||
return Color{ static_cast<Nz::UInt8>(c.r * 255.f), static_cast<Nz::UInt8>(c.g * 255.f), static_cast<Nz::UInt8>(c.b * 255.f), static_cast<Nz::UInt8>(c.a * 255.f) };
|
||||
return Color{ c.r, c.g, c.b, c.a };
|
||||
}
|
||||
|
||||
cpSpaceDebugColor ColorToCpDebugColor(Color c)
|
||||
{
|
||||
return cpSpaceDebugColor{ c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f };
|
||||
return cpSpaceDebugColor{ c.r, c.g, c.b, c.a };
|
||||
}
|
||||
|
||||
void CpCircleCallback(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
|
||||
|
|
@ -74,7 +74,7 @@ namespace Nz
|
|||
return ColorToCpDebugColor(drawOptions->colorCallback(rigidBody, rigidBody.GetShapeIndex(shape), drawOptions->userdata));
|
||||
}
|
||||
else
|
||||
return cpSpaceDebugColor{255.f, 0.f, 0.f, 255.f};
|
||||
return cpSpaceDebugColor{1.f, 0.f, 0.f, 1.f};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ namespace Nz
|
|||
{
|
||||
auto ColorToCpDebugColor = [](Color c) -> cpSpaceDebugColor
|
||||
{
|
||||
return cpSpaceDebugColor{ c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f };
|
||||
return cpSpaceDebugColor{ c.r, c.g, c.b, c.a };
|
||||
};
|
||||
|
||||
cpSpaceDebugDrawOptions drawOptions;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ namespace Nz
|
|||
if (!currentMaterial)
|
||||
currentMaterial = AddMaterial("default");
|
||||
|
||||
currentMaterial->ambient = Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
currentMaterial->ambient = Color(r, g, b);
|
||||
}
|
||||
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
|
||||
else
|
||||
|
|
@ -171,7 +171,7 @@ namespace Nz
|
|||
if (!currentMaterial)
|
||||
currentMaterial = AddMaterial("default");
|
||||
|
||||
currentMaterial->diffuse = Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
currentMaterial->diffuse = Color(r, g, b);
|
||||
}
|
||||
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
|
||||
else
|
||||
|
|
@ -186,7 +186,7 @@ namespace Nz
|
|||
if (!currentMaterial)
|
||||
currentMaterial = AddMaterial("default");
|
||||
|
||||
currentMaterial->specular = Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
currentMaterial->specular = Color(r, g, b);
|
||||
}
|
||||
#if NAZARA_UTILITY_STRICT_RESOURCE_PARSING
|
||||
else
|
||||
|
|
@ -518,27 +518,27 @@ namespace Nz
|
|||
EmitLine();
|
||||
|
||||
Emit("Ka ");
|
||||
Emit(mat.ambient.r / 255.f);
|
||||
Emit(mat.ambient.r);
|
||||
Emit(' ');
|
||||
Emit(mat.ambient.g / 255.f);
|
||||
Emit(mat.ambient.g);
|
||||
Emit(' ');
|
||||
Emit(mat.ambient.b / 255.f);
|
||||
Emit(mat.ambient.b);
|
||||
EmitLine();
|
||||
|
||||
Emit("Kd ");
|
||||
Emit(mat.diffuse.r / 255.f);
|
||||
Emit(mat.diffuse.r);
|
||||
Emit(' ');
|
||||
Emit(mat.diffuse.g / 255.f);
|
||||
Emit(mat.diffuse.g);
|
||||
Emit(' ');
|
||||
Emit(mat.diffuse.b / 255.f);
|
||||
Emit(mat.diffuse.b);
|
||||
EmitLine();
|
||||
|
||||
Emit("Ks ");
|
||||
Emit(mat.specular.r / 255.f);
|
||||
Emit(mat.specular.r);
|
||||
Emit(' ');
|
||||
Emit(mat.specular.g / 255.f);
|
||||
Emit(mat.specular.g);
|
||||
Emit(' ');
|
||||
Emit(mat.specular.b / 255.f);
|
||||
Emit(mat.specular.b);
|
||||
EmitLine();
|
||||
|
||||
if (!NumberEquals(mat.alpha, 1.f))
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ namespace Nz
|
|||
{
|
||||
ParameterList data;
|
||||
|
||||
UInt8 alphaValue = static_cast<UInt8>(mtlMat->alpha*255.f);
|
||||
float alphaValue = mtlMat->alpha;
|
||||
|
||||
Color ambientColor(mtlMat->ambient);
|
||||
Color diffuseColor(mtlMat->diffuse);
|
||||
|
|
|
|||
|
|
@ -715,7 +715,7 @@ namespace Nz
|
|||
const UInt8* pixel = GetPixelPtr(m_sharedImage->levels[0].get(), PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height);
|
||||
|
||||
Color color;
|
||||
if (!PixelFormatInfo::Convert(m_sharedImage->format, PixelFormat::RGBA8, pixel, &color.r))
|
||||
if (!PixelFormatInfo::Convert(m_sharedImage->format, PixelFormat::RGBA32F, pixel, &color.r))
|
||||
NazaraError("Failed to convert image's format to RGBA8");
|
||||
|
||||
return color;
|
||||
|
|
|
|||
|
|
@ -269,6 +269,23 @@ namespace Nz
|
|||
return dst;
|
||||
}
|
||||
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::BGR8, PixelFormat::RGBA32F>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
{
|
||||
float* ptr = reinterpret_cast<float*>(dst);
|
||||
while (start < end)
|
||||
{
|
||||
*ptr++ = start[2] / 255.f;
|
||||
*ptr++ = start[1] / 255.f;
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = 1.f;
|
||||
|
||||
start += 3;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**********************************BGRA8**********************************/
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::BGRA8, PixelFormat::A8>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
|
|
@ -409,6 +426,23 @@ namespace Nz
|
|||
return dst;
|
||||
}
|
||||
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::BGRA8, PixelFormat::RGBA32F>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
{
|
||||
float* ptr = reinterpret_cast<float*>(dst);
|
||||
while (start < end)
|
||||
{
|
||||
*ptr++ = start[2] / 255.f;
|
||||
*ptr++ = start[1] / 255.f;
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[3] / 255.f;
|
||||
|
||||
start += 4;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/***********************************L8************************************/
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::L8, PixelFormat::BGR8>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
|
|
@ -534,6 +568,23 @@ namespace Nz
|
|||
return dst;
|
||||
}
|
||||
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::L8, PixelFormat::RGBA32F>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
{
|
||||
float* ptr = reinterpret_cast<float*>(dst);
|
||||
while (start < end)
|
||||
{
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = 1.f;
|
||||
|
||||
start += 1;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/***********************************LA8***********************************/
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::LA8, PixelFormat::A8>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
|
|
@ -665,6 +716,23 @@ namespace Nz
|
|||
return dst;
|
||||
}
|
||||
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::LA8, PixelFormat::RGBA32F>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
{
|
||||
float* ptr = reinterpret_cast<float*>(dst);
|
||||
while (start < end)
|
||||
{
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[1] / 255.f;
|
||||
|
||||
start += 2;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/*********************************RGBA4***********************************/
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::RGBA4, PixelFormat::A8>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
|
|
@ -1158,6 +1226,23 @@ namespace Nz
|
|||
return dst;
|
||||
}
|
||||
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::RGB8, PixelFormat::RGBA32F>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
{
|
||||
float* ptr = reinterpret_cast<float*>(dst);
|
||||
while (start < end)
|
||||
{
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[1] / 255.f;
|
||||
*ptr++ = start[2] / 255.f;
|
||||
*ptr++ = 1.f;
|
||||
|
||||
start += 3;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**********************************RGBA8**********************************/
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::RGBA8, PixelFormat::A8>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
|
|
@ -1298,6 +1383,22 @@ namespace Nz
|
|||
return dst + count;
|
||||
}
|
||||
|
||||
template<>
|
||||
UInt8* ConvertPixels<PixelFormat::RGBA8, PixelFormat::RGBA32F>(const UInt8* start, const UInt8* end, UInt8* dst)
|
||||
{
|
||||
float* ptr = reinterpret_cast<float*>(dst);
|
||||
while (start < end)
|
||||
{
|
||||
*ptr++ = start[0] / 255.f;
|
||||
*ptr++ = start[1] / 255.f;
|
||||
*ptr++ = start[2] / 255.f;
|
||||
*ptr++ = start[3] / 255.f;
|
||||
|
||||
start += 4;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
template<PixelFormat Format1, PixelFormat Format2>
|
||||
void RegisterConverter()
|
||||
|
|
@ -1515,6 +1616,7 @@ namespace Nz
|
|||
RegisterConverter<PixelFormat::BGR8, PixelFormat::RGB8>();
|
||||
RegisterConverter<PixelFormat::BGR8, PixelFormat::RGBA4>();
|
||||
RegisterConverter<PixelFormat::BGR8, PixelFormat::RGBA8>();
|
||||
RegisterConverter<PixelFormat::BGR8, PixelFormat::RGBA32F>();
|
||||
|
||||
/**********************************BGRA8**********************************/
|
||||
RegisterConverter<PixelFormat::BGRA8, PixelFormat::A8>();
|
||||
|
|
@ -1534,6 +1636,7 @@ namespace Nz
|
|||
RegisterConverter<PixelFormat::BGRA8, PixelFormat::RGB8>();
|
||||
RegisterConverter<PixelFormat::BGRA8, PixelFormat::RGBA4>();
|
||||
RegisterConverter<PixelFormat::BGRA8, PixelFormat::RGBA8>();
|
||||
RegisterConverter<PixelFormat::BGRA8, PixelFormat::RGBA32F>();
|
||||
|
||||
/**********************************DXT1***********************************/
|
||||
///TODO: Décompresseur DXT1
|
||||
|
|
@ -1620,6 +1723,7 @@ namespace Nz
|
|||
RegisterConverter<PixelFormat::L8, PixelFormat::RGB8>();
|
||||
RegisterConverter<PixelFormat::L8, PixelFormat::RGBA4>();
|
||||
RegisterConverter<PixelFormat::L8, PixelFormat::RGBA8>();
|
||||
RegisterConverter<PixelFormat::L8, PixelFormat::RGBA32F>();
|
||||
|
||||
/***********************************LA8***********************************/
|
||||
RegisterConverter<PixelFormat::LA8, PixelFormat::A8>();
|
||||
|
|
@ -1638,6 +1742,7 @@ namespace Nz
|
|||
RegisterConverter<PixelFormat::LA8, PixelFormat::RGB8>();
|
||||
RegisterConverter<PixelFormat::LA8, PixelFormat::RGBA4>();
|
||||
RegisterConverter<PixelFormat::LA8, PixelFormat::RGBA8>();
|
||||
RegisterConverter<PixelFormat::LA8, PixelFormat::RGBA32F>();
|
||||
|
||||
/**********************************RGBA4**********************************/
|
||||
RegisterConverter<PixelFormat::RGBA4, PixelFormat::A8>();
|
||||
|
|
@ -1692,6 +1797,7 @@ namespace Nz
|
|||
RegisterConverter<PixelFormat::RGB8, PixelFormat::RGB8_SRGB>();
|
||||
RegisterConverter<PixelFormat::RGB8, PixelFormat::RGBA4>();
|
||||
RegisterConverter<PixelFormat::RGB8, PixelFormat::RGBA8>();
|
||||
RegisterConverter<PixelFormat::RGB8, PixelFormat::RGBA32F>();
|
||||
|
||||
/**********************************RGBA8**********************************/
|
||||
RegisterConverter<PixelFormat::RGBA8, PixelFormat::A8>();
|
||||
|
|
@ -1711,6 +1817,7 @@ namespace Nz
|
|||
RegisterConverter<PixelFormat::RGBA8, PixelFormat::RGB8>();
|
||||
RegisterConverter<PixelFormat::RGBA8, PixelFormat::RGBA4>();
|
||||
RegisterConverter<PixelFormat::RGBA8, PixelFormat::RGBA8_SRGB>();
|
||||
RegisterConverter<PixelFormat::RGBA8, PixelFormat::RGBA32F>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
|||
{
|
||||
std::size_t s_componentStride[ComponentTypeCount] =
|
||||
{
|
||||
4 * sizeof(UInt8), // ComponentType::Color
|
||||
4 * sizeof(float), // ComponentType::Color
|
||||
1 * sizeof(double), // ComponentType::Double1
|
||||
2 * sizeof(double), // ComponentType::Double2
|
||||
3 * sizeof(double), // ComponentType::Double3
|
||||
|
|
@ -31,7 +31,6 @@ namespace Nz
|
|||
2 * sizeof(UInt32), // ComponentType::Int2
|
||||
3 * sizeof(UInt32), // ComponentType::Int3
|
||||
4 * sizeof(UInt32), // ComponentType::Int4
|
||||
4 * sizeof(float) // ComponentType::Quaternion
|
||||
};
|
||||
}
|
||||
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
|
||||
|
|
@ -74,7 +73,6 @@ namespace Nz
|
|||
{
|
||||
switch (type)
|
||||
{
|
||||
case ComponentType::Color:
|
||||
case ComponentType::Double1:
|
||||
case ComponentType::Double2:
|
||||
case ComponentType::Double3:
|
||||
|
|
@ -88,9 +86,6 @@ namespace Nz
|
|||
case ComponentType::Int3:
|
||||
case ComponentType::Int4:
|
||||
return true;
|
||||
|
||||
case ComponentType::Quaternion:
|
||||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Component type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
|
||||
|
|
@ -127,7 +122,7 @@ namespace Nz
|
|||
},
|
||||
{
|
||||
VertexComponent::Color,
|
||||
ComponentType::Color,
|
||||
ComponentType::Float4,
|
||||
0
|
||||
},
|
||||
});
|
||||
|
|
@ -170,7 +165,7 @@ namespace Nz
|
|||
},
|
||||
{
|
||||
VertexComponent::Color,
|
||||
ComponentType::Color,
|
||||
ComponentType::Float4,
|
||||
0
|
||||
}
|
||||
});
|
||||
|
|
@ -186,7 +181,7 @@ namespace Nz
|
|||
},
|
||||
{
|
||||
VertexComponent::Color,
|
||||
ComponentType::Color,
|
||||
ComponentType::Float4,
|
||||
0
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ namespace Nz
|
|||
|
||||
if (PixelFormatInfo::GetContent(vkRenderPass.GetAttachment(i).format) == PixelFormatContent::ColorRGBA)
|
||||
{
|
||||
vkValues.color.float32[0] = values.color.r / 255.f;
|
||||
vkValues.color.float32[1] = values.color.g / 255.f;
|
||||
vkValues.color.float32[2] = values.color.b / 255.f;
|
||||
vkValues.color.float32[3] = values.color.a / 255.f;
|
||||
vkValues.color.float32[0] = values.color.r;
|
||||
vkValues.color.float32[1] = values.color.g;
|
||||
vkValues.color.float32[2] = values.color.b;
|
||||
vkValues.color.float32[3] = values.color.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -596,7 +596,7 @@ namespace Nz
|
|||
float endX = (i == m_cursorPositionEnd.y) ? GetGlyphPos({ m_cursorPositionEnd.x, i }) : lineInfo.bounds.width;
|
||||
float spriteSize = std::max(endX - beginX, 1.f);
|
||||
|
||||
cursor.sprite->SetColor((m_cursorPositionBegin == m_cursorPositionEnd) ? Color::Black : Color(0, 0, 0, 50));
|
||||
cursor.sprite->SetColor((m_cursorPositionBegin == m_cursorPositionEnd) ? Color::Black : Color(0.f, 0.f, 0.f, 0.2f));
|
||||
cursor.sprite->SetSize(Vector2f(spriteSize, lineInfo.bounds.height));
|
||||
|
||||
registry.get<NodeComponent>(cursor.entity).SetPosition(beginX, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);
|
||||
|
|
@ -604,7 +604,7 @@ namespace Nz
|
|||
else
|
||||
{
|
||||
// Full line selection
|
||||
cursor.sprite->SetColor(Color(0, 0, 0, 50));
|
||||
cursor.sprite->SetColor(Color(0.f, 0.f, 0.f, 0.2f));
|
||||
cursor.sprite->SetSize(Vector2f(lineInfo.bounds.width, lineInfo.bounds.height));
|
||||
|
||||
registry.get<NodeComponent>(cursor.entity).SetPosition(0.f, textHeight - lineInfo.bounds.y - lineInfo.bounds.height);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
#include <Nazara/Core/Color.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
const float epsilon = 1.f;
|
||||
|
||||
void CompareColor(const Nz::Color& lhs, const Nz::Color& rhs)
|
||||
{
|
||||
Nz::UInt8 tolerance = 3;
|
||||
REQUIRE(Nz::NumberEquals(lhs.r, rhs.r, tolerance));
|
||||
REQUIRE(Nz::NumberEquals(lhs.g, rhs.g, tolerance));
|
||||
REQUIRE(Nz::NumberEquals(lhs.b, rhs.b, tolerance));
|
||||
REQUIRE(Nz::NumberEquals(lhs.a, rhs.a, tolerance));
|
||||
constexpr float epsilon = 0.1f;
|
||||
|
||||
REQUIRE(lhs.r == Approx(rhs.r).margin(epsilon));
|
||||
REQUIRE(lhs.g == Approx(rhs.g).margin(epsilon));
|
||||
REQUIRE(lhs.b == Approx(rhs.b).margin(epsilon));
|
||||
REQUIRE(lhs.a == Approx(rhs.a).margin(epsilon));
|
||||
}
|
||||
|
||||
constexpr float epsilon = 1.f;
|
||||
|
||||
void CompareCMY(const Nz::Color& color, float cyan, float magenta, float yellow)
|
||||
{
|
||||
float retrievedCyan = 0.f, retrievedMagenta = 0.f, retrievedYellow = 0.f;
|
||||
|
|
@ -62,17 +63,18 @@ SCENARIO("Color", "[CORE][COLOR]")
|
|||
{
|
||||
GIVEN("Two colors, one red (255) and one gray (128)")
|
||||
{
|
||||
Nz::Color red(255, 0, 0);
|
||||
Nz::Color grey(128);
|
||||
Nz::Color red(1.f, 0.f, 0.f);
|
||||
Nz::Color grey(0.5f);
|
||||
|
||||
WHEN("We do operations")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
red += Nz::Color(0, 0, 0);
|
||||
grey *= Nz::Color(255);
|
||||
REQUIRE((red + grey) == Nz::Color(255, 128, 128));
|
||||
REQUIRE((red * grey) == Nz::Color(128, 0, 0));
|
||||
grey *= Nz::Color(1.f);
|
||||
|
||||
CompareColor(red + grey, Nz::Color(1.5f, 0.5f, 0.5f, 3.f));
|
||||
CompareColor(red * grey, Nz::Color(0.5f, 0.f, 0.f, 2.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,7 +96,7 @@ SCENARIO("Color", "[CORE][COLOR]")
|
|||
|
||||
colors.push_back({
|
||||
"blue",
|
||||
Nz::Color(0, 0, 255),
|
||||
Nz::Color(0.f, 0.f, 1.f),
|
||||
1.f, 1.f, 0.f, // cmy
|
||||
1.f, 1.f, 0.f, 0.f, // cmyk
|
||||
240.f, 1.f, 0.5f, // hsl
|
||||
|
|
@ -104,7 +106,7 @@ SCENARIO("Color", "[CORE][COLOR]")
|
|||
|
||||
colors.push_back({
|
||||
"white",
|
||||
Nz::Color(255, 255, 255),
|
||||
Nz::Color(1.f, 1.f, 1.f),
|
||||
0.f, 0.f, 0.f, // cmy
|
||||
0.f, 0.f, 0.f, 0.f, // cmyk
|
||||
0.f, 0.f, 1.f, // hsl
|
||||
|
|
@ -114,7 +116,7 @@ SCENARIO("Color", "[CORE][COLOR]")
|
|||
|
||||
colors.push_back({
|
||||
"greenish",
|
||||
Nz::Color(5, 191, 25),
|
||||
Nz::Color(5 / 255.f, 191.f / 255.f, 25.f / 255.f),
|
||||
0.980f, 0.251f, 0.902f, // cmy
|
||||
0.974f, 0.000f, 0.869f, 0.251f, // cmyk
|
||||
126.f, 0.95f, 0.38f, // hsl
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ SCENARIO("Images", "[Utility][Image]")
|
|||
CHECK(logo->GetWidth() == 765);
|
||||
CHECK(logo->GetHeight() == 212);
|
||||
CHECK(logo->GetLevelCount() == 1);
|
||||
CHECK(logo->GetPixelColor(165, 139) == Nz::Color(51, 58, 100));
|
||||
CHECK(logo->GetPixelColor(165, 139) == Nz::Color::FromRGB8(51, 58, 100));
|
||||
CHECK(logo->GetFormat() == Nz::PixelFormat::RGBA8);
|
||||
CHECK(logo->HasAlpha());
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ SCENARIO("Images", "[Utility][Image]")
|
|||
CHECK(background->GetWidth() == 1920);
|
||||
CHECK(background->GetHeight() == 1200);
|
||||
CHECK(background->GetLevelCount() == 1);
|
||||
CHECK(background->GetPixelColor(1377, 372) == Nz::Color(171, 152, 233));
|
||||
CHECK(background->GetPixelColor(1377, 372) == Nz::Color::FromRGB8(171, 152, 233));
|
||||
CHECK(background->GetFormat() == Nz::PixelFormat::RGBA8);
|
||||
CHECK(!background->HasAlpha());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue