Commit 62a50c97 authored by Johannes Braun's avatar Johannes Braun
Browse files

Huge function-style-cast to static_cast refactoring

parent 180949c3
......@@ -75,10 +75,10 @@ namespace glare
const float size = m_sector_size;
math::Vertex vertex;
for (int y = 0; y < int(m_height); ++y) {
for (int x = 0; x < int(m_width); ++x) {
for (int y = 0; y < static_cast<int>(m_height); ++y) {
for (int x = 0; x < static_cast<int>(m_width); ++x) {
const unsigned index_offset = (unsigned(m_width)*y + x) * v_count;
const unsigned index_offset = (static_cast<unsigned>(m_width)*y + x) * v_count;
//Base plateau
{
......
......@@ -28,7 +28,7 @@ const fs::path engine_settings_path = files::asset("/preferences/default.xml");
const fs::path pathtracer_settings_path = files::asset("/preferences/pathtracer_default.xml");
const fs::path skybox_files_path = files::asset("/textures/ryfjallet/");
const fs::path env_audio_path = files::asset("/audio/env.wav");
const fs::path startup_scene_path = files::asset("/meshes/scenery/material_testscene.dae");
const fs::path startup_scene_path = files::asset("/meshes/scenery/sphere.dae");
// My little all-enclosing pathtracer pointer
std::unique_ptr<raytrace::Pathtracer> pathtracer = nullptr;
......@@ -163,9 +163,9 @@ void drawDebugGui()
ImGui::BeginNamedGroup("Render Mode");
{
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
int render_state = int(render_mode);
int render_state = static_cast<int>(render_mode);
if (ImGui::Combo("", &render_state, { "OpenGL Wireframe", "OpenGL Raw Color", "OpenGL GBuffer", "Pathtracing" }))
render_mode = RenderMode(render_state);
render_mode = static_cast<RenderMode>(render_state);
ImGui::PopItemWidth();
}
ImGui::EndNamedGroup();
......@@ -187,10 +187,10 @@ void drawDebugGui()
{
ImGui::BeginNamedGroup("Ray Generator");
{
int raygenstate = int(pathtracer->getGenerator());
int raygenstate = static_cast<int>(pathtracer->getGenerator());
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
if (ImGui::Combo("", &raygenstate, { "Trace [default]", "OpenGL GBuffer" })) {
pathtracer->setGenerator(raytrace::RayGeneratorType(raygenstate));
pathtracer->setGenerator(static_cast<raytrace::RayGeneratorType>(raygenstate));
}
ImGui::PopItemWidth();
}
......@@ -201,7 +201,7 @@ void drawDebugGui()
ImGui::BeginNamedGroup("Samples");
{
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
ImGui::ProgressBar(pathtracer->currentSample() / float(pathtracer->getMaxSamples()), ImVec2(-1, 0),
ImGui::ProgressBar(pathtracer->currentSample() / static_cast<float>(pathtracer->getMaxSamples()), ImVec2(-1, 0),
("Current: " + std::to_string(pathtracer->currentSample()) + " of " + std::to_string(pathtracer->getMaxSamples())).c_str());
ImGui::PopItemWidth();
......@@ -234,7 +234,7 @@ void drawDebugGui()
{
int val = pathtracer->getEffectBounces(effect);
if (ImGui::DragInt(label.c_str(), &val, 0.1f, 0, 255))
pathtracer->setEffectBounces(effect, uint8_t(val));
pathtracer->setEffectBounces(effect, static_cast<uint8_t>(val));
};
effectBounces("Diffusion", raytrace::EffectType::eDiffusion);
......@@ -288,7 +288,7 @@ void drawDebugGui()
{
int val = pathtracer->getLinespaceBounceThreshold(effect);
if (ImGui::DragInt(label.c_str(), &val, 0.1f, 0, pathtracer->getEffectBounces(effect)))
pathtracer->setLinespaceBounceThresholds(effect, uint8_t(val));
pathtracer->setLinespaceBounceThresholds(effect, static_cast<uint8_t>(val));
};
bounceControl("Diffusion", raytrace::EffectType::eDiffusion);
......@@ -318,7 +318,7 @@ void drawDebugGui()
int vsync = int(core::state::window->getVSync());
if (ImGui::Combo("VSync", &vsync, { "None", "60 FPS", "30 FPS", "20 FPS" }))
core::state::window->setVSync(VSync(vsync));
core::state::window->setVSync(static_cast<VSync>(vsync));
ImGui::Separator();
ImGui::Title("Controls");
......
......@@ -15,8 +15,8 @@ namespace glare
if (time >= 1)
{
fps = float(frame);
frametime = float(1000 * time / frame);
fps = static_cast<float>(frame);
frametime = static_cast<float>(1000 * time / frame);
Log_Debug << std::to_string(frame) << " FPS | " << std::to_string(1000 * time / frame) << "ms/Frame";
time = 0;
frame = 0;
......
......@@ -88,11 +88,11 @@ namespace glare
{
auto transform = m_owner.lock()->transform();
float forward = float((controls::keyState(controls::Key::eW) == controls::ButtonAction::ePress) -
float forward = static_cast<float>((controls::keyState(controls::Key::eW) == controls::ButtonAction::ePress) -
(controls::keyState(controls::Key::eS) == controls::ButtonAction::ePress));
float right = float((controls::keyState(controls::Key::eD) == controls::ButtonAction::ePress) -
float right = static_cast<float>((controls::keyState(controls::Key::eD) == controls::ButtonAction::ePress) -
(controls::keyState(controls::Key::eA) == controls::ButtonAction::ePress));
float up = float((controls::keyState(controls::Key::eE) == controls::ButtonAction::ePress) -
float up = static_cast<float>((controls::keyState(controls::Key::eE) == controls::ButtonAction::ePress) -
(controls::keyState(controls::Key::eQ) == controls::ButtonAction::ePress));
if (controls::keyState(controls::Key::eLeftShift) == controls::ButtonAction::ePress) {
......
......@@ -18,7 +18,7 @@ namespace glare
m_data = audio::loadWAV(from_file);
m_format = format(m_data.bits_per_sample, m_data.channels);
al::bufferData(m_handle, m_format, unsigned(m_data.data.size()), m_data.sample_rate, m_data.data.data());
al::bufferData(m_handle, m_format, static_cast<unsigned>(m_data.data.size()), m_data.sample_rate, m_data.data.data());
}
unsigned SoundBuffer::id() const
......
......@@ -158,7 +158,7 @@ namespace glare
gl::namedFramebufferDrawBuffers(m_handle, m_draw_buffers);
}
if (auto status = gl::checkNamedFramebufferStatus(m_handle, gl::FramebufferTarget::eDraw) != gl::FramebufferStatus::eComplete)
Log_Error << "An error occured when generating the framebuffer: " << int(status);
Log_Error << "An error occured when generating the framebuffer: " << static_cast<int>(status);
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
......
......@@ -53,7 +53,7 @@ namespace glare
gl::setEnabled(gl::EnableParameter::eCullFace, m_last_enable_cull_face);
gl::setEnabled(gl::EnableParameter::eDepthTest, m_last_enable_depth_test);
gl::setEnabled(gl::EnableParameter::eScissorTest, m_last_enable_scissor_test);
gl::viewport(m_last_viewport[0], m_last_viewport[1], unsigned(m_last_viewport[2]), unsigned(m_last_viewport[3]));
gl::viewport(m_last_viewport[0], m_last_viewport[1], static_cast<unsigned>(m_last_viewport[2]), static_cast<unsigned>(m_last_viewport[3]));
}
}
}
......@@ -55,12 +55,12 @@ namespace glare
for (int i = 0; i < num_uniforms; ++i) {
UniformInfo data;
int length = max_length;
char* name = new char[length];
gl::getActiveUniform(m_handle, i, length, &data.size, &data.type, name);
data.name = name;
data.index = uniformLocation(name);
int length = max_length;
char* name = new char[length];
gl::getActiveUniform(m_handle, i, length, &data.size, &data.type, name);
data.name = name;
data.index = uniformLocation(name);
m_uniforms[data.name] = data;
if (data.size > 1 && std::string(data.name.data() + data.name.length() - 3) == "[0]")
......@@ -76,6 +76,7 @@ namespace glare
m_uniforms[data.name] = data;
}
}
delete[] name;
}
}
......@@ -92,18 +93,19 @@ namespace glare
for (int sr = 0; sr < num_subroutines; ++sr)
{
int length;
char* name = new char[max_length];
gl::getActiveSubroutineName(m_handle, shader->type(), sr, max_length, &length, name);
SubroutineInfo info;
info.index = sr;
info.name = name;
info.shader_type = shader->type();
m_subroutines[info.name].emplace(info.shader_type, info);
int length;
char* name = new char[max_length];
gl::getActiveSubroutineName(m_handle, shader->type(), sr, max_length, &length, name);
SubroutineInfo info;
info.index = sr;
info.name = name;
info.shader_type = shader->type();
m_subroutines[info.name].emplace(info.shader_type, info);
delete[] name;
delete[] name;
}
}
}
......@@ -169,7 +171,7 @@ namespace glare
if (location >= 0) {
auto &&list = m_subroutine_bindings[stage];
list.resize(glm::max(int(list.size()), location + 1));
list.resize(glm::max(static_cast<int>(list.size()), location + 1));
list[location] = subroutineIndex(stage, subroutine);
}
}
......
......@@ -38,7 +38,7 @@ namespace glare
gl::namedString(gl::NamedStringType::eShaderInclude, relative.string(), content);
m_named_strings.push_back(relative.string());
m_named_string_lengths.push_back(int(relative.string().size()));
m_named_string_lengths.push_back(static_cast<int>(relative.string().size()));
}
}
}
......@@ -238,7 +238,7 @@ namespace glare
const bool empty_call = content[pos + 1] == ')';
const size_t exp_length = expression_name.length();
unsigned temp_pos = pos - 2 - unsigned(exp_length);
unsigned temp_pos = pos - 2 - static_cast<unsigned>(exp_length);
char last = content[temp_pos];
std::string object;
......@@ -246,16 +246,12 @@ namespace glare
object = last + object;
last = content[--temp_pos];
}
// Log_Debug << "Rebuilding Method call \"" << expression_name << "\" on object \"" << object << "\"";
content = content.erase(temp_pos + 1, object.length() + 1);
content = content.insert(temp_pos + 2 + exp_length, object + (empty_call ? "" : ","));
pos = temp_pos;
// Log_Debug << "Final restructure: " << "..." << content.substr(temp_pos + 1, exp_length + 6 + object.length()) << "...";
state = state_t::eIdle;
}
else
......
......@@ -7,12 +7,12 @@ namespace glare
{
ButtonAction keyState(Key key)
{
return ButtonAction(core::state::window->getKeyState(int(key)));
return static_cast<ButtonAction>(core::state::window->getKeyState(static_cast<int>(key)));
}
ButtonAction mouseButtonState(MouseButton button)
{
return ButtonAction(core::state::window->getMouseButtonState(int(button)));
return static_cast<ButtonAction>(core::state::window->getMouseButtonState(static_cast<int>(button)));
}
glm::vec2 getCursorPosition()
......
......@@ -41,7 +41,7 @@ namespace glare
{
if (m_id == 0)
{
static uint64_t m_current_id = 1;
static uint64_t m_current_id = 1ui64;
m_id = m_current_id++;
}
return m_id;
......
......@@ -9,19 +9,19 @@ template<typename T> using enable_flag = std::enable_if_t<std::is_enum<T>::value
template<typename TEnum, enable_flag<TEnum>...>
inline TEnum operator&(TEnum left, TEnum right)
{
return TEnum(unsigned(left) & unsigned(right));
return TEnum(static_cast<unsigned>(left) & static_cast<unsigned>(right));
}
template<typename TEnum, enable_flag<TEnum>...>
inline TEnum operator|(TEnum left, TEnum right)
{
return TEnum(unsigned(left) | unsigned(right));
return TEnum(static_cast<unsigned>(left) | static_cast<unsigned>(right));
}
template<typename TEnum, enable_flag<TEnum>...>
inline TEnum operator^(TEnum left, TEnum right)
{
return TEnum(unsigned(left) ^ unsigned(right));
return TEnum(static_cast<unsigned>(left) ^ static_cast<unsigned>(right));
}
template<typename TEnum, enable_flag<TEnum>...>
......@@ -78,37 +78,37 @@ namespace math
template<typename TEnum, enable_flag<TEnum>...>
bool Flags::operator&(TEnum flags) const
{
return (m_flags & unsigned(flags)) != 0;
return (m_flags & static_cast<unsigned>(flags)) != 0;
}
template<typename TEnum, enable_flag<TEnum>...>
bool Flags::operator|(TEnum flags) const
{
return (m_flags | unsigned(flags)) != 0;
return (m_flags | static_cast<unsigned>(flags)) != 0;
}
template<typename TEnum, enable_flag<TEnum>...>
bool Flags::operator^(TEnum flags) const
{
return (m_flags ^ unsigned(flags)) != 0;
return (m_flags ^ static_cast<unsigned>(flags)) != 0;
}
template<typename TEnum, enable_flag<TEnum>...>
TEnum Flags::operator&=(TEnum flags)
{
return TEnum(m_flags &= unsigned(flags));
return TEnum(m_flags &= static_cast<unsigned>(flags));
}
template<typename TEnum, enable_flag<TEnum>...>
TEnum Flags::operator|=(TEnum flags)
{
return TEnum(m_flags |= unsigned(flags));
return TEnum(m_flags |= static_cast<unsigned>(flags));
}
template<typename TEnum, enable_flag<TEnum>...>
TEnum Flags::operator^=(TEnum flags)
{
return TEnum(m_flags ^= unsigned(flags));
return TEnum(m_flags ^= static_cast<unsigned>(flags));
}
}
......
......@@ -212,7 +212,7 @@ namespace math
const int largest_axis = largestAxis();
const glm::vec3 bounds_size = glm::max(glm::vec3(size().xyz), glm::vec3(1e-5f));
const float largest_axis_value = glm::compMax(bounds_size);
subdivision.size = largest_axis_value / float(max_subdivisions) + 1e-5f;
subdivision.size = largest_axis_value / static_cast<float>(max_subdivisions) + 1e-5f;
subdivision.resolution = glm::ivec3(0);
subdivision.resolution[largest_axis] = max_subdivisions;
......
......@@ -83,9 +83,9 @@ namespace glare
switch (m_projection)
{
default:
return glm::perspective(glm::radians(m_field_of_view), m_width / float(m_height), m_near, m_far);
return glm::perspective(glm::radians(m_field_of_view), m_width / static_cast<float>(m_height), m_near, m_far);
case Projection::eOrthographic:
return glm::ortho(-float(m_width) / 2, float(m_width)/2, -float(m_height)/2, float(m_height) / 2, m_near, m_far);
return glm::ortho(-static_cast<float>(m_width) / 2, static_cast<float>(m_width)/2, -static_cast<float>(m_height)/2, static_cast<float>(m_height) / 2, m_near, m_far);
}
}
......@@ -118,12 +118,12 @@ namespace glare
{
//translate the center (0, 0) to the bottom left and then scale it by 2 to stretch it over the screen. After that, scale it by the screen resolution.
return glm::translate(glm::vec3(-1, -1, 0)) *
glm::scale(glm::vec3(2 / float(m_width), 2 / float(m_height), 2));
glm::scale(glm::vec3(2 / static_cast<float>(m_width), 2 / static_cast<float>(m_height), 2));
}
float Camera::getAspectRatio() const
{
return float(m_width) / float(m_height);
return static_cast<float>(m_width) / static_cast<float>(m_height);
}
float Camera::getWidth() const
......
......@@ -68,34 +68,34 @@ namespace glare
m_shader->uniform("u_material.base.value", base.value);
if (base.texture)
m_shader->uniform("u_material.base.texture", base.texture->makeTextureResident());
m_shader->uniform("u_material.base.texture_available", uint32_t(bool(base.texture)));
m_shader->uniform("u_material.base.texture_available", static_cast<uint32_t>(static_cast<bool>(base.texture)));
m_shader->uniform("u_material.roughness.value", roughness.value);
if (base.texture)
m_shader->uniform("u_material.roughness.texture", roughness.texture->makeTextureResident());
m_shader->uniform("u_material.roughness.texture_available", uint32_t(bool(roughness.texture)));
m_shader->uniform("u_material.roughness.texture_available", static_cast<uint32_t>(static_cast<bool>(roughness.texture)));
m_shader->uniform("u_material.metallic.value", metallic.value);
if (base.texture)
m_shader->uniform("u_material.metallic.texture", metallic.texture->makeTextureResident());
m_shader->uniform("u_material.metallic.texture_available", uint32_t(bool(metallic.texture)));
m_shader->uniform("u_material.metallic.texture_available", static_cast<uint32_t>(static_cast<bool>(metallic.texture)));
m_shader->uniform("u_material.transmission.value", transmissive.value);
if (base.texture)
m_shader->uniform("u_material.transmission.texture", transmissive.texture->makeTextureResident());
m_shader->uniform("u_material.transmission.texture_available", uint32_t(bool(transmissive.texture)));
m_shader->uniform("u_material.transmission.texture_available", static_cast<uint32_t>(static_cast<bool>(transmissive.texture)));
m_shader->uniform("u_material.emission.value", emission.value);
if (base.texture)
m_shader->uniform("u_material.emission.texture", emission.texture->makeTextureResident());
m_shader->uniform("u_material.emission.texture_available", uint32_t(bool(emission.texture)));
m_shader->uniform("u_material.emission.texture_available", static_cast<uint32_t>(static_cast<bool>(emission.texture)));
if (map_normal)
m_shader->uniform("u_material.normal_map", map_normal->makeTextureResident());
if (map_displacement)
m_shader->uniform("u_material.displacement_map", map_displacement->makeTextureResident());
m_shader->uniform("u_material.has_displacement_map", bool(map_displacement));
m_shader->uniform("u_material.has_normal_map", bool(emission.texture));
m_shader->uniform("u_material.has_displacement_map", static_cast<bool>(map_displacement));
m_shader->uniform("u_material.has_normal_map", static_cast<bool>(emission.texture));
m_shader->uniform("u_material.ior", index_of_refraction);
......
......@@ -122,11 +122,11 @@ namespace glare
m_array_buffer->upload(m_vertices, gl::BufferUsage::eStaticDraw);
m_element_array_buffer->upload(m_indices, gl::BufferUsage::eStaticDraw);
m_vertex_array->linkAttribute(m_array_buffer->id(), unsigned(VertexAttribLocation::ePosition), 4, gl::Type::eFloat, false, sizeof(math::Vertex), 0);
m_vertex_array->linkAttribute(m_array_buffer->id(), unsigned(VertexAttribLocation::eNormal), 4, gl::Type::eFloat, false, sizeof(math::Vertex), sizeof(glm::vec4));
m_vertex_array->linkAttribute(m_array_buffer->id(), unsigned(VertexAttribLocation::eTexcoord), 2, gl::Type::eFloat, false, sizeof(math::Vertex), 2 * sizeof(glm::vec4)); //Length of 2, but there is a padding in-between.
m_vertex_array->linkAttribute(m_array_buffer->id(), unsigned(VertexAttribLocation::eTangent), 4, gl::Type::eFloat, false, sizeof(math::Vertex), 3 * sizeof(glm::vec4));
m_vertex_array->linkAttribute(m_array_buffer->id(), unsigned(VertexAttribLocation::eBitangend), 4, gl::Type::eFloat, false, sizeof(math::Vertex), 4 * sizeof(glm::vec4));
m_vertex_array->linkAttribute(m_array_buffer->id(), static_cast<unsigned>(VertexAttribLocation::ePosition), 4, gl::Type::eFloat, false, sizeof(math::Vertex), 0);
m_vertex_array->linkAttribute(m_array_buffer->id(), static_cast<unsigned>(VertexAttribLocation::eNormal), 4, gl::Type::eFloat, false, sizeof(math::Vertex), sizeof(glm::vec4));
m_vertex_array->linkAttribute(m_array_buffer->id(), static_cast<unsigned>(VertexAttribLocation::eTexcoord), 2, gl::Type::eFloat, false, sizeof(math::Vertex), 2 * sizeof(glm::vec4)); //Length of 2, but there is a padding in-between.
m_vertex_array->linkAttribute(m_array_buffer->id(), static_cast<unsigned>(VertexAttribLocation::eTangent), 4, gl::Type::eFloat, false, sizeof(math::Vertex), 3 * sizeof(glm::vec4));
m_vertex_array->linkAttribute(m_array_buffer->id(), static_cast<unsigned>(VertexAttribLocation::eBitangend), 4, gl::Type::eFloat, false, sizeof(math::Vertex), 4 * sizeof(glm::vec4));
m_vertex_array->linkIndices(m_element_array_buffer->id());
}
......
......@@ -43,8 +43,8 @@ namespace glare
scene_root->draw(DrawMode::eNoColor);
gl::setEnabled(gl::EnableParameter::eCullFace, true);
core::state::camera = main_camera;
gl::viewport(0, 0, unsigned(core::state::camera->getWidth()),
unsigned(core::state::camera->getWidth() / core::state::camera->getAspectRatio()));
gl::viewport(0, 0, static_cast<unsigned>(core::state::camera->getWidth()),
static_cast<unsigned>(core::state::camera->getWidth() / core::state::camera->getAspectRatio()));
gl::bindFramebuffer(gl::FramebufferTarget::eDefault, current_fb);
m_matrix = m_bias_matrix * m_camera->getViewProjection();
......
......@@ -40,7 +40,7 @@ namespace glare
Log_Debug << "Face No " << face;
auto vec = images::load<unsigned char>(faces[face], width, height, 3);
images::flip(width, height, 3, vec.data());
gl::textureImage2D(m_handle, gl::TextureImageTarget2D(int(gl::TextureImageTarget2D::eCubeMapPosX) + face), 0, gl::TextureInternalFormat::eRGB, width, height, 0, gl::TextureFormat::eRGB, gl::Type::eUByte, vec.data());
gl::textureImage2D(m_handle, gl::TextureImageTarget2D(static_cast<int>(gl::TextureImageTarget2D::eCubeMapPosX) + face), 0, gl::TextureInternalFormat::eRGB, width, height, 0, gl::TextureFormat::eRGB, gl::Type::eUByte, vec.data());
}
gl::textureParameter(m_handle, gl::TextureParameter::eMagFilter, gl::TextureFilterMag::eLinear);
......
......@@ -31,7 +31,7 @@ namespace glare
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
m_gbuffer_framebuffer = std::make_shared<Framebuffer<TextureMultisampled>>(unsigned(mode->width), unsigned(mode->height), samples);
m_gbuffer_framebuffer = std::make_shared<Framebuffer<TextureMultisampled>>(static_cast<unsigned>(mode->width), static_cast<unsigned>(mode->height), samples);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor0);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor1);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor2);
......
......@@ -38,7 +38,6 @@ namespace glare
std::string asset_path = splash_background.child("texture").attribute("src").as_string("");
if (asset_path != "") {
m_background_config |= 1 << 3;
m_background_texture = Resources::getInstance().getTexture(files::asset(asset_path));
......@@ -106,7 +105,7 @@ namespace glare
};
anim->on_update = [&](double, double current_value) {
m_animation_progress = float(current_value);
m_animation_progress = static_cast<float>(current_value);
};
anim->on_finish = [&]() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment