CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/GEDebugger/SimpleGLWindow.h
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <functional>
21
#include "CommonWindows.h"
22
23
#include "Common/GPU/OpenGL/GLSLProgram.h"
24
#include "Common/CommonWindows.h"
25
#include "Windows/W32Util/ContextMenu.h"
26
27
struct SimpleGLWindow {
28
static const wchar_t *windowClass;
29
30
enum Format {
31
FORMAT_565_REV = 0x00,
32
FORMAT_5551_REV = 0x01,
33
FORMAT_4444_REV = 0x02,
34
FORMAT_8888 = 0x03,
35
FORMAT_565 = 0x04,
36
FORMAT_5551 = 0x05,
37
FORMAT_4444 = 0x06,
38
FORMAT_5551_BGRA_REV = 0x09,
39
FORMAT_4444_BGRA_REV = 0x0A,
40
FORMAT_8888_BGRA = 0x0B,
41
42
FORMAT_FLOAT = 0x10,
43
FORMAT_16BIT = 0x11,
44
FORMAT_8BIT = 0x12,
45
FORMAT_24BIT_8X = 0x13,
46
FORMAT_24X_8BIT = 0x14,
47
48
FORMAT_FLOAT_DIV_256 = 0x18,
49
FORMAT_24BIT_8X_DIV_256 = 0x1B,
50
};
51
52
enum Flags {
53
RESIZE_NONE = 0x00,
54
RESIZE_CENTER = 0x01,
55
RESIZE_SHRINK_FIT = 0x02,
56
RESIZE_SHRINK_CENTER = 0x03,
57
RESIZE_GROW_FIT = 0x04,
58
RESIZE_GROW_CENTER = 0x05,
59
RESIZE_BEST_FIT = 0x06,
60
RESIZE_BEST_CENTER = 0x07,
61
62
ALPHA_IGNORE = 0x00,
63
ALPHA_BLEND = 0x08,
64
};
65
66
SimpleGLWindow(HWND wnd);
67
~SimpleGLWindow();
68
69
void Clear();
70
void Draw(const u8 *data, int w, int h, bool flipped = false, Format = FORMAT_8888);
71
void Redraw(bool andSwap = true);
72
void Initialize(u32 flags);
73
static SimpleGLWindow *GetFrom(HWND hwnd);
74
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
75
76
// To draw something custom.
77
void Begin();
78
void End();
79
80
void SetFlags(u32 flags) {
81
flags_ = flags;
82
}
83
84
void Swap() {
85
swapped_ = true;
86
SwapBuffers(hDC_);
87
}
88
89
int Width() {
90
return w_;
91
}
92
93
int Height() {
94
return h_;
95
}
96
97
bool HasTex() {
98
return tw_ > 0 && th_ > 0;
99
}
100
101
int TexWidth() {
102
return tw_;
103
}
104
105
int TexHeight() {
106
return th_;
107
}
108
109
void GetContentSize(float &x, float &y, float &fw, float &fh);
110
111
void SetRedrawCallback(std::function<void()> callback) {
112
redrawCallback_ = callback;
113
}
114
115
void SetHoverCallback(std::function<void(int, int)> hoverCallback) {
116
hoverCallback_ = hoverCallback;
117
}
118
119
// Called first with 0 that it's opening, then the selected item.
120
void SetRightClickMenu(ContextMenuID menu, std::function<void(int, int, int)> callback) {
121
rightClickCallback_ = callback;
122
rightClickMenu_ = menu;
123
}
124
125
static void RegisterClass();
126
protected:
127
void SetupGL();
128
void ResizeGL(int w, int h);
129
void CreateProgram();
130
void GenerateChecker();
131
void DrawChecker();
132
bool DragStart(int mouseX, int mouseY);
133
bool DragContinue(int mouseX, int mouseY);
134
bool DragEnd(int mouseX, int mouseY);
135
bool Hover(int mouseX, int mouseY);
136
bool Leave();
137
bool RightClick(int mouseX, int mouseY);
138
bool ToggleZoom();
139
POINT PosFromMouse(int mouseX, int mouseY);
140
const u8 *Reformat(const u8 *data, Format fmt, u32 numPixels);
141
142
HWND hWnd_;
143
HDC hDC_;
144
HGLRC hGLRC_;
145
bool valid_ = false;
146
// Width and height of the window.
147
int w_;
148
int h_;
149
// Last texture size/flipped for Redraw().
150
int tw_;
151
int th_;
152
bool tflipped_;
153
154
GLSLProgram *drawProgram_ = nullptr;
155
GLuint vao_ = 0;
156
GLuint ibuf_ = 0;
157
GLuint vbuf_ = 0;
158
GLuint checker_ = 0;
159
GLuint tex_ = 0;
160
u32 flags_ = 0;
161
// Disable shrink (toggled by double click.)
162
bool zoom_ = false;
163
bool dragging_ = false;
164
bool inRedrawCallback_ = false;
165
bool swapped_ = false;
166
int dragStartX_;
167
int dragStartY_;
168
u32 dragLastUpdate_;
169
// Offset to position the texture is drawn at.
170
int offsetX_ = 0;
171
int offsetY_ = 0;
172
u32 *reformatBuf_ = nullptr;
173
u32 reformatBufSize_ = 0;
174
175
std::function<void()> redrawCallback_;
176
std::function<void(int, int)> hoverCallback_;
177
std::function<void(int, int, int)> rightClickCallback_;
178
ContextMenuID rightClickMenu_;
179
};
180
181