Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: |
mkdir build
conan profile detect --force
conan install . --output-folder=build --build=missing -s build_type=Release
conan install . --output-folder=build --build=missing -s build_type=Release -s compiler.cppstd=20

- name: Generate projects
run: |
Expand Down
2 changes: 1 addition & 1 deletion BMEdit/Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ target_compile_definitions(Editor
# --- Required GameLib & Qt6
target_link_libraries(Editor PUBLIC Qt6::Widgets OpenGL::GL Qt6::OpenGL Qt6::OpenGLWidgets)
target_link_libraries(Editor PRIVATE GameLib RenderDoc::AppInterface)
target_link_libraries(Editor PRIVATE ${libzip_LIBRARIES} ${ZLIB_LIBRARIES} ${libsquish_LIBRARIES})
target_link_libraries(Editor PRIVATE ${libzip_LIBRARIES} ${ZLIB_LIBRARIES} ${libsquish_LIBRARIES} Freetype::Freetype)
target_include_directories(Editor PRIVATE ${ZLIB_INCLUDE_DIRS} ${libzip_INCLUDE_DIRS} ${libsquish_INCLUDE_DIRS})
target_compile_definitions(Editor PRIVATE ${libzip_DEFINITIONS} ${libsquish_DEFINITIONS})
49 changes: 46 additions & 3 deletions BMEdit/Editor/Include/Render/GizmoRenderer.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
#pragma once

#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QFile>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/vec2.hpp>
#include <glm/mat4x4.hpp>
#include <vector>
#include <map>
#include <string>
#include <GameLib/BoundingBox.h>
#include <Render/GL.h>

#include <ft2build.h>
#include FT_FREETYPE_H

namespace render
{
class GizmoRenderer
{
public:
bool setup(GLFunctions *gapi);
bool setup(GLFunctions *gapi, int screenWidth, int screenHeight);
bool setFont(GLFunctions *gapi, QFile &fontFile, int pixelSize);
void setScreenSize(int w, int h);
void clear();
void addLine(const glm::vec3& a, const glm::vec3& b, const glm::vec4& color);
void addAABB(const gamelib::BoundingBox& box, const glm::vec4& fillColor, const glm::vec4& lineColor);
void render(GLFunctions *gapi, QOpenGLShaderProgram *shader, GLint cameraProjViewLoc, const glm::mat4 &projView);
void addText(const std::string& text, const glm::vec2& screenPos, float size);
void render(GLFunctions *gapi,
QOpenGLShaderProgram *shader,
GLint cameraProjViewLoc,
const glm::mat4 &projView,
QOpenGLShaderProgram *textShader);

private:
struct Vertex
Expand All @@ -31,5 +44,35 @@ namespace render
GLuint m_triVao {0}, m_triVbo {0};
std::vector<Vertex> m_lines;
std::vector<Vertex> m_tris;

struct Glyph {
glm::vec2 texCoordMin;// Top-left UV coordinate
glm::vec2 texCoordMax;// Bottom-right UV coordinate
glm::ivec2 size; // Width and height in pixels
glm::ivec2 bearing; // Offset from baseline to glyph origin
GLuint advance; // Horizontal advance to next glyph
};

struct TextVertex
{
glm::vec2 pos;
glm::vec2 uv;
glm::vec4 color;
};

struct TextGlyph
{
TextVertex verts[6];
};

std::vector<TextGlyph> m_text;
std::map<char, Glyph> m_glyphs;
FT_Library m_ft { nullptr };
FT_Face m_face { nullptr };
GLuint m_textVao {0}, m_textVbo {0};
int m_screenW {1}, m_screenH {1};

GLuint m_atlasTexture = 0;
QByteArray m_fontData;
};
}
5 changes: 5 additions & 0 deletions BMEdit/Editor/Include/Widgets/SceneRenderWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QMouseEvent>
#include <QKeyEvent>
#include <QString>
#include <QFile>

#include <Render/RenderEntry.h>
#include <Render/GizmoRenderer.h>
Expand All @@ -21,6 +22,7 @@
#include <memory>
#include <vector>
#include <list>
#include <string>


class QOpenGLFunctions_3_3_Core;
Expand Down Expand Up @@ -60,7 +62,9 @@ namespace widgets

void addGizmoLine(const glm::vec3& a, const glm::vec3& b, const glm::vec4& color) { m_gizmo.addLine(a, b, color); }
void addGizmoBox(const gamelib::BoundingBox &box, const glm::vec4 &color, const glm::vec4 &lineColor) { m_gizmo.addAABB(box, color, lineColor); }
void addGizmoText(const std::string& text, const glm::vec2& pos, float size) { m_gizmo.addText(text, pos, size); }
void clearGizmos() { m_gizmo.clear(); }
bool setGizmoFont(QFile &file, int pixelSize);
signals:
void resourcesReady();
void resourceLoadFailed(const QString& reason);
Expand Down Expand Up @@ -88,6 +92,7 @@ namespace widgets
void updateViewLists();
void generateDrawCommands();
void drawScene();
void drawGizmo();
void generateGizmosForEntity(gamelib::scene::SceneObject* pSceneObject);

[[nodiscard]] glm::ivec2 getViewportSize() const {
Expand Down
4 changes: 4 additions & 0 deletions BMEdit/Editor/Resources/BMEdit.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
<file alias="culling.csh">Shaders/Culling.csh</file>
<file alias="gizmo_gl33.vsh">Shaders/Gizmo_GL33.vsh</file>
<file alias="gizmo_gl33.fsh">Shaders/Gizmo_GL33.fsh</file>
<file alias="gizmo_text_gl33.vsh">Shaders/GizmoText_GL33.vsh</file>
<file alias="gizmo_text_gl33.fsh">Shaders/GizmoText_GL33.fsh</file>

<file alias="gizmo_font_main.ttf">Fonts/DejaVuSansMono.ttf</file>
</qresource>
</RCC>
Binary file added BMEdit/Editor/Resources/Fonts/DejaVuSansMono.ttf
Binary file not shown.
31 changes: 31 additions & 0 deletions BMEdit/Editor/Resources/Shaders/GizmoText_GL33.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#version 450 core

in vec2 fUV;
in vec4 fColor;

out vec4 FragColor;

uniform sampler2D textAtlas;
uniform float outlineThickness;

void main() {
vec4 outlineColor = vec4(0.0); // NOTE: Maybe will pass from CPU as uniform, idk
float distance = texture(textAtlas, fUV).r;

// Transform distance into world space
float smoothing = fwidth(distance);

// Calculate alpha for main part
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);

// Calculate alpha for outline
float outlineDistance = 0.5 - outlineThickness;
float outlineAlpha = smoothstep(outlineDistance - smoothing, outlineDistance + smoothing, distance);

// Combine all
vec4 textColor = fColor;
vec4 finalColor = mix(outlineColor, textColor, alpha);
finalColor.a = outlineAlpha;

FragColor = finalColor;
}
12 changes: 12 additions & 0 deletions BMEdit/Editor/Resources/Shaders/GizmoText_GL33.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450 core
layout(location = 0) in vec2 vPos;
layout(location = 1) in vec2 vUV;
layout(location = 2) in vec4 vColor;
out vec2 fUV;
out vec4 fColor;
void main()
{
gl_Position = vec4(vPos, 0.0, 1.0);
fUV = vUV;
fColor = vColor;
}
2 changes: 1 addition & 1 deletion BMEdit/Editor/Resources/Shaders/Gizmo_GL33.fsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 330 core
#version 450 core
in vec4 fColor;
out vec4 FragColor;
void main()
Expand Down
2 changes: 1 addition & 1 deletion BMEdit/Editor/Resources/Shaders/Gizmo_GL33.vsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 330 core
#version 450 core
layout(location = 0) in vec3 vPos;
layout(location = 1) in vec4 vColor;
uniform mat4 cameraProjView;
Expand Down
2 changes: 1 addition & 1 deletion BMEdit/Editor/Source/Edtor/EditorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace editor {
try
#endif
{
if (!m_currentLevel->loadSceneData())
if (!m_currentLevel->loadSceneData(gamelib::LevelLoadCompatibilityLevel::CL_HitmanBloodMoney))
{
levelLoadFailed(QString("Unable to load scene data!"));
return;
Expand Down
8 changes: 6 additions & 2 deletions BMEdit/Editor/Source/Edtor/TextureProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ namespace editor
std::memcpy(result.get(), textureEntry.m_mipLevels.at(mipLevel).m_buffer.get(), realWidth * realHeight * 4);
return result;
}
else if (format == EntryType::ET_BITMAP_DXT1 || format == EntryType::ET_BITMAP_DXT3)
else if (format == EntryType::ET_BITMAP_DXT1 || format == EntryType::ET_BITMAP_DXT3 || format == EntryType::ET_BITMAP_DXT5)
{
// DXT1, DXT3: Process via squish
int flags = 0;

flags |= (format == EntryType::ET_BITMAP_DXT1 ? squish::kDxt1 : 0);
flags |= (format == EntryType::ET_BITMAP_DXT3 ? squish::kDxt3 : 0);
flags |= (format == EntryType::ET_BITMAP_DXT5 ? squish::kDxt5 : 0);

auto result = std::make_unique<uint8_t[]>(static_cast<int>(realWidth) * static_cast<int>(realHeight) * 4);
squish::DecompressImage(result.get(), realWidth, realHeight, textureEntry.m_mipLevels.at(mipLevel).m_buffer.get(), flags);

Expand Down Expand Up @@ -304,14 +306,16 @@ namespace editor
break;
case gamelib::tex::TEXEntryType::ET_BITMAP_DXT1:
case gamelib::tex::TEXEntryType::ET_BITMAP_DXT3:
// Use libsquish to create DXT1/DXT3 buffers
case gamelib::tex::TEXEntryType::ET_BITMAP_DXT5:
// Use libsquish to create DXT1/DXT3/DXT5 buffers
{
uint32_t w = sourceMIP.width();
uint32_t h = sourceMIP.height();
int flags = 0;

flags |= (targetFormat == gamelib::tex::TEXEntryType::ET_BITMAP_DXT1 ? squish::kDxt1 : 0);
flags |= (targetFormat == gamelib::tex::TEXEntryType::ET_BITMAP_DXT3 ? squish::kDxt3 : 0);
flags |= (targetFormat == gamelib::tex::TEXEntryType::ET_BITMAP_DXT5 ? squish::kDxt5 : 0);

// Calculate & allocate space
textureMIP.m_mipLevelSize = squish::GetStorageRequirements(static_cast<int>(w), static_cast<int>(h), flags);
Expand Down
2 changes: 1 addition & 1 deletion BMEdit/Editor/Source/Models/LocalizationTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace models
{
const auto& root = m_level->getLevelLocalization()->localizationRoot;

return root->children.empty() ? 0 : static_cast<int>(root->children.size());
return !root || root->children.empty() ? 0 : static_cast<int>(root->children.size());
}

if (auto node = static_cast<gamelib::loc::LOCTreeNode*>(parent.internalPointer()))
Expand Down
1 change: 1 addition & 0 deletions BMEdit/Editor/Source/Models/SceneTexturesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ QVariant SceneTexturesModel::data(const QModelIndex &index, int role) const
case gamelib::tex::TEXEntryType::ET_BITMAP_U8V8: return "U8V8";
case gamelib::tex::TEXEntryType::ET_BITMAP_DXT1: return "DXT1";
case gamelib::tex::TEXEntryType::ET_BITMAP_DXT3: return "DXT3";
case gamelib::tex::TEXEntryType::ET_BITMAP_DXT5: return "DXT5";
default:
assert(false && "Unknown entry");
return "Unknown";
Expand Down
Loading
Loading