This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathvidext.cpp
More file actions
154 lines (134 loc) · 3.78 KB
/
vidext.cpp
File metadata and controls
154 lines (134 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "vidext.h"
#include "interface/common.h"
#include "workerthread.h"
#include "mainwindow.h"
#include "interface/core_commands.h"
#include <stdio.h>
#include <QScreen>
static int init;
static QThread *rendering_thread;
static QVulkanInstance vulkan_inst;
static QVulkanInfoVector<QVulkanExtension> extensions;
static QVector<const char *> extension_list;
m64p_error qtVidExtFuncInit(void)
{
init = 0;
rendering_thread = QThread::currentThread();
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncInitWithRenderMode(m64p_render_mode)
{
return qtVidExtFuncInit();
}
m64p_error qtVidExtFuncQuit(void)
{
init = 0;
w->getWorkerThread()->toggleFS(M64VIDEO_WINDOWED);
w->getWorkerThread()->deleteVkWindow();
if (vulkan_inst.isValid())
vulkan_inst.destroy();
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncListModes(m64p_2d_size *SizeArray, int *NumSizes)
{
QList<QScreen *> screens = QGuiApplication::screens();
QRect size = screens.first()->geometry();
SizeArray[0].uiWidth = size.width();
SizeArray[0].uiHeight = size.height();
*NumSizes = 1;
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncListRates(m64p_2d_size, int *, int *)
{
return M64ERR_UNSUPPORTED;
}
m64p_error qtVidExtFuncSetMode(int Width, int Height, int, int WindowMode, int)
{
if (WindowMode == M64VIDEO_FULLSCREEN)
w->getWorkerThread()->toggleFS(M64VIDEO_FULLSCREEN);
else
w->getWorkerThread()->resizeMainWindow(Width, Height);
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncSetModeWithRate(int, int, int, int, int, int)
{
return M64ERR_UNSUPPORTED;
}
m64p_function qtVidExtFuncGLGetProc(const char *)
{
return NULL;
}
m64p_error qtVidExtFuncGLSetAttr(m64p_GLattr, int)
{
return M64ERR_UNSUPPORTED;
}
m64p_error qtVidExtFuncGLGetAttr(m64p_GLattr, int *)
{
if (!init)
return M64ERR_NOT_INIT;
return M64ERR_UNSUPPORTED;
}
m64p_error qtVidExtFuncGLSwapBuf(void)
{
w->getWorkerThread()->addFrameCount();
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncSetCaption(const char *)
{
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncToggleFS(void)
{
if (QThread::currentThread() == rendering_thread)
w->getWorkerThread()->toggleFS(M64VIDEO_NONE);
else
w->toggleFS(M64VIDEO_NONE);
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncResizeWindow(int width, int height)
{
int response = M64VIDEO_NONE;
(*CoreDoCommand)(M64CMD_CORE_STATE_QUERY, M64CORE_VIDEO_MODE, &response);
if (response == M64VIDEO_WINDOWED)
{
int size = (width << 16) + height;
int current_size = 0;
(*CoreDoCommand)(M64CMD_CORE_STATE_QUERY, M64CORE_VIDEO_SIZE, ¤t_size);
if (current_size != size)
w->getWorkerThread()->resizeMainWindow(width, height);
}
return M64ERR_SUCCESS;
}
uint32_t qtVidExtFuncGLGetDefaultFramebuffer(void)
{
return 0;
}
m64p_error qtVidExtFuncGetVkSurface(void **surface, void *instance)
{
if (!vulkan_inst.vkInstance())
{
vulkan_inst.setVkInstance((VkInstance)instance);
vulkan_inst.create();
w->getWorkerThread()->createVkWindow(&vulkan_inst);
}
while (*surface == nullptr)
*surface = QVulkanInstance::surfaceForWindow(w->getVkWindow());
init = 1;
return M64ERR_SUCCESS;
}
m64p_error qtVidExtFuncGetVkInstExtensions(const char **ext[], uint32_t *ext_num)
{
extensions = vulkan_inst.supportedExtensions();
extension_list.clear();
for (int i = 0; i < extensions.size(); ++i)
{
QString ext_name = QString(extensions[i].name);
if (ext_name.startsWith("VK_KHR_") && ext_name.endsWith("surface"))
{
extension_list.append(extensions[i].name.data());
++*ext_num;
}
}
*ext = extension_list.data();
return M64ERR_SUCCESS;
}