public:
using Position = glm::vec3;
using TexCoord = glm::vec3;
- using ColorMod = glm::vec3;
+ using ColorMod = glm::tvec3<unsigned char>;
using Light = float;
using Index = unsigned int;
public:
using Position = glm::vec3;
using TexCoord = glm::vec3;
- using ColorMod = glm::vec3;
+ using ColorMod = glm::tvec3<unsigned char>;
using Normal = glm::vec3;
using Index = unsigned int;
public:
using Position = glm::vec3;
- using Color = glm::vec4;
+ using Color = glm::tvec4<unsigned char>;
using Index = unsigned short;
using Positions = std::vector<Position>;
void FillRect(
float w, float h,
- const glm::vec4 &color = glm::vec4(0.0f),
+ const Color &color = Color(0),
const glm::vec2 &pivot = glm::vec2(0.0f)
);
void OutlineBox(
const AABB &,
- const glm::vec4 &color = glm::vec4(0.0f)
+ const Color &color = Color(0)
);
};
void Bind() const noexcept;
template <class T>
- void PushAttribute(std::size_t which, const std::vector<T> &data) noexcept;
+ void PushAttribute(std::size_t which, const std::vector<T> &data, bool normalized = false) noexcept;
template<class T>
void PushIndices(std::size_t which, const std::vector<T> &indices) noexcept;
template <class T>
void AttributeData(const std::vector<T> &) noexcept;
template <class T>
- void AttributePointer(std::size_t which) noexcept;
+ void AttributePointer(std::size_t which, bool normalized = false) noexcept;
void BindIndex(std::size_t which) const noexcept;
template <class T>
template<std::size_t N>
template <class T>
-void VertexArray<N>::PushAttribute(std::size_t which, const std::vector<T> &data) noexcept {
+void VertexArray<N>::PushAttribute(std::size_t which, const std::vector<T> &data, bool normalized) noexcept {
BindAttribute(which);
AttributeData(data);
EnableAttribute(which);
- AttributePointer<T>(which);
+ AttributePointer<T>(which, normalized);
}
template<std::size_t N>
template<std::size_t N>
template <class T>
-void VertexArray<N>::AttributePointer(std::size_t which) noexcept {
+void VertexArray<N>::AttributePointer(std::size_t which, bool normalized) noexcept {
glVertexAttribPointer(
which, // program location
gl_traits<T>::size, // element size
gl_traits<T>::type, // element type
- GL_FALSE, // normalize to [-1,1] or [0,1] for unsigned types
+ normalized, // normalize to [-1,1] or [0,1] for unsigned types
0, // stride
nullptr // offset
);
vao.Bind();
vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
- vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
- vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
+ vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods, true);
+ vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods, true);
vao.PushAttribute(ATTRIB_NORMAL, buf.normals);
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
vao.Bind();
vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
vao.PushAttribute(ATTRIB_TEXCOORD, buf.tex_coords);
- vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods);
- vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods);
+ vao.PushAttribute(ATTRIB_HSL, buf.hsl_mods, true);
+ vao.PushAttribute(ATTRIB_RGB, buf.rgb_mods, true);
vao.PushAttribute(ATTRIB_LIGHT, buf.lights);
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
void PrimitiveMesh::Buffer::FillRect(
float w, float h,
- const glm::vec4 &color,
+ const Color &color,
const glm::vec2 &pivot
) {
Clear();
indices.assign({ 0, 2, 1, 1, 2, 3 });
}
-void PrimitiveMesh::Buffer::OutlineBox(const AABB &box, const glm::vec4 &color) {
+void PrimitiveMesh::Buffer::OutlineBox(const AABB &box, const Color &color) {
Clear();
Reserve(8, 24);
vao.Bind();
vao.PushAttribute(ATTRIB_VERTEX, buf.vertices);
- vao.PushAttribute(ATTRIB_COLOR, buf.colors);
+ vao.PushAttribute(ATTRIB_COLOR, buf.colors, true);
vao.PushIndices(ATTRIB_INDEX, buf.indices);
}
std::vector<float> tex_map;
mutable std::unique_ptr<EntityMesh> mesh;
State initial;
- glm::vec3 hsl_mod;
- glm::vec3 rgb_mod;
+ glm::tvec3<unsigned char> hsl_mod;
+ glm::tvec3<unsigned char> rgb_mod;
std::uint16_t id;
};
, tex_map()
, mesh()
, initial()
-, hsl_mod(0.0f, 1.0f, 1.0f)
-, rgb_mod(1.0f, 1.0f, 1.0f)
+, hsl_mod(0, 255, 255)
+, rgb_mod(255, 255, 255)
, id(0) {
}
std::string name;
std::string shape_name;
std::string tex_name;
+ glm::vec3 color_conv;
in.Skip(Token::ANGLE_BRACKET_OPEN);
while (in.HasMore() && in.Peek().type != Token::ANGLE_BRACKET_CLOSE) {
in.ReadIdentifier(name);
} else if (name == "orientation") {
in.ReadQuat(initial.orientation);
} else if (name == "hsl_mod") {
- in.ReadVec(hsl_mod);
+ in.ReadVec(color_conv);
+ hsl_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
} else if (name == "rgb_mod") {
- in.ReadVec(rgb_mod);
+ in.ReadVec(color_conv);
+ rgb_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
} else if (name == "textures") {
in.Skip(Token::BRACKET_OPEN);
while (in.HasMore() && in.Peek().type != Token::BRACKET_CLOSE) {
buf.indices = std::vector<PrimitiveMesh::Index>({
0, 1, 2, 3
});
- buf.colors.resize(4, { 10.0f, 10.0f, 10.0f, 1.0f });
+ buf.colors.resize(4, { 255, 255, 255, 255 });
crosshair.Update(buf);
}
const Shape *shape;
std::vector<float> textures;
- glm::vec3 hsl_mod;
- glm::vec3 rgb_mod;
- glm::vec3 outline_color;
+ glm::tvec3<unsigned char> hsl_mod;
+ glm::tvec3<unsigned char> rgb_mod;
+ glm::tvec3<unsigned char> outline_color;
/// gravity configuration or null if not emitting gravity
std::unique_ptr<BlockGravity> gravity;
BlockType::BlockType() noexcept
: shape(nullptr)
, textures()
-, hsl_mod(0.0f, 1.0f, 1.0f)
-, rgb_mod(1.0f, 1.0f, 1.0f)
+, hsl_mod(0, 255, 255)
+, rgb_mod(255, 255, 255)
, outline_color(-1, -1, -1)
, gravity()
, name("anonymous")
) {
std::string name;
in.Skip(Token::ANGLE_BRACKET_OPEN);
+ glm::vec3 color_conv;
while (in.Peek().type != Token::ANGLE_BRACKET_CLOSE) {
in.ReadIdentifier(name);
in.Skip(Token::EQUALS);
}
in.Skip(Token::BRACKET_CLOSE);
} else if (name == "rgb_mod") {
- in.ReadVec(rgb_mod);
+ in.ReadVec(color_conv);
+ rgb_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
} else if (name == "hsl_mod") {
- in.ReadVec(hsl_mod);
+ in.ReadVec(color_conv);
+ hsl_mod = glm::tvec3<unsigned char>(color_conv * 255.0f);
} else if (name == "outline") {
- in.ReadVec(outline_color);
+ in.ReadVec(color_conv);
+ outline_color = glm::tvec3<unsigned char>(color_conv * 255.0f);
} else if (name == "gravity") {
gravity = BlockGravity::Read(in);
} else if (name == "label") {
void BlockType::OutlinePrimitiveMesh(PrimitiveMesh::Buffer &buf) const noexcept {
if (!shape) return;
shape->Outline(buf);
- buf.colors.insert(buf.colors.end(), shape->OutlineCount(), glm::vec4(outline_color, 1.0f));
+ buf.colors.insert(buf.colors.end(), shape->OutlineCount(), glm::tvec4<unsigned char>(outline_color, 255));
}
PrimitiveMesh debug_mesh;
PlainColor &prog = viewport.WorldColorProgram();
for (const Entity &entity : entities) {
- debug_buf.OutlineBox(entity.Bounds(), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
+ debug_buf.OutlineBox(entity.Bounds(), glm::tvec4<unsigned char>(255, 0, 0, 255));
debug_mesh.Update(debug_buf);
prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords()));
debug_mesh.DrawLines();