xb style.

This commit is contained in:
Ben Vanik
2015-08-07 07:56:57 -07:00
parent 5e08889d93
commit 14beb27ebc
63 changed files with 338 additions and 331 deletions

View File

@@ -12,6 +12,7 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>
namespace xe {

View File

@@ -35,48 +35,46 @@ Blitter::~Blitter() = default;
bool Blitter::Initialize() {
const std::string header =
"\n\
#version 450 \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\
";
R"(
#version 450
#extension GL_ARB_explicit_uniform_location : require
#extension GL_ARB_shading_language_420pack : require
precision highp float;
precision highp int;
layout(std140, column_major) uniform;
layout(std430, column_major) buffer;
)";
const std::string vs_source = header +
"\n\
layout(location = 0) uniform vec4 src_uv; \n\
out gl_PerVertex { \n\
vec4 gl_Position; \n\
float gl_PointSize; \n\
float gl_ClipDistance[]; \n\
}; \n\
layout(location = 0) in vec2 vfetch_pos; \n\
layout(location = 0) out vec2 vtx_uv; \n\
void main() { \n\
gl_Position = vec4(vfetch_pos.xy * vec2(2.0, -2.0) - vec2(1.0, -1.0), 0.0, 1.0); \n\
vtx_uv = vfetch_pos.xy * src_uv.zw + src_uv.xy; \n\
} \n\
";
R"(
layout(location = 0) uniform vec4 src_uv;
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
};
layout(location = 0) in vec2 vfetch_pos;
layout(location = 0) out vec2 vtx_uv;
void main() {
gl_Position = vec4(vfetch_pos.xy * vec2(2.0, -2.0) -
vec2(1.0, -1.0), 0.0, 1.0);
vtx_uv = vfetch_pos.xy * src_uv.zw + src_uv.xy;
})";
const std::string color_fs_source = header +
"\n\
layout(location = 1) uniform sampler2D src_texture; \n\
layout(location = 0) in vec2 vtx_uv; \n\
layout(location = 0) out vec4 oC; \n\
void main() { \n\
oC = texture(src_texture, vtx_uv); \n\
} \n\
";
R"(
layout(location = 1) uniform sampler2D src_texture;
layout(location = 0) in vec2 vtx_uv;
layout(location = 0) out vec4 oC;
void main() {
oC = texture(src_texture, vtx_uv);
})";
const std::string depth_fs_source = header +
"\n\
layout(location = 1) uniform sampler2D src_texture; \n\
layout(location = 0) in vec2 vtx_uv; \n\
layout(location = 0) out vec4 oC; \n\
void main() { \n\
gl_FragDepth = texture(src_texture, vtx_uv).r; \n\
} \n\
";
R"(
layout(location = 1) uniform sampler2D src_texture;
layout(location = 0) in vec2 vtx_uv;
layout(location = 0) out vec4 oC;
void main() {
gl_FragDepth = texture(src_texture, vtx_uv).r;
})";
auto vs_source_str = vs_source.c_str();
vertex_program_ = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &vs_source_str);
@@ -165,7 +163,8 @@ struct SavedState {
glGetIntegerv(GL_CULL_FACE_MODE, &cull_face);
glGetIntegerv(GL_FRONT_FACE, &front_face);
glGetIntegerv(GL_POLYGON_MODE, &polygon_mode);
glGetBooleani_v(GL_COLOR_WRITEMASK, 0, (GLboolean*)&color_mask_0_enabled);
glGetBooleani_v(GL_COLOR_WRITEMASK, 0,
reinterpret_cast<GLboolean*>(&color_mask_0_enabled));
blend_0_enabled = glIsEnabledi(GL_BLEND, 0);
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_buffer);
glGetFloati_v(GL_VIEWPORT, 0, viewport);
@@ -230,10 +229,11 @@ void Blitter::Draw(GLuint src_texture, Rect2D src_rect, Rect2D dest_rect,
GLint src_texture_height;
glGetTextureLevelParameteriv(src_texture, 0, GL_TEXTURE_HEIGHT,
&src_texture_height);
glProgramUniform4f(vertex_program_, 0, src_rect.x / float(src_texture_width),
src_rect.y / float(src_texture_height),
src_rect.width / float(src_texture_width),
src_rect.height / float(src_texture_height));
glProgramUniform4f(vertex_program_, 0,
src_rect.x / static_cast<float>(src_texture_width),
src_rect.y / static_cast<float>(src_texture_height),
src_rect.width / static_cast<float>(src_texture_width),
src_rect.height / static_cast<float>(src_texture_height));
// Useful for seeing the entire framebuffer/etc:
// glProgramUniform4f(vertex_program_, 0, 0.0f, 0.0f, 1.0f, 1.0f);

View File

@@ -9,6 +9,8 @@
#include "xenia/ui/gl/circular_buffer.h"
#include <algorithm>
#include "xenia/base/assert.h"
#include "xenia/base/math.h"

View File

@@ -10,6 +10,7 @@
#include "xenia/ui/gl/gl4_elemental_renderer.h"
#include <memory>
#include <string>
#include "el/graphics/bitmap_fragment.h"
#include "el/util/math.h"
@@ -93,45 +94,43 @@ bool GL4ElementalRenderer::Initialize() {
}
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\
";
R"(
#version 450
#extension GL_ARB_bindless_texture : require
#extension GL_ARB_explicit_uniform_location : require
#extension GL_ARB_shading_language_420pack : require
precision highp float;
precision highp int;
layout(std140, column_major) uniform;
layout(std430, column_major) buffer;
)";
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\
";
R"(
layout(location = 0) uniform mat4 projection_matrix;
layout(location = 0) in vec2 in_pos;
layout(location = 1) in vec4 in_color;
layout(location = 2) in vec2 in_uv;
layout(location = 0) out vec4 vtx_color;
layout(location = 1) out vec2 vtx_uv;
void main() {
gl_Position = projection_matrix * vec4(in_pos.xy, 0.0, 1.0);
vtx_color = in_color;
vtx_uv = in_uv;
})";
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\
";
R"(
layout(location = 1, bindless_sampler) uniform sampler2D texture_sampler;
layout(location = 2) uniform float texture_mix;
layout(location = 0) in vec4 vtx_color;
layout(location = 1) in vec2 vtx_uv;
layout(location = 0) out vec4 oC;
void main() {
oC = vtx_color;
if (texture_mix > 0.0) {
vec4 color = texture(texture_sampler, vtx_uv);
oC *= color.rgba;
}
})";
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
const char* vertex_shader_source_ptr = vertex_shader_source.c_str();
@@ -204,8 +203,8 @@ void GL4ElementalRenderer::BeginPaint(int render_target_w,
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 right = static_cast<float>(render_target_w);
float bottom = static_cast<float>(render_target_h);
float top = 0.0f;
float z_near = -1.0f;
float z_far = 1.0f;

View File

@@ -23,7 +23,7 @@ namespace gl {
class GL4ElementalRenderer : public el::graphics::Renderer {
public:
GL4ElementalRenderer(GLContext* context);
explicit GL4ElementalRenderer(GLContext* context);
~GL4ElementalRenderer() override;
static std::unique_ptr<GL4ElementalRenderer> Create(GLContext* context);

View File

@@ -449,7 +449,8 @@ void GLContext::BeginSwap() {
SCOPE_profile_cpu_i("gpu", "xe::ui::gl::GLContext::BeginSwap");
float clear_color[] = {238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.0f};
if (FLAGS_random_clear_color) {
clear_color[0] = rand() / (float)RAND_MAX;
clear_color[0] =
rand() / static_cast<float>(RAND_MAX); // NOLINT(runtime/threadsafe_fn)
clear_color[1] = 1.0f;
clear_color[2] = 0.0f;
clear_color[3] = 1.0f;

View File

@@ -49,7 +49,7 @@ class GLContext : public GraphicsContext {
Blitter* blitter() { return &blitter_; }
private:
GLContext(Window* target_window);
explicit GLContext(Window* target_window);
GLContext(Window* target_window, HGLRC glrc);
bool Initialize(Window* target_window);

View File

@@ -9,6 +9,9 @@
#include "xenia/ui/gl/gl_profiler_display.h"
#include <algorithm>
#include <string>
#include "third_party/microprofile/microprofileui.h"
#include "xenia/base/assert.h"
@@ -255,50 +258,48 @@ bool GLProfilerDisplay::SetupState() {
bool GLProfilerDisplay::SetupShaders() {
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\
";
R"(
#version 450
#extension GL_ARB_bindless_texture : require
#extension GL_ARB_explicit_uniform_location : require
#extension GL_ARB_shading_language_420pack : require
precision highp float;
precision highp int;
layout(std140, column_major) uniform;
layout(std430, column_major) buffer;
)";
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\
";
R"(
layout(location = 0) uniform mat4 projection_matrix;
layout(location = 0) in vec2 in_pos;
layout(location = 1) in vec4 in_color;
layout(location = 2) in vec2 in_uv;
layout(location = 0) out vec4 vtx_color;
layout(location = 1) out vec2 vtx_uv;
void main() {
gl_Position = projection_matrix * vec4(in_pos.xy, 0.0, 1.0);
vtx_color = in_color;
vtx_uv = in_uv;
})";
const std::string fragment_shader_source = header +
"\n\
layout(location = 1, bindless_sampler) uniform sampler2D font_texture; \n\
layout(location = 2) uniform float font_height; \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\
if (vtx_uv.x > 1.0) { \n\
oC = vtx_color; \n\
} else { \n\
vec4 color = texture(font_texture, vtx_uv); \n\
oC = color.rgba * vtx_color; \n\
if (color.a < 0.5) { \n\
vec4 c1 = texture(font_texture, vtx_uv + vec2(0.0, font_height)); \n\
oC = vec4(0, 0, 0, c1.a); \n\
} \n\
} \n\
} \n\
";
R"(
layout(location = 1, bindless_sampler) uniform sampler2D font_texture;
layout(location = 2) uniform float font_height;
layout(location = 0) in vec4 vtx_color;
layout(location = 1) in vec2 vtx_uv;
layout(location = 0) out vec4 oC;
void main() {
if (vtx_uv.x > 1.0) {
oC = vtx_color;
} else {
vec4 color = texture(font_texture, vtx_uv);
oC = color.rgba * vtx_color;
if (color.a < 0.5) {
vec4 c1 = texture(font_texture, vtx_uv + vec2(0.0, font_height));
oC = vec4(0, 0, 0, c1.a);
}
}
})";
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
const char* vertex_shader_source_ptr = vertex_shader_source.c_str();
@@ -365,8 +366,8 @@ void GLProfilerDisplay::Begin() {
glViewport(0, 0, width(), height());
float left = 0.0f;
float right = float(width());
float bottom = float(height());
float right = static_cast<float>(width());
float bottom = static_cast<float>(height());
float top = 0.0f;
float z_near = -1.0f;
float z_far = 1.0f;
@@ -441,23 +442,23 @@ void GLProfilerDisplay::DrawBox(int x0, int y0, int x1, int y1, uint32_t color,
if (type == BoxType::kFlat) {
color =
((color & 0xff) << 16) | ((color >> 16) & 0xff) | (0xff00ff00 & color);
Q0(v, x, (float)x0);
Q0(v, y, (float)y0);
Q0(v, x, x0);
Q0(v, y, y0);
Q0(v, color, color);
Q0(v, u, 2.0f);
Q0(v, v, 2.0f);
Q1(v, x, (float)x1);
Q1(v, y, (float)y0);
Q1(v, x, x1);
Q1(v, y, y0);
Q1(v, color, color);
Q1(v, u, 2.0f);
Q1(v, v, 2.0f);
Q2(v, x, (float)x1);
Q2(v, y, (float)y1);
Q2(v, x, x1);
Q2(v, y, y1);
Q2(v, color, color);
Q2(v, u, 2.0f);
Q2(v, v, 2.0f);
Q3(v, x, (float)x0);
Q3(v, y, (float)y1);
Q3(v, x, x0);
Q3(v, y, y1);
Q3(v, color, color);
Q3(v, u, 2.0f);
Q3(v, v, 2.0f);
@@ -477,23 +478,23 @@ void GLProfilerDisplay::DrawBox(int x0, int y0, int x1, int y1, uint32_t color,
uint32_t b1 = 0xff & ((b + nMin) / 2);
uint32_t color0 = (r0 << 0) | (g0 << 8) | (b0 << 16) | (0xff000000 & color);
uint32_t color1 = (r1 << 0) | (g1 << 8) | (b1 << 16) | (0xff000000 & color);
Q0(v, x, (float)x0);
Q0(v, y, (float)y0);
Q0(v, x, x0);
Q0(v, y, y0);
Q0(v, color, color0);
Q0(v, u, 2.0f);
Q0(v, v, 2.0f);
Q1(v, x, (float)x1);
Q1(v, y, (float)y0);
Q1(v, x, x1);
Q1(v, y, y0);
Q1(v, color, color0);
Q1(v, u, 3.0f);
Q1(v, v, 2.0f);
Q2(v, x, (float)x1);
Q2(v, y, (float)y1);
Q2(v, x, x1);
Q2(v, y, y1);
Q2(v, color, color1);
Q2(v, u, 3.0f);
Q2(v, v, 3.0f);
Q3(v, x, (float)x0);
Q3(v, y, (float)y1);
Q3(v, x, x0);
Q3(v, y, y1);
Q3(v, color, color1);
Q3(v, u, 2.0f);
Q3(v, v, 3.0f);
@@ -532,8 +533,8 @@ void GLProfilerDisplay::DrawText(int x, int y, uint32_t color, const char* text,
}
const float fOffsetU = 5.0f / 1024.0f;
float fX = (float)x;
float fY = (float)y;
float fX = static_cast<float>(x);
float fY = static_cast<float>(y);
float fY2 = fY + (MICROPROFILE_TEXT_HEIGHT + 1);
auto v = BeginVertices(6 * text_length);
@@ -542,7 +543,7 @@ void GLProfilerDisplay::DrawText(int x, int y, uint32_t color, const char* text,
((color >> 16) & 0xff);
for (size_t j = 0; j < text_length; ++j) {
int16_t char_offset = font_description_.char_offsets[(int)*pStr++];
int16_t char_offset = font_description_.char_offsets[*pStr++];
float fOffset = char_offset / 1024.0f;
Q0(v, x, fX);
Q0(v, y, fY);

View File

@@ -20,7 +20,7 @@ namespace gl {
class GLProfilerDisplay : public ProfilerDisplay {
public:
GLProfilerDisplay(xe::ui::Window* window);
explicit GLProfilerDisplay(xe::ui::Window* window);
virtual ~GLProfilerDisplay();
uint32_t width() const override;

View File

@@ -43,7 +43,7 @@ class GraphicsContext {
};
struct GraphicsContextLock {
GraphicsContextLock(GraphicsContext* context) : context_(context) {
explicit GraphicsContextLock(GraphicsContext* context) : context_(context) {
context_->MakeCurrent();
}
~GraphicsContextLock() { context_->ClearCurrent(); }

View File

@@ -17,7 +17,7 @@ class Window;
class UIEvent {
public:
UIEvent(Window* target = nullptr) : target_(target) {}
explicit UIEvent(Window* target = nullptr) : target_(target) {}
virtual ~UIEvent() = default;
Window* target() const { return target_; }

View File

@@ -40,7 +40,7 @@ constexpr int32_t kMouseWheelDetent = 120;
class RootElement : public el::Element {
public:
RootElement(Window* owner) : owner_(owner) {}
explicit RootElement(Window* owner) : owner_(owner) {}
void OnInvalid() override { owner_->Invalidate(); }
private:
@@ -199,8 +199,9 @@ void Window::OnPaint(UIEvent& e) {
++fps_frame_count_;
uint64_t now_ns = xe::Clock::QueryHostSystemTime();
if (now_ns > fps_update_time_ + 1000 * 10000) {
fps_ = uint32_t(fps_frame_count_ /
(double(now_ns - fps_update_time_) / 10000000.0));
fps_ = static_cast<uint32_t>(
fps_frame_count_ /
(static_cast<double>(now_ns - fps_update_time_) / 10000000.0));
fps_update_time_ = now_ns;
fps_frame_count_ = 0;
}

View File

@@ -409,7 +409,7 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
TABLET_ENABLE_MULTITOUCHDATA;
case WM_MENUCOMMAND: {
// TODO: Redirect this to MenuItem's on_selected delegate.
// TODO(benvanik): Redirect this to MenuItem's on_selected delegate.
MENUINFO menu_info = {0};
menu_info.cbSize = sizeof(menu_info);
menu_info.fMask = MIM_MENUDATA;
@@ -503,7 +503,7 @@ bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
}
bool Win32Window::HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam) {
auto e = KeyEvent(this, (int)wParam);
auto e = KeyEvent(this, static_cast<int>(wParam));
switch (message) {
case WM_KEYDOWN:
OnKeyDown(e);