修改create_texture接口,使其更易于使用。新增text sdf测试代码
This commit is contained in:
parent
e27f316774
commit
a522ba5961
@ -56,8 +56,8 @@ bool dx_renderer::render() {
|
||||
return true;
|
||||
}
|
||||
|
||||
renderer_texture* dx_renderer::create_texture(const Eigen::Vector2i& size, texture_format in_format) {
|
||||
return new dx_texture(size, in_format);
|
||||
renderer_texture* dx_renderer::create_texture(int in_size_width, int in_size_height, texture_format in_format) {
|
||||
return new dx_texture({ in_size_width, in_size_height }, in_format);
|
||||
}
|
||||
|
||||
Eigen::Matrix4f dx_renderer::make_projection_matrix(const Eigen::Vector2i& size) {
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
void destroy() override;
|
||||
bool render() override;
|
||||
|
||||
renderer_texture* create_texture(const Eigen::Vector2i& size, texture_format in_format) override;
|
||||
renderer_texture* create_texture(int in_size_width, int in_size_height, texture_format in_format) override;
|
||||
|
||||
[[nodiscard]] ID3D11Device* get_d3d_device() const { return device; }
|
||||
[[nodiscard]] ID3D11DeviceContext* get_d3d_context() const { return context; }
|
||||
|
@ -3,12 +3,35 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "dx_renderer.h"
|
||||
#include "core/pixel_format/pixel.h"
|
||||
#include "core/renderer/renderer_text.h"
|
||||
#include "core/renderer/renderer_texture.h"
|
||||
#include "misc/scope_exit.h"
|
||||
|
||||
using namespace aorii;
|
||||
|
||||
static float thickness = 1.f;
|
||||
renderer_texture* test_texture = nullptr;
|
||||
text_font* text = nullptr;
|
||||
int current_char = 33;
|
||||
void on_mouse_scroll(GLFWwindow* window, double xoffset, double yoffset) {
|
||||
current_char -= yoffset;
|
||||
current_char = std::clamp(current_char, 33, 126);
|
||||
const auto& character = text->glyphs[current_char];
|
||||
if (!character.buffer)
|
||||
return;
|
||||
const auto font_image = image_accessor<pixel_r8>(character.buffer, character.size);
|
||||
|
||||
delete test_texture;
|
||||
test_texture = get_renderer_raw()->create_texture(character.size, texture_format::R8_UNORM);
|
||||
|
||||
uint32_t row_pitch = 0;
|
||||
const auto data = test_texture->lock(&row_pitch);
|
||||
auto image = image_accessor<pixel_r8>(data, test_texture->size());
|
||||
image.set_row_pitch(row_pitch);
|
||||
image.copy_from(font_image);
|
||||
test_texture->unlock();
|
||||
}
|
||||
|
||||
bool dx_window::create_surface(GLFWwindow* in_window) {
|
||||
auto dx = aorii::get_renderer<dx_renderer>();
|
||||
const auto d3d_device = dx->get_d3d_device();
|
||||
@ -69,10 +92,11 @@ bool dx_window::create_surface(GLFWwindow* in_window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
test_texture = dx->load_image(R"(D:\69054578_p0.jpg)", texture_format::RGBA8_UNORM);
|
||||
glfwSetScrollCallback(get_glfw_window(), [](GLFWwindow* window, double xoffset, double yoffset) {
|
||||
thickness += yoffset;
|
||||
});
|
||||
// test_texture = dx->load_image(R"(D:\69054578_p0.jpg)", texture_format::RGBA8_UNORM);
|
||||
glfwSetScrollCallback(get_glfw_window(), on_mouse_scroll);
|
||||
text = aorii_text::load_font("C:/Windows/Fonts/simsunb.ttf", true, 48);
|
||||
on_mouse_scroll(nullptr, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -94,9 +118,9 @@ void dx_window::begin_frame() {
|
||||
double mouse_x, mouse_y;
|
||||
glfwGetCursorPos(get_glfw_window(), &mouse_x, &mouse_y);
|
||||
// auto height = sin(get_total_time().count()) * 100;
|
||||
context.draw_line( { 600, 600 }, { mouse_x, mouse_y }, { 1, 0, 1, 1 }, thickness);
|
||||
// context.draw_line( { 600, 600 }, { mouse_x, mouse_y }, { 1, 0, 1, 1 }, thickness);
|
||||
|
||||
// if (test_texture) context.draw_texture({ 0, 0 }, test_texture->size(), test_texture);
|
||||
if (test_texture) context.draw_texture({ 0.f, 0.f }, test_texture->size().cast<float>(), test_texture);
|
||||
|
||||
context.flush();
|
||||
|
||||
|
@ -14,11 +14,11 @@ protected:
|
||||
void on_resize(const Eigen::Vector2i& in_size) override;
|
||||
|
||||
HRESULT build_render_target_view();
|
||||
|
||||
private:
|
||||
renderer_context context;
|
||||
IDXGISwapChain1* swap_chain = nullptr;
|
||||
ID3D11RenderTargetView* render_target_view = nullptr;
|
||||
Eigen::Matrix4f projection_matrix;
|
||||
|
||||
renderer_texture* test_texture = nullptr;
|
||||
};
|
||||
|
@ -35,7 +35,7 @@ renderer_texture* renderer::load_image(const std::string& file_path, texture_for
|
||||
int target_channel_count = get_format_channel_count(in_format);
|
||||
unsigned int row_pitch = 0;
|
||||
|
||||
auto texture = create_texture({ width, height }, in_format);
|
||||
auto texture = create_texture(width, height, in_format);
|
||||
auto data = texture->lock(&row_pitch);
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
|
@ -218,7 +218,11 @@ public:
|
||||
virtual void tick();
|
||||
virtual bool render() = 0;
|
||||
|
||||
virtual renderer_texture* create_texture(const Eigen::Vector2i& size, texture_format in_format) = 0;
|
||||
template<typename T>
|
||||
renderer_texture* create_texture(const Eigen::Vector2<T>& in_size, texture_format in_format) {
|
||||
return create_texture(in_size.x(), in_size.y(), in_format);
|
||||
}
|
||||
virtual renderer_texture* create_texture(int in_size_width, int in_size_height, texture_format in_format) = 0;
|
||||
virtual void destroy_texture(renderer_texture* texture);
|
||||
|
||||
renderer_texture* load_image(const std::string& file_path, texture_format in_format);
|
||||
|
Loading…
x
Reference in New Issue
Block a user