Red GL4.5 screen.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <xenia/gpu/gl4/gl4_gpu.h>
|
||||
|
||||
//#include <xenia/gpu/gl4/gl4_graphics_system.h>
|
||||
#include <xenia/gpu/gl4/gl4_graphics_system.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
@@ -32,12 +32,6 @@ void InitializeIfNeeded() {
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
class GL4GraphicsSystem : public GraphicsSystem {
|
||||
public:
|
||||
GL4GraphicsSystem(Emulator* emulator) : GraphicsSystem(emulator) {}
|
||||
~GL4GraphicsSystem() override = default;
|
||||
};
|
||||
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator) {
|
||||
InitializeIfNeeded();
|
||||
return std::make_unique<GL4GraphicsSystem>(emulator);
|
||||
|
||||
36
src/xenia/gpu/gl4/gl4_graphics_system.cc
Normal file
36
src/xenia/gpu/gl4/gl4_graphics_system.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/gpu/gl4/gl4_graphics_system.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
GL4GraphicsSystem::GL4GraphicsSystem(Emulator* emulator)
|
||||
: GraphicsSystem(emulator) {}
|
||||
|
||||
GL4GraphicsSystem::~GL4GraphicsSystem() = default;
|
||||
|
||||
X_STATUS GL4GraphicsSystem::Setup() {
|
||||
auto loop = emulator_->main_window()->loop();
|
||||
loop->Post([this]() {
|
||||
control_ = std::make_unique<WGLControl>();
|
||||
emulator_->main_window()->AddChild(control_.get());
|
||||
});
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void GL4GraphicsSystem::Shutdown() {
|
||||
control_.reset();
|
||||
}
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
39
src/xenia/gpu/gl4/gl4_graphics_system.h
Normal file
39
src/xenia/gpu/gl4/gl4_graphics_system.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_GPU_GL4_GL4_GRAPHICS_SYSTEM_H_
|
||||
#define XENIA_GPU_GL4_GL4_GRAPHICS_SYSTEM_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/gpu/gl4/wgl_control.h>
|
||||
#include <xenia/gpu/graphics_system.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
class GL4GraphicsSystem : public GraphicsSystem {
|
||||
public:
|
||||
GL4GraphicsSystem(Emulator* emulator);
|
||||
~GL4GraphicsSystem() override;
|
||||
|
||||
X_STATUS Setup() override;
|
||||
void Shutdown() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<WGLControl> control_;
|
||||
};
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_GPU_GL4_GL4_GRAPHICS_SYSTEM_H_
|
||||
119
src/xenia/gpu/gl4/gl_context.cc
Normal file
119
src/xenia/gpu/gl4/gl_context.cc
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/gpu/gl4/gl_context.h>
|
||||
|
||||
#include <poly/logging.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
thread_local GLEWContext* tls_glew_context_ = nullptr;
|
||||
thread_local WGLEWContext* tls_wglew_context_ = nullptr;
|
||||
extern "C" GLEWContext* glewGetContext() { return tls_glew_context_; }
|
||||
extern "C" WGLEWContext* wglewGetContext() { return tls_wglew_context_; }
|
||||
|
||||
GLContext::GLContext() : dc_(nullptr), glrc_(nullptr) {}
|
||||
|
||||
GLContext::~GLContext() {
|
||||
wglMakeCurrent(nullptr, nullptr);
|
||||
if (glrc_) {
|
||||
wglDeleteContext(glrc_);
|
||||
}
|
||||
}
|
||||
|
||||
bool GLContext::Initialize(HDC dc) {
|
||||
dc_ = dc;
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd = {0};
|
||||
pfd.nSize = sizeof(pfd);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cDepthBits = 32;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
int pixel_format = ChoosePixelFormat(dc_, &pfd);
|
||||
if (!pixel_format) {
|
||||
PLOGE("Unable to choose pixel format");
|
||||
return false;
|
||||
}
|
||||
if (!SetPixelFormat(dc_, pixel_format, &pfd)) {
|
||||
PLOGE("Unable to set pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
HGLRC temp_context = wglCreateContext(dc_);
|
||||
if (!temp_context) {
|
||||
PLOGE("Unable to create temporary GL context");
|
||||
return false;
|
||||
}
|
||||
wglMakeCurrent(dc_, temp_context);
|
||||
|
||||
tls_glew_context_ = &glew_context_;
|
||||
tls_wglew_context_ = &wglew_context_;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
PLOGE("Unable to initialize GLEW");
|
||||
return false;
|
||||
}
|
||||
if (wglewInit() != GLEW_OK) {
|
||||
PLOGE("Unable to initialize WGLEW");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WGLEW_ARB_create_context) {
|
||||
PLOGE("WGL_ARG_create_context not supported by GL ICD");
|
||||
return false;
|
||||
}
|
||||
|
||||
int context_flags = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
||||
#if DEBUG
|
||||
context_flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
|
||||
#endif // DEBUG
|
||||
|
||||
int attrib_list[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 4, //
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, 5, //
|
||||
WGL_CONTEXT_FLAGS_ARB, context_flags, //
|
||||
0};
|
||||
|
||||
glrc_ = wglCreateContextAttribsARB(dc_, nullptr, attrib_list);
|
||||
wglMakeCurrent(nullptr, nullptr);
|
||||
wglDeleteContext(temp_context);
|
||||
if (!glrc_) {
|
||||
PLOGE("Unable to create real GL context");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MakeCurrent()) {
|
||||
PLOGE("Could not make real GL context current");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GLContext::MakeCurrent() {
|
||||
if (!wglMakeCurrent(dc_, glrc_)) {
|
||||
return false;
|
||||
}
|
||||
tls_glew_context_ = &glew_context_;
|
||||
tls_wglew_context_ = &wglew_context_;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLContext::ClearCurrent() {
|
||||
wglMakeCurrent(nullptr, nullptr);
|
||||
tls_glew_context_ = nullptr;
|
||||
tls_wglew_context_ = nullptr;
|
||||
}
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
44
src/xenia/gpu/gl4/gl_context.h
Normal file
44
src/xenia/gpu/gl4/gl_context.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_GPU_GL4_GL_CONTEXT_H_
|
||||
#define XENIA_GPU_GL4_GL_CONTEXT_H_
|
||||
|
||||
#include <third_party/GL/glew.h>
|
||||
#include <third_party/GL/wglew.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
class GLContext {
|
||||
public:
|
||||
GLContext();
|
||||
~GLContext();
|
||||
|
||||
bool Initialize(HDC dc);
|
||||
|
||||
HDC dc() const { return dc_; }
|
||||
|
||||
bool MakeCurrent();
|
||||
void ClearCurrent();
|
||||
|
||||
private:
|
||||
HDC dc_;
|
||||
HGLRC glrc_;
|
||||
|
||||
GLEWContext glew_context_;
|
||||
WGLEWContext wglew_context_;
|
||||
};
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_GPU_GL4_GL_CONTEXT_H_
|
||||
@@ -4,5 +4,18 @@
|
||||
'gl4_gpu-private.h',
|
||||
'gl4_gpu.cc',
|
||||
'gl4_gpu.h',
|
||||
'gl4_graphics_system.cc',
|
||||
'gl4_graphics_system.h',
|
||||
'gl_context.cc',
|
||||
'gl_context.h',
|
||||
],
|
||||
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
'sources': [
|
||||
'wgl_control.cc',
|
||||
'wgl_control.h',
|
||||
],
|
||||
}],
|
||||
],
|
||||
}
|
||||
|
||||
91
src/xenia/gpu/gl4/wgl_control.cc
Normal file
91
src/xenia/gpu/gl4/wgl_control.cc
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/gpu/gl4/wgl_control.h>
|
||||
|
||||
#include <poly/logging.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
WGLControl::WGLControl()
|
||||
: poly::ui::win32::Win32Control(Flags::kFlagOwnPaint) {}
|
||||
|
||||
WGLControl::~WGLControl() = default;
|
||||
|
||||
bool WGLControl::Create() {
|
||||
HINSTANCE hInstance = GetModuleHandle(nullptr);
|
||||
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
wcex.lpfnWndProc = Win32Control::WndProcThunk;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = nullptr;
|
||||
wcex.hIconSm = nullptr;
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
wcex.lpszMenuName = nullptr;
|
||||
wcex.lpszClassName = L"XeniaWglClass";
|
||||
if (!RegisterClassEx(&wcex)) {
|
||||
PLOGE("WGL RegisterClassEx failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create window.
|
||||
DWORD window_style = WS_CHILD | WS_VISIBLE;
|
||||
DWORD window_ex_style = 0;
|
||||
hwnd_ =
|
||||
CreateWindowEx(window_ex_style, L"XeniaWglClass", L"Xenia", window_style,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
parent_hwnd(), nullptr, hInstance, this);
|
||||
if (!hwnd_) {
|
||||
PLOGE("WGL CreateWindow failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
HDC dc = GetDC(hwnd_);
|
||||
if (!dc) {
|
||||
PLOGE("No DC for WGL window");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!context_.Initialize(dc)) {
|
||||
PFATAL("Unable to initialize GL context");
|
||||
return false;
|
||||
}
|
||||
|
||||
OnCreate();
|
||||
return true;
|
||||
}
|
||||
|
||||
void WGLControl::OnLayout(poly::ui::UIEvent& e) {
|
||||
Control::ResizeToFill();
|
||||
}
|
||||
|
||||
LRESULT WGLControl::WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
switch (message) {
|
||||
case WM_PAINT:
|
||||
context_.MakeCurrent();
|
||||
glViewport(0, 0, width_, height_);
|
||||
glClearColor(1.0f, 0, 0, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
SwapBuffers(context_.dc());
|
||||
return 0;
|
||||
}
|
||||
return Win32Control::WndProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
43
src/xenia/gpu/gl4/wgl_control.h
Normal file
43
src/xenia/gpu/gl4/wgl_control.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_GPU_GL4_WGL_CONTROL_H_
|
||||
#define XENIA_GPU_GL4_WGL_CONTROL_H_
|
||||
|
||||
#include <poly/ui/win32/win32_control.h>
|
||||
#include <xenia/gpu/gl4/gl_context.h>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
class WGLControl : public poly::ui::win32::Win32Control {
|
||||
public:
|
||||
WGLControl();
|
||||
~WGLControl() override;
|
||||
|
||||
GLContext* context() { return &context_; }
|
||||
|
||||
protected:
|
||||
bool Create() override;
|
||||
|
||||
void OnLayout(poly::ui::UIEvent& e) override;
|
||||
|
||||
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
||||
LPARAM lParam) override;
|
||||
|
||||
private:
|
||||
GLContext context_;
|
||||
};
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_GPU_GL4_WGL_CONTROL_H_
|
||||
Reference in New Issue
Block a user