mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 12:39:13 +12:00
Moar HTTP
This commit is contained in:
parent
536e4566db
commit
ba1c3a8ec5
6 changed files with 47 additions and 40 deletions
|
@ -669,7 +669,7 @@ void Renderer::initGraphicsContext() {
|
|||
dummyVAO.create();
|
||||
|
||||
// Create texture and framebuffer for the 3DS screen
|
||||
const u32 screenTextureWidth = 2 * 400; // Top screen is 400 pixels wide, bottom is 320
|
||||
const u32 screenTextureWidth = 400; // Top screen is 400 pixels wide, bottom is 320
|
||||
const u32 screenTextureHeight = 2 * 240; // Both screens are 240 pixels tall
|
||||
|
||||
glGenTextures(1,&lightLUTTextureArray);
|
||||
|
@ -1028,4 +1028,29 @@ void Renderer::displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32
|
|||
}
|
||||
|
||||
OpenGL::draw(OpenGL::TriangleStrip, 4); // Actually draw our 3DS screen
|
||||
}
|
||||
|
||||
void Renderer::screenshot(const std::string& name) {
|
||||
constexpr uint width = 400;
|
||||
constexpr uint height = 2 * 240;
|
||||
|
||||
std::vector<uint8_t> pixels, flippedPixels;
|
||||
pixels.resize(width * height * 4);
|
||||
flippedPixels.resize(pixels.size());;
|
||||
|
||||
OpenGL::bindScreenFramebuffer();
|
||||
glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels.data());
|
||||
|
||||
// Flip the image vertically
|
||||
for (int y = 0; y < height; y++) {
|
||||
memcpy(&flippedPixels[y * width * 4], &pixels[(height - y - 1) * width * 4], width * 4);
|
||||
// Swap R and B channels
|
||||
for (int x = 0; x < width; x++) {
|
||||
std::swap(flippedPixels[y * width * 4 + x * 4 + 0], flippedPixels[y * width * 4 + x * 4 + 2]);
|
||||
// Set alpha to 0xFF
|
||||
flippedPixels[y * width * 4 + x * 4 + 3] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
stbi_write_png(name.c_str(), width, height, 4, flippedPixels.data(), 0);
|
||||
}
|
|
@ -82,27 +82,6 @@ void Emulator::reset() {
|
|||
}
|
||||
}
|
||||
|
||||
void Emulator::screenshot(const std::string& name) {
|
||||
std::vector<uint8_t> pixels, flippedPixels;
|
||||
pixels.resize(width * height * 4);
|
||||
flippedPixels.resize(width * height * 4);
|
||||
|
||||
glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels.data());
|
||||
|
||||
// Flip the image vertically
|
||||
for (int y = 0; y < height; y++) {
|
||||
memcpy(&flippedPixels[y * width * 4], &pixels[(height - y - 1) * width * 4], width * 4);
|
||||
// Swap R and B channels
|
||||
for (int x = 0; x < width; x++) {
|
||||
std::swap(flippedPixels[y * width * 4 + x * 4 + 0], flippedPixels[y * width * 4 + x * 4 + 2]);
|
||||
// Set alpha to 0xFF
|
||||
flippedPixels[y * width * 4 + x * 4 + 3] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
stbi_write_png(name.c_str(), width, height, 4, flippedPixels.data(), 0);
|
||||
}
|
||||
|
||||
void Emulator::step() {}
|
||||
void Emulator::render() {}
|
||||
|
||||
|
@ -428,28 +407,27 @@ void Emulator::pollHttpServer() {
|
|||
|
||||
if (httpServer.pendingAction) {
|
||||
switch (httpServer.action) {
|
||||
case HttpAction::Screenshot: {
|
||||
screenshot(HttpServer::httpServerScreenshotPath);
|
||||
case HttpAction::Screenshot:
|
||||
gpu.screenshot(HttpServer::httpServerScreenshotPath);
|
||||
break;
|
||||
}
|
||||
case HttpAction::PressKey: {
|
||||
|
||||
case HttpAction::PressKey:
|
||||
if (httpServer.pendingKey != 0) {
|
||||
srv.pressKey(httpServer.pendingKey);
|
||||
httpServer.pendingKey = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case HttpAction::ReleaseKey: {
|
||||
|
||||
case HttpAction::ReleaseKey:
|
||||
if (httpServer.pendingKey != 0) {
|
||||
srv.releaseKey(httpServer.pendingKey);
|
||||
httpServer.pendingKey = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case HttpAction::None: {
|
||||
break;
|
||||
}
|
||||
|
||||
case HttpAction::None: break;
|
||||
}
|
||||
|
||||
httpServer.action = HttpAction::None;
|
||||
httpServer.pendingAction = false;
|
||||
httpServer.pendingAction.notify_all();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||
#include "httpserver.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "httplib.h"
|
||||
#include "services/hid.hpp"
|
||||
|
@ -42,9 +42,7 @@ void HttpServer::startHttpServer() {
|
|||
std::thread http_thread([this]() {
|
||||
httplib::Server server;
|
||||
|
||||
server.Get("/ping", [](const httplib::Request&, httplib::Response& response) {
|
||||
response.set_content("pong", "text/plain");
|
||||
});
|
||||
server.Get("/ping", [](const httplib::Request&, httplib::Response& response) { response.set_content("pong", "text/plain"); });
|
||||
|
||||
server.Get("/screen", [this](const httplib::Request&, httplib::Response& response) {
|
||||
{
|
||||
|
@ -61,9 +59,10 @@ void HttpServer::startHttpServer() {
|
|||
|
||||
server.Get("/input", [this](const httplib::Request& request, httplib::Response& response) {
|
||||
bool ok = false;
|
||||
for (auto& [keyStr, value]: request.params) {
|
||||
for (auto& [keyStr, value] : request.params) {
|
||||
auto key = stringToKey(keyStr);
|
||||
printf("Param: %s\n", keyStr.c_str());
|
||||
|
||||
if (key != 0) {
|
||||
std::scoped_lock lock(actionMutex);
|
||||
pendingAction = true;
|
||||
|
@ -97,6 +96,7 @@ void HttpServer::startHttpServer() {
|
|||
printf("Starting HTTP server on port 1234\n");
|
||||
server.listen("localhost", 1234);
|
||||
});
|
||||
|
||||
http_thread.detach();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue