Switching to my turbo badger fork.

This commit is contained in:
Ben Vanik
2015-07-06 18:12:17 -07:00
parent f2ce11d268
commit 253a685dde
21 changed files with 882 additions and 1576 deletions

View File

@@ -9,6 +9,9 @@
#include "xenia/debug/ui/application.h"
#include "el/message_handler.h"
#include "el/util/metrics.h"
#include "el/util/timer.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/base/platform.h"
@@ -16,10 +19,6 @@
#include "xenia/debug/ui/main_window.h"
#include "xenia/profiling.h"
#include "third_party/turbobadger/src/tb/message_handler.h"
#include "third_party/turbobadger/src/tb/util/metrics.h"
#include "third_party/turbobadger/src/tb/util/timer.h"
namespace xe {
namespace debug {
namespace ui {
@@ -82,16 +81,16 @@ void Application::Quit() {
// This doesn't really belong here (it belongs in tb_system_[linux/windows].cpp.
// This is here since the proper implementations has not yet been done.
void tb::util::RescheduleTimer(uint64_t fire_time) {
if (fire_time == tb::MessageHandler::kNotSoon) {
void el::util::RescheduleTimer(uint64_t fire_time) {
if (fire_time == el::MessageHandler::kNotSoon) {
return;
}
uint64_t now = tb::util::GetTimeMS();
uint64_t now = el::util::GetTimeMS();
uint64_t delay_millis = fire_time >= now ? fire_time - now : 0;
xe::debug::ui::Application::current()->loop()->PostDelayed([]() {
uint64_t next_fire_time = tb::MessageHandler::GetNextMessageFireTime();
uint64_t now = tb::util::GetTimeMS();
uint64_t next_fire_time = el::MessageHandler::GetNextMessageFireTime();
uint64_t now = el::util::GetTimeMS();
if (now < next_fire_time) {
// We timed out *before* we were supposed to (the OS is not playing nice).
// Calling ProcessMessages now won't achieve a thing so force a reschedule
@@ -100,11 +99,11 @@ void tb::util::RescheduleTimer(uint64_t fire_time) {
return;
}
tb::MessageHandler::ProcessMessages();
el::MessageHandler::ProcessMessages();
// If we still have things to do (because we didn't process all messages,
// or because there are new messages), we need to rescedule, so call
// RescheduleTimer.
tb::util::RescheduleTimer(tb::MessageHandler::GetNextMessageFireTime());
el::util::RescheduleTimer(el::MessageHandler::GetNextMessageFireTime());
}, delay_millis);
}

View File

@@ -13,7 +13,9 @@
#include "xenia/base/logging.h"
#include "xenia/base/platform.h"
#include "xenia/base/threading.h"
#include "xenia/debug/ui/turbo_badger_control.h"
// TODO(benvanik): platform based.
#include "xenia/ui/gl/wgl_elemental_control.h"
namespace xe {
namespace debug {
@@ -89,7 +91,7 @@ bool MainWindow::Initialize() {
// Setup the GL control that actually does the drawing.
// We run here in the loop and only touch it (and its context) on this
// thread. That means some sync-fu when we want to swap.
control_ = std::make_unique<TurboBadgerControl>(loop());
control_ = std::make_unique<xe::ui::gl::WGLElementalControl>(loop());
AddChild(control_.get());
Resize(1440, 1200);

View File

@@ -13,6 +13,7 @@
#include <memory>
#include "xenia/debug/ui/application.h"
#include "xenia/ui/elemental_control.h"
#include "xenia/ui/platform.h"
#include "xenia/ui/window.h"
@@ -20,8 +21,6 @@ namespace xe {
namespace debug {
namespace ui {
class TurboBadgerControl;
class MainWindow : public xe::ui::PlatformWindow {
public:
MainWindow(Application* app);
@@ -37,7 +36,7 @@ class MainWindow : public xe::ui::PlatformWindow {
Application* app_ = nullptr;
xe::ui::PlatformMenu main_menu_;
std::unique_ptr<TurboBadgerControl> control_;
std::unique_ptr<xe::ui::ElementalControl> control_;
};
} // namespace ui

File diff suppressed because it is too large Load Diff

View File

@@ -1,82 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_DEBUG_UI_TURBO_BADGER_CONTROL_H_
#define XENIA_DEBUG_UI_TURBO_BADGER_CONTROL_H_
#include <memory>
#include "xenia/ui/gl/wgl_control.h"
#include "xenia/ui/loop.h"
#include "third_party/turbobadger/src/tb/element.h"
namespace xe {
namespace debug {
namespace ui {
class TurboBadgerControl : public xe::ui::gl::WGLControl {
public:
TurboBadgerControl(xe::ui::Loop* loop);
~TurboBadgerControl() override;
static bool InitializeTurboBadger(tb::graphics::Renderer* renderer);
static void ShutdownTurboBadger();
tb::graphics::Renderer* renderer() const { return renderer_.get(); }
tb::Element* root_element() const { return root_element_.get(); }
protected:
using super = xe::ui::gl::WGLControl;
bool Create() override;
void Destroy() override;
void OnLayout(xe::ui::UIEvent& e) override;
void OnPaint(xe::ui::UIEvent& e) override;
void OnGotFocus(xe::ui::UIEvent& e) override;
void OnLostFocus(xe::ui::UIEvent& e) override;
tb::ModifierKeys GetModifierKeys();
void OnKeyPress(xe::ui::KeyEvent& e, bool is_down);
bool CheckShortcutKey(xe::ui::KeyEvent& e, tb::SpecialKey special_key,
bool is_down);
void OnKeyDown(xe::ui::KeyEvent& e) override;
void OnKeyUp(xe::ui::KeyEvent& e) override;
void OnMouseDown(xe::ui::MouseEvent& e) override;
void OnMouseMove(xe::ui::MouseEvent& e) override;
void OnMouseUp(xe::ui::MouseEvent& e) override;
void OnMouseWheel(xe::ui::MouseEvent& e) override;
std::unique_ptr<tb::graphics::Renderer> renderer_;
std::unique_ptr<tb::Element> root_element_;
uint32_t frame_count_ = 0;
uint32_t fps_ = 0;
uint64_t fps_update_time_ = 0;
uint64_t fps_frame_count_ = 0;
bool modifier_shift_pressed_ = false;
bool modifier_cntrl_pressed_ = false;
bool modifier_alt_pressed_ = false;
bool modifier_super_pressed_ = false;
uint64_t last_click_time_ = 0;
int last_click_x_ = 0;
int last_click_y_ = 0;
int last_click_counter_ = 0;
};
} // namespace ui
} // namespace debug
} // namespace xe
#endif // XENIA_DEBUG_UI_TURBO_BADGER_CONTROL_H_

View File

@@ -1,305 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/debug/ui/turbo_badger_renderer.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "third_party/turbobadger/src/tb/graphics/bitmap_fragment.h"
#include "third_party/turbobadger/src/tb/util/math.h"
namespace xe {
namespace debug {
namespace ui {
using namespace tb;
class TBRendererGL4::TBBitmapGL4 : public tb::graphics::Bitmap {
public:
TBBitmapGL4(xe::ui::gl::GLContext* context, TBRendererGL4* renderer);
~TBBitmapGL4();
bool Init(int width, int height, uint32_t* data);
int Width() override { return width_; }
int Height() override { return height_; }
void SetData(uint32_t* data) override;
xe::ui::gl::GLContext* context_ = nullptr;
TBRendererGL4* renderer_ = nullptr;
int width_ = 0;
int height_ = 0;
GLuint handle_ = 0;
GLuint64 gpu_handle_ = 0;
};
TBRendererGL4::TBBitmapGL4::TBBitmapGL4(xe::ui::gl::GLContext* context,
TBRendererGL4* renderer)
: context_(context), renderer_(renderer) {}
TBRendererGL4::TBBitmapGL4::~TBBitmapGL4() {
xe::ui::gl::GLContextLock lock(context_);
// Must flush and unbind before we delete the texture.
renderer_->FlushBitmap(this);
glMakeTextureHandleNonResidentARB(gpu_handle_);
glDeleteTextures(1, &handle_);
}
bool TBRendererGL4::TBBitmapGL4::Init(int width, int height, uint32_t* data) {
assert(width == tb::util::GetNearestPowerOfTwo(width));
assert(height == tb::util::GetNearestPowerOfTwo(height));
width_ = width;
height_ = height;
glCreateTextures(GL_TEXTURE_2D, 1, &handle_);
glTextureParameteri(handle_, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(handle_, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTextureParameteri(handle_, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameteri(handle_, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTextureStorage2D(handle_, 1, GL_RGBA8, width_, height_);
gpu_handle_ = glGetTextureHandleARB(handle_);
glMakeTextureHandleResidentARB(gpu_handle_);
SetData(data);
return true;
}
void TBRendererGL4::TBBitmapGL4::SetData(uint32_t* data) {
renderer_->FlushBitmap(this);
glTextureSubImage2D(handle_, 0, 0, 0, width_, height_, GL_RGBA,
GL_UNSIGNED_BYTE, data);
}
TBRendererGL4::TBRendererGL4(xe::ui::gl::GLContext* context)
: context_(context),
vertex_buffer_(graphics::BatchingRenderer::kVertexBatchSize *
sizeof(Vertex)) {}
TBRendererGL4::~TBRendererGL4() {
xe::ui::gl::GLContextLock lock(context_);
vertex_buffer_.Shutdown();
glDeleteVertexArrays(1, &vao_);
glDeleteProgram(program_);
}
std::unique_ptr<TBRendererGL4> TBRendererGL4::Create(
xe::ui::gl::GLContext* context) {
auto renderer = std::make_unique<TBRendererGL4>(context);
if (!renderer->Initialize()) {
XELOGE("Failed to initialize TurboBadger GL4 renderer");
return nullptr;
}
return renderer;
}
bool TBRendererGL4::Initialize() {
if (!vertex_buffer_.Initialize()) {
XELOGE("Failed to initialize circular buffer");
return false;
}
const std::string header =
"\n\
#version 450 \n\
#extension GL_ARB_bindless_texture : require \n\
#extension GL_ARB_explicit_uniform_location : require \n\
#extension GL_ARB_shading_language_420pack : require \n\
precision highp float; \n\
precision highp int; \n\
layout(std140, column_major) uniform; \n\
layout(std430, column_major) buffer; \n\
";
const std::string vertex_shader_source = header +
"\n\
layout(location = 0) uniform mat4 projection_matrix; \n\
layout(location = 0) in vec2 in_pos; \n\
layout(location = 1) in vec4 in_color; \n\
layout(location = 2) in vec2 in_uv; \n\
layout(location = 0) out vec4 vtx_color; \n\
layout(location = 1) out vec2 vtx_uv; \n\
void main() { \n\
gl_Position = projection_matrix * vec4(in_pos.xy, 0.0, 1.0); \n\
vtx_color = in_color; \n\
vtx_uv = in_uv; \n\
} \n\
";
const std::string fragment_shader_source = header +
"\n\
layout(location = 1, bindless_sampler) uniform sampler2D texture_sampler; \n\
layout(location = 2) uniform float texture_mix; \n\
layout(location = 0) in vec4 vtx_color; \n\
layout(location = 1) in vec2 vtx_uv; \n\
layout(location = 0) out vec4 oC; \n\
void main() { \n\
oC = vtx_color; \n\
if (texture_mix > 0.0) { \n\
vec4 color = texture(texture_sampler, vtx_uv); \n\
oC *= color.rgba; \n\
} \n\
} \n\
";
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
const char* vertex_shader_source_ptr = vertex_shader_source.c_str();
GLint vertex_shader_source_length = GLint(vertex_shader_source.size());
glShaderSource(vertex_shader, 1, &vertex_shader_source_ptr,
&vertex_shader_source_length);
glCompileShader(vertex_shader);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
const char* fragment_shader_source_ptr = fragment_shader_source.c_str();
GLint fragment_shader_source_length = GLint(fragment_shader_source.size());
glShaderSource(fragment_shader, 1, &fragment_shader_source_ptr,
&fragment_shader_source_length);
glCompileShader(fragment_shader);
program_ = glCreateProgram();
glAttachShader(program_, vertex_shader);
glAttachShader(program_, fragment_shader);
glLinkProgram(program_);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
glCreateVertexArrays(1, &vao_);
glEnableVertexArrayAttrib(vao_, 0);
glVertexArrayAttribBinding(vao_, 0, 0);
glVertexArrayAttribFormat(vao_, 0, 2, GL_FLOAT, GL_FALSE,
offsetof(Vertex, x));
glEnableVertexArrayAttrib(vao_, 1);
glVertexArrayAttribBinding(vao_, 1, 0);
glVertexArrayAttribFormat(vao_, 1, 4, GL_UNSIGNED_BYTE, GL_TRUE,
offsetof(Vertex, col));
glEnableVertexArrayAttrib(vao_, 2);
glVertexArrayAttribBinding(vao_, 2, 0);
glVertexArrayAttribFormat(vao_, 2, 2, GL_FLOAT, GL_FALSE,
offsetof(Vertex, u));
glVertexArrayVertexBuffer(vao_, 0, vertex_buffer_.handle(), 0,
sizeof(Vertex));
return true;
}
graphics::Bitmap* TBRendererGL4::CreateBitmap(int width, int height,
uint32_t* data) {
auto bitmap = std::make_unique<TBBitmapGL4>(context_, this);
if (!bitmap->Init(width, height, data)) {
return nullptr;
}
return bitmap.release();
}
void TBRendererGL4::SetClipRect(const Rect& rect) {
Flush();
glScissor(clip_rect_.x, screen_rect_.h - (clip_rect_.y + clip_rect_.h),
clip_rect_.w, clip_rect_.h);
}
void TBRendererGL4::BeginPaint(int render_target_w, int render_target_h) {
tb::graphics::BatchingRenderer::BeginPaint(render_target_w, render_target_h);
glEnablei(GL_BLEND, 0);
glBlendFunci(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glEnable(GL_SCISSOR_TEST);
glViewport(0, 0, render_target_w, render_target_h);
glScissor(0, 0, render_target_w, render_target_h);
float left = 0.0f;
float right = float(render_target_w);
float bottom = float(render_target_h);
float top = 0.0f;
float z_near = -1.0f;
float z_far = 1.0f;
float projection[16] = {0};
projection[0] = 2.0f / (right - left);
projection[5] = 2.0f / (top - bottom);
projection[10] = -2.0f / (z_far - z_near);
projection[12] = -(right + left) / (right - left);
projection[13] = -(top + bottom) / (top - bottom);
projection[14] = -(z_far + z_near) / (z_far - z_near);
projection[15] = 1.0f;
glProgramUniformMatrix4fv(program_, 0, 1, GL_FALSE, projection);
current_bitmap_ = nullptr;
glUseProgram(program_);
glBindVertexArray(vao_);
}
void TBRendererGL4::EndPaint() {
tb::graphics::BatchingRenderer::EndPaint();
Flush();
glUseProgram(0);
glBindVertexArray(0);
}
void TBRendererGL4::Flush() {
if (!draw_command_count_) {
return;
}
vertex_buffer_.Flush();
for (size_t i = 0; i < draw_command_count_; ++i) {
glDrawArrays(draw_commands_[i].prim_type,
GLint(draw_commands_[i].vertex_offset),
GLsizei(draw_commands_[i].vertex_count));
}
draw_command_count_ = 0;
// TODO(benvanik): don't finish here.
vertex_buffer_.WaitUntilClean();
}
void TBRendererGL4::RenderBatch(Batch* batch) {
auto bitmap = static_cast<TBBitmapGL4*>(batch->bitmap);
if (bitmap != current_bitmap_) {
current_bitmap_ = bitmap;
Flush();
glProgramUniformHandleui64ARB(program_, 1,
bitmap ? bitmap->gpu_handle_ : 0);
glProgramUniform1f(program_, 2, bitmap ? 1.0f : 0.0f);
}
if (draw_command_count_ + 1 > kMaxCommands) {
Flush();
}
size_t total_length = sizeof(Vertex) * batch->vertex_count;
if (!vertex_buffer_.CanAcquire(total_length)) {
Flush();
}
auto allocation = vertex_buffer_.Acquire(total_length);
// TODO(benvanik): custom batcher that lets us use the ringbuffer memory
// without a copy.
std::memcpy(allocation.host_ptr, batch->vertex, total_length);
if (draw_command_count_ &&
draw_commands_[draw_command_count_ - 1].prim_type == GL_TRIANGLES) {
// Coalesce.
assert_always("haven't seen this yet");
auto& prev_command = draw_commands_[draw_command_count_ - 1];
prev_command.vertex_count += batch->vertex_count;
} else {
auto& command = draw_commands_[draw_command_count_++];
command.prim_type = GL_TRIANGLES;
command.vertex_offset = allocation.offset / sizeof(Vertex);
command.vertex_count = batch->vertex_count;
}
vertex_buffer_.Commit(std::move(allocation));
}
} // namespace ui
} // namespace debug
} // namespace xe

View File

@@ -1,68 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_DEBUG_UI_TURBO_BADGER_RENDERER_H_
#define XENIA_DEBUG_UI_TURBO_BADGER_RENDERER_H_
#include <cstddef>
#include <memory>
#include "xenia/ui/gl/circular_buffer.h"
#include "xenia/ui/gl/gl_context.h"
#include "xenia/ui/gl/gl.h"
#include "third_party/turbobadger/src/tb/graphics/batching_renderer.h"
namespace xe {
namespace debug {
namespace ui {
class TBRendererGL4 : public tb::graphics::BatchingRenderer {
public:
TBRendererGL4(xe::ui::gl::GLContext* context);
~TBRendererGL4() override;
static std::unique_ptr<TBRendererGL4> Create(xe::ui::gl::GLContext* context);
void BeginPaint(int render_target_w, int render_target_h) override;
void EndPaint() override;
tb::graphics::Bitmap* CreateBitmap(int width, int height,
uint32_t* data) override;
void RenderBatch(Batch* batch) override;
void SetClipRect(const tb::Rect& rect) override;
private:
class TBBitmapGL4;
bool Initialize();
void Flush();
xe::ui::gl::GLContext* context_ = nullptr;
GLuint program_ = 0;
GLuint vao_ = 0;
xe::ui::gl::CircularBuffer vertex_buffer_;
static const size_t kMaxCommands = 512;
struct {
GLenum prim_type;
size_t vertex_offset;
size_t vertex_count;
} draw_commands_[kMaxCommands] = {0};
uint32_t draw_command_count_ = 0;
TBBitmapGL4* current_bitmap_ = nullptr;
};
} // namespace ui
} // namespace debug
} // namespace xe
#endif // XENIA_DEBUG_UI_TURBO_BADGER_RENDERER_H_

View File

@@ -77,15 +77,11 @@
<ClInclude Include="..\..\base\main.h" />
<ClInclude Include="application.h" />
<ClInclude Include="main_window.h" />
<ClInclude Include="turbo_badger_control.h" />
<ClInclude Include="turbo_badger_renderer.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\base\main_win.cc" />
<ClCompile Include="application.cc" />
<ClCompile Include="main_window.cc" />
<ClCompile Include="turbo_badger_control.cc" />
<ClCompile Include="turbo_badger_renderer.cc" />
<ClCompile Include="xe-debug-ui.cc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -16,6 +16,9 @@
<Filter Include="src\xenia\base">
<UniqueIdentifier>{9a5724c2-5473-4d53-93b4-26531201f38d}</UniqueIdentifier>
</Filter>
<Filter Include="src\xenia\debug\ui\elements">
<UniqueIdentifier>{f0ac4999-4700-4b41-b73d-c6dc8b23c5e6}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\base\main.h">
@@ -27,12 +30,6 @@
<ClInclude Include="application.h">
<Filter>src\xenia\debug\ui</Filter>
</ClInclude>
<ClInclude Include="turbo_badger_control.h">
<Filter>src\xenia\debug\ui</Filter>
</ClInclude>
<ClInclude Include="turbo_badger_renderer.h">
<Filter>src\xenia\debug\ui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\base\main_win.cc">
@@ -47,11 +44,5 @@
<ClCompile Include="application.cc">
<Filter>src\xenia\debug\ui</Filter>
</ClCompile>
<ClCompile Include="turbo_badger_control.cc">
<Filter>src\xenia\debug\ui</Filter>
</ClCompile>
<ClCompile Include="turbo_badger_renderer.cc">
<Filter>src\xenia\debug\ui</Filter>
</ClCompile>
</ItemGroup>
</Project>