CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/GEDebugger/SimpleGLWindow.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <functional>20#include "CommonWindows.h"2122#include "Common/GPU/OpenGL/GLSLProgram.h"23#include "Common/CommonWindows.h"24#include "Windows/W32Util/ContextMenu.h"2526struct SimpleGLWindow {27static const wchar_t *windowClass;2829enum Format {30FORMAT_565_REV = 0x00,31FORMAT_5551_REV = 0x01,32FORMAT_4444_REV = 0x02,33FORMAT_8888 = 0x03,34FORMAT_565 = 0x04,35FORMAT_5551 = 0x05,36FORMAT_4444 = 0x06,37FORMAT_5551_BGRA_REV = 0x09,38FORMAT_4444_BGRA_REV = 0x0A,39FORMAT_8888_BGRA = 0x0B,4041FORMAT_FLOAT = 0x10,42FORMAT_16BIT = 0x11,43FORMAT_8BIT = 0x12,44FORMAT_24BIT_8X = 0x13,45FORMAT_24X_8BIT = 0x14,4647FORMAT_FLOAT_DIV_256 = 0x18,48FORMAT_24BIT_8X_DIV_256 = 0x1B,49};5051enum Flags {52RESIZE_NONE = 0x00,53RESIZE_CENTER = 0x01,54RESIZE_SHRINK_FIT = 0x02,55RESIZE_SHRINK_CENTER = 0x03,56RESIZE_GROW_FIT = 0x04,57RESIZE_GROW_CENTER = 0x05,58RESIZE_BEST_FIT = 0x06,59RESIZE_BEST_CENTER = 0x07,6061ALPHA_IGNORE = 0x00,62ALPHA_BLEND = 0x08,63};6465SimpleGLWindow(HWND wnd);66~SimpleGLWindow();6768void Clear();69void Draw(const u8 *data, int w, int h, bool flipped = false, Format = FORMAT_8888);70void Redraw(bool andSwap = true);71void Initialize(u32 flags);72static SimpleGLWindow *GetFrom(HWND hwnd);73static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);7475// To draw something custom.76void Begin();77void End();7879void SetFlags(u32 flags) {80flags_ = flags;81}8283void Swap() {84swapped_ = true;85SwapBuffers(hDC_);86}8788int Width() {89return w_;90}9192int Height() {93return h_;94}9596bool HasTex() {97return tw_ > 0 && th_ > 0;98}99100int TexWidth() {101return tw_;102}103104int TexHeight() {105return th_;106}107108void GetContentSize(float &x, float &y, float &fw, float &fh);109110void SetRedrawCallback(std::function<void()> callback) {111redrawCallback_ = callback;112}113114void SetHoverCallback(std::function<void(int, int)> hoverCallback) {115hoverCallback_ = hoverCallback;116}117118// Called first with 0 that it's opening, then the selected item.119void SetRightClickMenu(ContextMenuID menu, std::function<void(int, int, int)> callback) {120rightClickCallback_ = callback;121rightClickMenu_ = menu;122}123124static void RegisterClass();125protected:126void SetupGL();127void ResizeGL(int w, int h);128void CreateProgram();129void GenerateChecker();130void DrawChecker();131bool DragStart(int mouseX, int mouseY);132bool DragContinue(int mouseX, int mouseY);133bool DragEnd(int mouseX, int mouseY);134bool Hover(int mouseX, int mouseY);135bool Leave();136bool RightClick(int mouseX, int mouseY);137bool ToggleZoom();138POINT PosFromMouse(int mouseX, int mouseY);139const u8 *Reformat(const u8 *data, Format fmt, u32 numPixels);140141HWND hWnd_;142HDC hDC_;143HGLRC hGLRC_;144bool valid_ = false;145// Width and height of the window.146int w_;147int h_;148// Last texture size/flipped for Redraw().149int tw_;150int th_;151bool tflipped_;152153GLSLProgram *drawProgram_ = nullptr;154GLuint vao_ = 0;155GLuint ibuf_ = 0;156GLuint vbuf_ = 0;157GLuint checker_ = 0;158GLuint tex_ = 0;159u32 flags_ = 0;160// Disable shrink (toggled by double click.)161bool zoom_ = false;162bool dragging_ = false;163bool inRedrawCallback_ = false;164bool swapped_ = false;165int dragStartX_;166int dragStartY_;167u32 dragLastUpdate_;168// Offset to position the texture is drawn at.169int offsetX_ = 0;170int offsetY_ = 0;171u32 *reformatBuf_ = nullptr;172u32 reformatBufSize_ = 0;173174std::function<void()> redrawCallback_;175std::function<void(int, int)> hoverCallback_;176std::function<void(int, int, int)> rightClickCallback_;177ContextMenuID rightClickMenu_;178};179180181