refactor: 重构文件结构,将backend相关文件移动到opengl目录
- 将graphics/backends/opengl下的文件移动到graphics/opengl目录 - 更新相关头文件引用路径 - 调整xmake构建文件以匹配新的文件结构 - 清理不再使用的service_locator.h包含 - 格式化代码并统一代码风格
This commit is contained in:
parent
b892736fb2
commit
a490d9e296
|
|
@ -1,84 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/texture/font.h>
|
||||
|
||||
#include <stb/stb_truetype.h>
|
||||
#include <stb/stb_rect_pack.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
// OpenGL 字体图集实现 (使用 STB 库)
|
||||
// 使用 stb_rect_pack 进行动态矩形打包,支持动态缓存字形
|
||||
// ============================================================================
|
||||
class GLFontAtlas : public FontAtlas {
|
||||
public:
|
||||
GLFontAtlas(const std::string& filepath, int fontSize, bool useSDF = false);
|
||||
~GLFontAtlas() override;
|
||||
|
||||
// FontAtlas 接口实现
|
||||
const Glyph* getGlyph(char32_t codepoint) const override;
|
||||
Texture* getTexture() const override { return texture_.get(); }
|
||||
int getFontSize() const override { return fontSize_; }
|
||||
float getAscent() const override { return ascent_; }
|
||||
float getDescent() const override { return descent_; }
|
||||
float getLineGap() const override { return lineGap_; }
|
||||
float getLineHeight() const override { return lineHeight_; }
|
||||
bool isSDF() const override { return useSDF_; }
|
||||
Vec2 measureText(const std::string& text) override;
|
||||
|
||||
private:
|
||||
// 字形数据内部结构
|
||||
struct GlyphData {
|
||||
float width;
|
||||
float height;
|
||||
float bearingX;
|
||||
float bearingY;
|
||||
float advance;
|
||||
float u0, v0, u1, v1;
|
||||
};
|
||||
|
||||
// 图集配置 - 增大尺寸以支持更多字符
|
||||
static constexpr int ATLAS_WIDTH = 1024;
|
||||
static constexpr int ATLAS_HEIGHT = 1024;
|
||||
static constexpr int PADDING = 2; // 字形之间的间距
|
||||
|
||||
bool useSDF_;
|
||||
int fontSize_;
|
||||
|
||||
Ptr<GLTexture> texture_;
|
||||
std::unordered_map<char32_t, GlyphData> glyphs_;
|
||||
float lineHeight_;
|
||||
float ascent_;
|
||||
float descent_;
|
||||
float lineGap_;
|
||||
|
||||
// 字体数据
|
||||
std::vector<unsigned char> fontData_;
|
||||
stbtt_fontinfo fontInfo_;
|
||||
float scale_;
|
||||
|
||||
// stb_rect_pack 上下文 - 持久化以支持增量打包
|
||||
mutable stbrp_context packContext_;
|
||||
mutable std::vector<stbrp_node> packNodes_;
|
||||
|
||||
// 预分配缓冲区,避免每次动态分配
|
||||
mutable std::vector<uint8_t> glyphBitmapCache_;
|
||||
mutable std::vector<uint8_t> glyphRgbaCache_;
|
||||
|
||||
// 初始化字体
|
||||
bool initFont(const std::string& filepath);
|
||||
// 创建空白图集纹理
|
||||
void createAtlas();
|
||||
// 缓存字形到图集
|
||||
void cacheGlyph(char32_t codepoint);
|
||||
// 更新图集纹理区域
|
||||
void updateAtlas(int x, int y, int width, int height,
|
||||
const std::vector<uint8_t>& data);
|
||||
};
|
||||
|
||||
} // namespace extra2d
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <extra2d/core/color.h>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/texture/texture.h>
|
||||
#include <mutex>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/texture/font.h>
|
||||
|
||||
#include <stb/stb_rect_pack.h>
|
||||
#include <stb/stb_truetype.h>
|
||||
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
// OpenGL 字体图集实现 (使用 STB 库)
|
||||
// 使用 stb_rect_pack 进行动态矩形打包,支持动态缓存字形
|
||||
// ============================================================================
|
||||
class GLFontAtlas : public FontAtlas {
|
||||
public:
|
||||
GLFontAtlas(const std::string &filepath, int fontSize, bool useSDF = false);
|
||||
~GLFontAtlas() override;
|
||||
|
||||
// FontAtlas 接口实现
|
||||
const Glyph *getGlyph(char32_t codepoint) const override;
|
||||
Texture *getTexture() const override { return texture_.get(); }
|
||||
int getFontSize() const override { return fontSize_; }
|
||||
float getAscent() const override { return ascent_; }
|
||||
float getDescent() const override { return descent_; }
|
||||
float getLineGap() const override { return lineGap_; }
|
||||
float getLineHeight() const override { return lineHeight_; }
|
||||
bool isSDF() const override { return useSDF_; }
|
||||
Vec2 measureText(const std::string &text) override;
|
||||
|
||||
private:
|
||||
// 字形数据内部结构
|
||||
struct GlyphData {
|
||||
float width;
|
||||
float height;
|
||||
float bearingX;
|
||||
float bearingY;
|
||||
float advance;
|
||||
float u0, v0, u1, v1;
|
||||
};
|
||||
|
||||
// 图集配置 - 增大尺寸以支持更多字符
|
||||
static constexpr int ATLAS_WIDTH = 1024;
|
||||
static constexpr int ATLAS_HEIGHT = 1024;
|
||||
static constexpr int PADDING = 2; // 字形之间的间距
|
||||
|
||||
bool useSDF_;
|
||||
int fontSize_;
|
||||
|
||||
Ptr<GLTexture> texture_;
|
||||
std::unordered_map<char32_t, GlyphData> glyphs_;
|
||||
float lineHeight_;
|
||||
float ascent_;
|
||||
float descent_;
|
||||
float lineGap_;
|
||||
|
||||
// 字体数据
|
||||
std::vector<unsigned char> fontData_;
|
||||
stbtt_fontinfo fontInfo_;
|
||||
float scale_;
|
||||
|
||||
// stb_rect_pack 上下文 - 持久化以支持增量打包
|
||||
mutable stbrp_context packContext_;
|
||||
mutable std::vector<stbrp_node> packNodes_;
|
||||
|
||||
// 预分配缓冲区,避免每次动态分配
|
||||
mutable std::vector<uint8_t> glyphBitmapCache_;
|
||||
mutable std::vector<uint8_t> glyphRgbaCache_;
|
||||
|
||||
// 初始化字体
|
||||
bool initFont(const std::string &filepath);
|
||||
// 创建空白图集纹理
|
||||
void createAtlas();
|
||||
// 缓存字形到图集
|
||||
void cacheGlyph(char32_t codepoint);
|
||||
// 更新图集纹理区域
|
||||
void updateAtlas(int x, int y, int width, int height,
|
||||
const std::vector<uint8_t> &data);
|
||||
};
|
||||
|
||||
} // namespace extra2d
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/graphics/backends/opengl/gl_buffer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_framebuffer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_pipeline.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_sprite_batch.h>
|
||||
#include <extra2d/graphics/core/render_backend.h>
|
||||
#include <extra2d/graphics/opengl/gl_buffer.h>
|
||||
#include <extra2d/graphics/opengl/gl_framebuffer.h>
|
||||
#include <extra2d/graphics/opengl/gl_pipeline.h>
|
||||
#include <extra2d/graphics/opengl/gl_sprite_batch.h>
|
||||
#include <extra2d/graphics/shader/shader_interface.h>
|
||||
|
||||
|
||||
#include <array>
|
||||
#include <glad/glad.h>
|
||||
#include <vector>
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/graphics/backends/opengl/gl_buffer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/batch/sprite_batch.h>
|
||||
#include <extra2d/graphics/opengl/gl_buffer.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/shader/shader_interface.h>
|
||||
#include <extra2d/graphics/shader/shader_manager.h>
|
||||
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -48,7 +49,9 @@ public:
|
|||
Ptr<IShader> getShader() const { return shader_; }
|
||||
|
||||
// 设置额外的uniform值(用于SDF字体等特殊渲染)
|
||||
void setExtraUniforms(const UniformValueMap &uniforms) { extraUniforms_ = uniforms; }
|
||||
void setExtraUniforms(const UniformValueMap &uniforms) {
|
||||
extraUniforms_ = uniforms;
|
||||
}
|
||||
void clearExtraUniforms() { extraUniforms_.clear(); }
|
||||
|
||||
private:
|
||||
|
|
@ -3,12 +3,13 @@
|
|||
#include <extra2d/core/color.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/texture/texture.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -117,7 +118,9 @@ public:
|
|||
Vec2 getOriginalSize(const std::string &name) const;
|
||||
|
||||
// 获取所有图集页面
|
||||
const std::vector<std::unique_ptr<TextureAtlasPage>>& getPages() const { return pages_; }
|
||||
const std::vector<std::unique_ptr<TextureAtlasPage>> &getPages() const {
|
||||
return pages_;
|
||||
}
|
||||
|
||||
// 获取总使用率
|
||||
float getTotalUsageRatio() const;
|
||||
|
|
@ -159,9 +162,7 @@ public:
|
|||
return atlas_.addTexture(name, width, height, pixels);
|
||||
}
|
||||
|
||||
bool contains(const std::string& name) const {
|
||||
return atlas_.contains(name);
|
||||
}
|
||||
bool contains(const std::string &name) const { return atlas_.contains(name); }
|
||||
|
||||
const Texture *getAtlasTexture(const std::string &name) const {
|
||||
return atlas_.getAtlasTexture(name);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include <extra2d/app/application.h>
|
||||
#include <extra2d/core/registry.h>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_renderer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_shader.h>
|
||||
#include <extra2d/graphics/core/render_module.h>
|
||||
#include <extra2d/graphics/opengl/gl_renderer.h>
|
||||
#include <extra2d/graphics/opengl/gl_shader.h>
|
||||
#include <extra2d/graphics/shader/shader_manager.h>
|
||||
#include <extra2d/platform/window_module.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/core/render_target.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
#include <cstring>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_buffer.h>
|
||||
#include <extra2d/graphics/memory/vram_manager.h>
|
||||
#include <extra2d/graphics/opengl/gl_buffer.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
|
|
@ -42,9 +40,8 @@ bool GLBuffer::init(const BufferDesc &desc) {
|
|||
// 追踪显存使用
|
||||
VRAMMgr::get().allocBuffer(size_);
|
||||
|
||||
E2D_LOG_DEBUG("GLBuffer 已创建: ID={}, 大小={}, 类型={}, 用途={}",
|
||||
bufferID_, size_, static_cast<int>(type_),
|
||||
static_cast<int>(usage_));
|
||||
E2D_LOG_DEBUG("GLBuffer 已创建: ID={}, 大小={}, 类型={}, 用途={}", bufferID_,
|
||||
size_, static_cast<int>(type_), static_cast<int>(usage_));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_context.h>
|
||||
#include <extra2d/graphics/memory/gpu_context.h>
|
||||
#include <extra2d/graphics/opengl/gl_context.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_font_atlas.h>
|
||||
#include <extra2d/graphics/opengl/gl_font_atlas.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_framebuffer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/opengl/gl_framebuffer.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
|
|
@ -37,8 +35,8 @@ bool GLFramebuffer::init(const FramebufferDesc &desc) {
|
|||
return false;
|
||||
}
|
||||
|
||||
E2D_LOG_DEBUG("GLFramebuffer 已创建: ID={}, 大小={}x{}, 颜色附件={}",
|
||||
fboID_, width_, height_, numColorAttachments_);
|
||||
E2D_LOG_DEBUG("GLFramebuffer 已创建: ID={}, 大小={}x{}, 颜色附件={}", fboID_,
|
||||
width_, height_, numColorAttachments_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -237,8 +235,7 @@ bool GLFramebuffer::checkStatus() {
|
|||
E2D_LOG_ERROR("帧缓冲区不完整: GL_FRAMEBUFFER_UNDEFINED");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
E2D_LOG_ERROR(
|
||||
"帧缓冲区不完整: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
|
||||
E2D_LOG_ERROR("帧缓冲区不完整: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
E2D_LOG_ERROR(
|
||||
|
|
@ -246,12 +243,10 @@ bool GLFramebuffer::checkStatus() {
|
|||
break;
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
E2D_LOG_ERROR(
|
||||
"帧缓冲区不完整: GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER");
|
||||
E2D_LOG_ERROR("帧缓冲区不完整: GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
E2D_LOG_ERROR(
|
||||
"帧缓冲区不完整: GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER");
|
||||
E2D_LOG_ERROR("帧缓冲区不完整: GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER");
|
||||
break;
|
||||
#endif
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_pipeline.h>
|
||||
#include <extra2d/graphics/opengl/gl_pipeline.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_context.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_font_atlas.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_framebuffer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_renderer.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/batch/sprite_batch.h>
|
||||
#include <extra2d/graphics/memory/gpu_context.h>
|
||||
#include <extra2d/graphics/memory/vram_manager.h>
|
||||
#include <extra2d/graphics/opengl/gl_context.h>
|
||||
#include <extra2d/graphics/opengl/gl_font_atlas.h>
|
||||
#include <extra2d/graphics/opengl/gl_framebuffer.h>
|
||||
#include <extra2d/graphics/opengl/gl_renderer.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/shader/shader_manager.h>
|
||||
#include <extra2d/platform/iwindow.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// VBO 初始大小(用于 VRAM 跟踪)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_shader.h>
|
||||
#include <extra2d/graphics/opengl/gl_shader.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_sprite_batch.h>
|
||||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/opengl/gl_sprite_batch.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/shader/shader_manager.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
|
@ -93,7 +92,8 @@ void GLSpriteBatch::begin(const glm::mat4 &viewProjection) {
|
|||
ebo_.bind();
|
||||
}
|
||||
|
||||
void GLSpriteBatch::begin(const glm::mat4 &viewProjection, Ptr<IShader> shader) {
|
||||
void GLSpriteBatch::begin(const glm::mat4 &viewProjection,
|
||||
Ptr<IShader> shader) {
|
||||
// 设置自定义着色器
|
||||
if (shader) {
|
||||
shader_ = shader;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <extra2d/graphics/backends/opengl/gl_texture.h>
|
||||
#include <extra2d/graphics/memory/gpu_context.h>
|
||||
#include <extra2d/graphics/memory/vram_manager.h>
|
||||
#include <extra2d/graphics/opengl/gl_texture.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <cstring>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
|
|
@ -8,7 +9,6 @@
|
|||
#include <fstream>
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
|
|
@ -351,8 +351,8 @@ bool GLTexture::loadKTX(const std::string &filepath) {
|
|||
dataSize_ = imageSize;
|
||||
VRAMMgr::get().allocTexture(dataSize_);
|
||||
|
||||
E2D_LOG_INFO("已加载 KTX 压缩纹理: {} ({}x{}, 格式={:#06x})",
|
||||
filepath, width_, height_, glInternalFormat);
|
||||
E2D_LOG_INFO("已加载 KTX 压缩纹理: {} ({}x{}, 格式={:#06x})", filepath,
|
||||
width_, height_, glInternalFormat);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -412,8 +412,7 @@ bool GLTexture::loadDDS(const std::string &filepath) {
|
|||
return false;
|
||||
}
|
||||
} else {
|
||||
E2D_LOG_ERROR("DDS 文件未使用 DX10 扩展,不支持: {}",
|
||||
filepath);
|
||||
E2D_LOG_ERROR("DDS 文件未使用 DX10 扩展,不支持: {}", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -455,8 +454,7 @@ bool GLTexture::loadDDS(const std::string &filepath) {
|
|||
dataSize_ = imageSize;
|
||||
VRAMMgr::get().allocTexture(dataSize_);
|
||||
|
||||
E2D_LOG_INFO("已加载 DDS 压缩纹理: {} ({}x{})", filepath, width_,
|
||||
height_);
|
||||
E2D_LOG_INFO("已加载 DDS 压缩纹理: {} ({}x{})", filepath, width_, height_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "glfw_input.h"
|
||||
#include <cmath>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
#include <glfw/glfw_input.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "glfw_window.h"
|
||||
#include "glfw_input.h"
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <glfw/glfw_input.h>
|
||||
#include <glfw/glfw_window.h>
|
||||
|
||||
#include <extra2d/event/event.h>
|
||||
#include <extra2d/platform/keys.h>
|
||||
#include <extra2d/services/event_service.h>
|
||||
|
|
@ -488,79 +488,225 @@ void GLFWWindow::keyCallback(GLFWwindow *window, int key, int scancode,
|
|||
// 将 GLFW key code 转换为引擎 Key 枚举值
|
||||
Key eKey = Key::None;
|
||||
switch (key) {
|
||||
case GLFW_KEY_A: eKey = Key::A; break;
|
||||
case GLFW_KEY_B: eKey = Key::B; break;
|
||||
case GLFW_KEY_C: eKey = Key::C; break;
|
||||
case GLFW_KEY_D: eKey = Key::D; break;
|
||||
case GLFW_KEY_E: eKey = Key::E; break;
|
||||
case GLFW_KEY_F: eKey = Key::F; break;
|
||||
case GLFW_KEY_G: eKey = Key::G; break;
|
||||
case GLFW_KEY_H: eKey = Key::H; break;
|
||||
case GLFW_KEY_I: eKey = Key::I; break;
|
||||
case GLFW_KEY_J: eKey = Key::J; break;
|
||||
case GLFW_KEY_K: eKey = Key::K; break;
|
||||
case GLFW_KEY_L: eKey = Key::L; break;
|
||||
case GLFW_KEY_M: eKey = Key::M; break;
|
||||
case GLFW_KEY_N: eKey = Key::N; break;
|
||||
case GLFW_KEY_O: eKey = Key::O; break;
|
||||
case GLFW_KEY_P: eKey = Key::P; break;
|
||||
case GLFW_KEY_Q: eKey = Key::Q; break;
|
||||
case GLFW_KEY_R: eKey = Key::R; break;
|
||||
case GLFW_KEY_S: eKey = Key::S; break;
|
||||
case GLFW_KEY_T: eKey = Key::T; break;
|
||||
case GLFW_KEY_U: eKey = Key::U; break;
|
||||
case GLFW_KEY_V: eKey = Key::V; break;
|
||||
case GLFW_KEY_W: eKey = Key::W; break;
|
||||
case GLFW_KEY_X: eKey = Key::X; break;
|
||||
case GLFW_KEY_Y: eKey = Key::Y; break;
|
||||
case GLFW_KEY_Z: eKey = Key::Z; break;
|
||||
case GLFW_KEY_0: eKey = Key::Num0; break;
|
||||
case GLFW_KEY_1: eKey = Key::Num1; break;
|
||||
case GLFW_KEY_2: eKey = Key::Num2; break;
|
||||
case GLFW_KEY_3: eKey = Key::Num3; break;
|
||||
case GLFW_KEY_4: eKey = Key::Num4; break;
|
||||
case GLFW_KEY_5: eKey = Key::Num5; break;
|
||||
case GLFW_KEY_6: eKey = Key::Num6; break;
|
||||
case GLFW_KEY_7: eKey = Key::Num7; break;
|
||||
case GLFW_KEY_8: eKey = Key::Num8; break;
|
||||
case GLFW_KEY_9: eKey = Key::Num9; break;
|
||||
case GLFW_KEY_F1: eKey = Key::F1; break;
|
||||
case GLFW_KEY_F2: eKey = Key::F2; break;
|
||||
case GLFW_KEY_F3: eKey = Key::F3; break;
|
||||
case GLFW_KEY_F4: eKey = Key::F4; break;
|
||||
case GLFW_KEY_F5: eKey = Key::F5; break;
|
||||
case GLFW_KEY_F6: eKey = Key::F6; break;
|
||||
case GLFW_KEY_F7: eKey = Key::F7; break;
|
||||
case GLFW_KEY_F8: eKey = Key::F8; break;
|
||||
case GLFW_KEY_F9: eKey = Key::F9; break;
|
||||
case GLFW_KEY_F10: eKey = Key::F10; break;
|
||||
case GLFW_KEY_F11: eKey = Key::F11; break;
|
||||
case GLFW_KEY_F12: eKey = Key::F12; break;
|
||||
case GLFW_KEY_SPACE: eKey = Key::Space; break;
|
||||
case GLFW_KEY_ENTER: eKey = Key::Enter; break;
|
||||
case GLFW_KEY_ESCAPE: eKey = Key::Escape; break;
|
||||
case GLFW_KEY_TAB: eKey = Key::Tab; break;
|
||||
case GLFW_KEY_BACKSPACE: eKey = Key::Backspace; break;
|
||||
case GLFW_KEY_INSERT: eKey = Key::Insert; break;
|
||||
case GLFW_KEY_DELETE: eKey = Key::Delete; break;
|
||||
case GLFW_KEY_HOME: eKey = Key::Home; break;
|
||||
case GLFW_KEY_END: eKey = Key::End; break;
|
||||
case GLFW_KEY_PAGE_UP: eKey = Key::PageUp; break;
|
||||
case GLFW_KEY_PAGE_DOWN: eKey = Key::PageDown; break;
|
||||
case GLFW_KEY_UP: eKey = Key::Up; break;
|
||||
case GLFW_KEY_DOWN: eKey = Key::Down; break;
|
||||
case GLFW_KEY_LEFT: eKey = Key::Left; break;
|
||||
case GLFW_KEY_RIGHT: eKey = Key::Right; break;
|
||||
case GLFW_KEY_LEFT_SHIFT: eKey = Key::LShift; break;
|
||||
case GLFW_KEY_RIGHT_SHIFT: eKey = Key::RShift; break;
|
||||
case GLFW_KEY_LEFT_CONTROL: eKey = Key::LCtrl; break;
|
||||
case GLFW_KEY_RIGHT_CONTROL: eKey = Key::RCtrl; break;
|
||||
case GLFW_KEY_LEFT_ALT: eKey = Key::LAlt; break;
|
||||
case GLFW_KEY_RIGHT_ALT: eKey = Key::RAlt; break;
|
||||
case GLFW_KEY_CAPS_LOCK: eKey = Key::CapsLock; break;
|
||||
case GLFW_KEY_NUM_LOCK: eKey = Key::NumLock; break;
|
||||
case GLFW_KEY_SCROLL_LOCK: eKey = Key::ScrollLock; break;
|
||||
default: eKey = Key::None; break;
|
||||
case GLFW_KEY_A:
|
||||
eKey = Key::A;
|
||||
break;
|
||||
case GLFW_KEY_B:
|
||||
eKey = Key::B;
|
||||
break;
|
||||
case GLFW_KEY_C:
|
||||
eKey = Key::C;
|
||||
break;
|
||||
case GLFW_KEY_D:
|
||||
eKey = Key::D;
|
||||
break;
|
||||
case GLFW_KEY_E:
|
||||
eKey = Key::E;
|
||||
break;
|
||||
case GLFW_KEY_F:
|
||||
eKey = Key::F;
|
||||
break;
|
||||
case GLFW_KEY_G:
|
||||
eKey = Key::G;
|
||||
break;
|
||||
case GLFW_KEY_H:
|
||||
eKey = Key::H;
|
||||
break;
|
||||
case GLFW_KEY_I:
|
||||
eKey = Key::I;
|
||||
break;
|
||||
case GLFW_KEY_J:
|
||||
eKey = Key::J;
|
||||
break;
|
||||
case GLFW_KEY_K:
|
||||
eKey = Key::K;
|
||||
break;
|
||||
case GLFW_KEY_L:
|
||||
eKey = Key::L;
|
||||
break;
|
||||
case GLFW_KEY_M:
|
||||
eKey = Key::M;
|
||||
break;
|
||||
case GLFW_KEY_N:
|
||||
eKey = Key::N;
|
||||
break;
|
||||
case GLFW_KEY_O:
|
||||
eKey = Key::O;
|
||||
break;
|
||||
case GLFW_KEY_P:
|
||||
eKey = Key::P;
|
||||
break;
|
||||
case GLFW_KEY_Q:
|
||||
eKey = Key::Q;
|
||||
break;
|
||||
case GLFW_KEY_R:
|
||||
eKey = Key::R;
|
||||
break;
|
||||
case GLFW_KEY_S:
|
||||
eKey = Key::S;
|
||||
break;
|
||||
case GLFW_KEY_T:
|
||||
eKey = Key::T;
|
||||
break;
|
||||
case GLFW_KEY_U:
|
||||
eKey = Key::U;
|
||||
break;
|
||||
case GLFW_KEY_V:
|
||||
eKey = Key::V;
|
||||
break;
|
||||
case GLFW_KEY_W:
|
||||
eKey = Key::W;
|
||||
break;
|
||||
case GLFW_KEY_X:
|
||||
eKey = Key::X;
|
||||
break;
|
||||
case GLFW_KEY_Y:
|
||||
eKey = Key::Y;
|
||||
break;
|
||||
case GLFW_KEY_Z:
|
||||
eKey = Key::Z;
|
||||
break;
|
||||
case GLFW_KEY_0:
|
||||
eKey = Key::Num0;
|
||||
break;
|
||||
case GLFW_KEY_1:
|
||||
eKey = Key::Num1;
|
||||
break;
|
||||
case GLFW_KEY_2:
|
||||
eKey = Key::Num2;
|
||||
break;
|
||||
case GLFW_KEY_3:
|
||||
eKey = Key::Num3;
|
||||
break;
|
||||
case GLFW_KEY_4:
|
||||
eKey = Key::Num4;
|
||||
break;
|
||||
case GLFW_KEY_5:
|
||||
eKey = Key::Num5;
|
||||
break;
|
||||
case GLFW_KEY_6:
|
||||
eKey = Key::Num6;
|
||||
break;
|
||||
case GLFW_KEY_7:
|
||||
eKey = Key::Num7;
|
||||
break;
|
||||
case GLFW_KEY_8:
|
||||
eKey = Key::Num8;
|
||||
break;
|
||||
case GLFW_KEY_9:
|
||||
eKey = Key::Num9;
|
||||
break;
|
||||
case GLFW_KEY_F1:
|
||||
eKey = Key::F1;
|
||||
break;
|
||||
case GLFW_KEY_F2:
|
||||
eKey = Key::F2;
|
||||
break;
|
||||
case GLFW_KEY_F3:
|
||||
eKey = Key::F3;
|
||||
break;
|
||||
case GLFW_KEY_F4:
|
||||
eKey = Key::F4;
|
||||
break;
|
||||
case GLFW_KEY_F5:
|
||||
eKey = Key::F5;
|
||||
break;
|
||||
case GLFW_KEY_F6:
|
||||
eKey = Key::F6;
|
||||
break;
|
||||
case GLFW_KEY_F7:
|
||||
eKey = Key::F7;
|
||||
break;
|
||||
case GLFW_KEY_F8:
|
||||
eKey = Key::F8;
|
||||
break;
|
||||
case GLFW_KEY_F9:
|
||||
eKey = Key::F9;
|
||||
break;
|
||||
case GLFW_KEY_F10:
|
||||
eKey = Key::F10;
|
||||
break;
|
||||
case GLFW_KEY_F11:
|
||||
eKey = Key::F11;
|
||||
break;
|
||||
case GLFW_KEY_F12:
|
||||
eKey = Key::F12;
|
||||
break;
|
||||
case GLFW_KEY_SPACE:
|
||||
eKey = Key::Space;
|
||||
break;
|
||||
case GLFW_KEY_ENTER:
|
||||
eKey = Key::Enter;
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE:
|
||||
eKey = Key::Escape;
|
||||
break;
|
||||
case GLFW_KEY_TAB:
|
||||
eKey = Key::Tab;
|
||||
break;
|
||||
case GLFW_KEY_BACKSPACE:
|
||||
eKey = Key::Backspace;
|
||||
break;
|
||||
case GLFW_KEY_INSERT:
|
||||
eKey = Key::Insert;
|
||||
break;
|
||||
case GLFW_KEY_DELETE:
|
||||
eKey = Key::Delete;
|
||||
break;
|
||||
case GLFW_KEY_HOME:
|
||||
eKey = Key::Home;
|
||||
break;
|
||||
case GLFW_KEY_END:
|
||||
eKey = Key::End;
|
||||
break;
|
||||
case GLFW_KEY_PAGE_UP:
|
||||
eKey = Key::PageUp;
|
||||
break;
|
||||
case GLFW_KEY_PAGE_DOWN:
|
||||
eKey = Key::PageDown;
|
||||
break;
|
||||
case GLFW_KEY_UP:
|
||||
eKey = Key::Up;
|
||||
break;
|
||||
case GLFW_KEY_DOWN:
|
||||
eKey = Key::Down;
|
||||
break;
|
||||
case GLFW_KEY_LEFT:
|
||||
eKey = Key::Left;
|
||||
break;
|
||||
case GLFW_KEY_RIGHT:
|
||||
eKey = Key::Right;
|
||||
break;
|
||||
case GLFW_KEY_LEFT_SHIFT:
|
||||
eKey = Key::LShift;
|
||||
break;
|
||||
case GLFW_KEY_RIGHT_SHIFT:
|
||||
eKey = Key::RShift;
|
||||
break;
|
||||
case GLFW_KEY_LEFT_CONTROL:
|
||||
eKey = Key::LCtrl;
|
||||
break;
|
||||
case GLFW_KEY_RIGHT_CONTROL:
|
||||
eKey = Key::RCtrl;
|
||||
break;
|
||||
case GLFW_KEY_LEFT_ALT:
|
||||
eKey = Key::LAlt;
|
||||
break;
|
||||
case GLFW_KEY_RIGHT_ALT:
|
||||
eKey = Key::RAlt;
|
||||
break;
|
||||
case GLFW_KEY_CAPS_LOCK:
|
||||
eKey = Key::CapsLock;
|
||||
break;
|
||||
case GLFW_KEY_NUM_LOCK:
|
||||
eKey = Key::NumLock;
|
||||
break;
|
||||
case GLFW_KEY_SCROLL_LOCK:
|
||||
eKey = Key::ScrollLock;
|
||||
break;
|
||||
default:
|
||||
eKey = Key::None;
|
||||
break;
|
||||
}
|
||||
|
||||
if (eKey != Key::None) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include <extra2d/platform/input_module.h>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/core/registry.h>
|
||||
#include <extra2d/services/event_service.h>
|
||||
#include <extra2d/platform/input_module.h>
|
||||
#include <extra2d/platform/window_module.h>
|
||||
#include <extra2d/services/event_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -17,7 +17,8 @@ InputModule::~InputModule() {
|
|||
}
|
||||
|
||||
bool InputModule::init() {
|
||||
if (initialized_) return true;
|
||||
if (initialized_)
|
||||
return true;
|
||||
|
||||
// 获取WindowModule依赖
|
||||
auto *winMod = Registry::instance().get<WindowModule>();
|
||||
|
|
@ -36,7 +37,8 @@ bool InputModule::init() {
|
|||
}
|
||||
|
||||
void InputModule::shutdown() {
|
||||
if (!initialized_) return;
|
||||
if (!initialized_)
|
||||
return;
|
||||
|
||||
input_ = nullptr;
|
||||
initialized_ = false;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <extra2d/platform/window_module.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
#include "backends/glfw/glfw_window.h"
|
||||
#include <glfw/glfw_window.h>
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#include <switch.h>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/core/render_command.h>
|
||||
#include <extra2d/scene/node.h>
|
||||
#include <extra2d/scene/scene.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/core/render_backend.h>
|
||||
#include <extra2d/graphics/core/render_command.h>
|
||||
#include <extra2d/scene/scene.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include <algorithm>
|
||||
#include <extra2d/app/application.h>
|
||||
#include <extra2d/core/service_locator.h>
|
||||
#include <extra2d/graphics/core/render_backend.h>
|
||||
#include <extra2d/graphics/core/render_command.h>
|
||||
#include <extra2d/platform/iinput.h>
|
||||
|
|
@ -13,7 +12,6 @@
|
|||
#include <extra2d/scene/transition_slide_scene.h>
|
||||
#include <extra2d/services/logger_service.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
namespace {
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ function define_extra2d_engine()
|
|||
set_kind("static")
|
||||
|
||||
-- 引擎核心源文件(后端无关)
|
||||
add_files("Extra2D/src/**.cpp|platform/backends/**.cpp|graphics/backends/**.cpp")
|
||||
add_files("Extra2D/src/**.cpp|platform/backends/**.cpp|graphics/opengl/**.cpp")
|
||||
|
||||
-- OpenGL 渲染后端源文件
|
||||
add_files("Extra2D/src/graphics/backends/opengl/*.cpp")
|
||||
add_files("Extra2D/src/graphics/opengl/*.cpp")
|
||||
add_files("Extra2D/src/glad/glad.c")
|
||||
|
||||
-- GLFW 窗口后端源文件
|
||||
add_files("Extra2D/src/platform/backends/glfw/*.cpp")
|
||||
add_files("Extra2D/src/platform/glfw/*.cpp")
|
||||
|
||||
-- 头文件路径
|
||||
add_includedirs("Extra2D/include", {public = true})
|
||||
|
|
|
|||
Loading…
Reference in New Issue