Compare commits

...

6 Commits

Author SHA1 Message Date
Andy Vandijck
9ae1473f36 Fix 8 bit PNG recording
Fix 8 bit PNG recording
2025-08-02 11:27:21 +02:00
Andy Vandijck
9cd0c5c04c Fix 8 bit video recording
Fix 8 bit video recording
2025-08-02 11:10:00 +02:00
Andy Vandijck
9e41c5476a Fix 8 bit color
Fix 8 bit color
2025-08-02 10:20:05 +02:00
Andy Vandijck
e91171459d Fix policy in newer CMake 2025-08-02 09:49:22 +02:00
Andy Vandijck
16f008b448 Fix macOS build
Fix macOS build
2025-08-02 09:38:42 +02:00
Rafael Kitover
bad10342bd build: use pkg-config on UNIX for SDL3
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2025-08-02 06:20:37 +00:00
10 changed files with 53 additions and 87 deletions

View File

@@ -4,6 +4,7 @@ cmake_policy(VERSION 3.19...3.28.3)
# Use new link library de-duplication behavior.
cmake_policy(SET CMP0156 NEW)
cmake_policy(SET CMP0179 NEW)
# cmake_policy(SET CMP0181 NEW)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

View File

@@ -48,16 +48,20 @@ if((NOT ENABLE_SDL3) AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
endif()
if(ENABLE_SDL3)
if(VBAM_STATIC)
set(VBAM_SDL_LIBS SDL3::SDL3-static ${SDL_LIBRARY_TEMP})
if(UNIX AND NOT APPLE)
set(VBAM_SDL_LIBS "${SDL3_LIBRARIES}")
else()
set(VBAM_SDL_LIBS SDL3::SDL3 ${SDL_LIBRARY_TEMP})
if(VBAM_STATIC)
set(VBAM_SDL_LIBS SDL3::SDL3-static ${SDL_LIBRARY_TEMP})
else()
set(VBAM_SDL_LIBS SDL3::SDL3 ${SDL_LIBRARY_TEMP})
endif()
endif()
else()
if(VBAM_STATIC)
set(VBAM_SDL_LIBS SDL2::SDL2-static ${SDL_LIBRARY_TEMP})
set(VBAM_SDL_LIBS SDL2::SDL2-static ${SDL_LIBRARY_TEMP})
else()
set(VBAM_SDL_LIBS SDL2::SDL2 ${SDL_LIBRARY_TEMP})
set(VBAM_SDL_LIBS SDL2::SDL2 ${SDL_LIBRARY_TEMP})
endif()
endif()

View File

@@ -40,15 +40,27 @@ if(VBAM_STATIC)
endif()
endif()
find_package(SDL3 QUIET)
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^([xX]86_64|[aA][mM][dD]64)$")
set(PKG_CONFIG_EXECUTABLE "$ENV{VCPKG_ROOT}/installed/x64-windows/tools/pkgconf/pkgconf.exe")
endif()
find_package(PkgConfig)
if(UNIX AND NOT APPLE)
pkg_check_modules(SDL3 sdl3 QUIET)
else()
find_package(SDL3 QUIET)
endif()
option(ENABLE_SDL3 "Use SDL3" "${SDL3_FOUND}")
if(NOT TRANSLATIONS_ONLY)
if(ENABLE_SDL3)
find_package(SDL3 CONFIG REQUIRED)
if(NOT UNIX)
find_package(SDL3 REQUIRED)
endif()
else()
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2 REQUIRED)
endif()
endif()
@@ -93,12 +105,6 @@ if(APPLE AND NOT DISABLE_MACOS_PACKAGE_MANAGERS)
include(MacPackageManagers)
endif()
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^([xX]86_64|[aA][mM][dD]64)$")
set(PKG_CONFIG_EXECUTABLE "$ENV{VCPKG_ROOT}/installed/x64-windows/tools/pkgconf/pkgconf.exe")
endif()
find_package(PkgConfig)
# Link / SFML
if(NOT TRANSLATIONS_ONLY)
set(ENABLE_LINK_DEFAULT ON)

View File

@@ -278,7 +278,7 @@ recording::MediaRet recording::MediaRecorder::setup_video_stream_info(int width,
switch (pixsize)
{
case 1:
tbord = 1; rbord = 2;
tbord = 1; rbord = 4;
break;
case 2:
// 16-bit: 2 @ right, 1 @ top

View File

@@ -10,8 +10,6 @@ extern "C" {
#include "core/base/system.h"
#include "core/base/message.h"
bool no_border = false;
bool utilWritePNGFile(const char* fileName, int w, int h, uint8_t* pix) {
static constexpr size_t kNumChannels = 3;
uint8_t* writeBuffer = new uint8_t[w * h * kNumChannels];
@@ -23,7 +21,7 @@ bool utilWritePNGFile(const char* fileName, int w, int h, uint8_t* pix) {
switch (systemColorDepth) {
case 8: {
uint8_t* pixU8 = (uint8_t*)pix + (w);
uint8_t* pixU8 = (uint8_t*)pix + (w + 4);
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++, pixU8++) {
// White color fix
@@ -38,9 +36,7 @@ bool utilWritePNGFile(const char* fileName, int w, int h, uint8_t* pix) {
}
}
if (no_border == false) {
pixU8 += 2;
}
pixU8 += 4;
}
} break;
case 16: {
@@ -155,11 +151,7 @@ bool utilWriteBMPFile(const char* fileName, int w, int h, uint8_t* pix) {
switch (systemColorDepth) {
case 8: {
uint8_t* pixU8 = 0;
if (no_border == false) {
pixU8 = (uint8_t*)pix + ((w + 2) * (h));
} else {
pixU8 = (uint8_t*)pix + ((w) * (h));
}
pixU8 = (uint8_t*)pix + ((w + 4) * (h));
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++, pixU8++) {
@@ -175,13 +167,11 @@ bool utilWriteBMPFile(const char* fileName, int w, int h, uint8_t* pix) {
}
}
if (no_border == false) {
pixU8++;
pixU8++;
pixU8 -= 2 * (w + 2);
} else {
pixU8 -= 2 * (w);
}
pixU8++;
pixU8++;
pixU8++;
pixU8++;
pixU8 -= 2 * (w + 4);
fwrite(writeBuffer, 1, 3 * w, fp);
b = writeBuffer;

View File

@@ -3905,7 +3905,7 @@ void gbDrawLine()
uint8_t* dest = (uint8_t*)g_pix + gbBorderLineSkip * (register_LY + gbBorderRowSkip)
+ gbBorderColumnSkip;
#else
uint8_t* dest = (uint8_t*)g_pix + (gbBorderLineSkip + 2) * (register_LY + gbBorderRowSkip + 1)
uint8_t* dest = (uint8_t*)g_pix + (gbBorderLineSkip + 4) * (register_LY + gbBorderRowSkip + 1)
+ gbBorderColumnSkip;
#endif
for (size_t x = 0; x < kGBWidth;) {

View File

@@ -4211,7 +4211,7 @@ void CPULoop(int ticks)
#ifdef __LIBRETRO__
uint8_t* dest = (uint8_t*)g_pix + 240 * VCOUNT;
#else
uint8_t* dest = (uint8_t*)g_pix + 242 * (VCOUNT + 1);
uint8_t* dest = (uint8_t*)g_pix + 244 * (VCOUNT + 1);
#endif
for (int x = 0; x < 240;) {
*dest++ = systemColorMap8[g_lineMix[x++] & 0xFFFF];

View File

@@ -1163,7 +1163,7 @@ void sdlInitVideo()
switch (systemColorDepth)
{
case 8:
srcPitch = sizeX * (systemColorDepth >> 3) + 2;
srcPitch = sizeX * (systemColorDepth >> 3) + 4;
break;
case 16:
@@ -1186,7 +1186,7 @@ void sdlInitVideo()
} else {
#ifdef CONFIG_8BIT
systemColorDepth = 8;
srcPitch = sizeX * (systemColorDepth >> 3) + 2;
srcPitch = sizeX * (systemColorDepth >> 3) + 4;
#elif defined(CONFIG_16BIT)
systemColorDepth = 16;
srcPitch = sizeX * (systemColorDepth >> 3) + 4;

View File

@@ -268,7 +268,7 @@ void MetalDrawingPanel::DrawArea()
DrawingPanelInit();
if (systemColorDepth == 8) {
srcPitch = std::ceil(width * scale) + 2;
srcPitch = std::ceil(width * scale) + 4;
} else if (systemColorDepth == 16) {
srcPitch = std::ceil(width * scale * 2) + 4;
} else if (systemColorDepth == 24) {
@@ -302,7 +302,7 @@ void MetalDrawingPanel::DrawArea()
src_pos++;
}
pos++;
src_pos += 2;
src_pos += 4;
}
_texture = loadTextureUsingData(dst);

View File

@@ -1197,20 +1197,14 @@ void GameArea::OnIdle(wxIdleEvent& event)
if (!panel) {
switch (OPTION(kDispRenderMethod)) {
case config::RenderMethod::kSimple:
no_border = false;
panel = new BasicDrawingPanel(this, basic_width, basic_height);
break;
case config::RenderMethod::kSDL:
no_border = false;
panel = new SDLDrawingPanel(this, basic_width, basic_height);
break;
#ifdef __WXMAC__
#ifndef NO_METAL
case config::RenderMethod::kMetal:
no_border = false;
if (is_macosx_1012_or_newer()) {
panel =
new MetalDrawingPanel(this, basic_width, basic_height);
@@ -1221,27 +1215,17 @@ void GameArea::OnIdle(wxIdleEvent& event)
break;
#endif
case config::RenderMethod::kQuartz2d:
no_border = false;
panel =
new Quartz2DDrawingPanel(this, basic_width, basic_height);
break;
#endif
#ifndef NO_OGL
case config::RenderMethod::kOpenGL:
if (out_8) {
no_border = true;
} else {
no_border = false;
}
panel = new GLDrawingPanel(this, basic_width, basic_height);
break;
#endif
#if defined(__WXMSW__) && !defined(NO_D3D)
case config::RenderMethod::kDirect3d:
no_border = false;
panel = new DXDrawingPanel(this, basic_width, basic_height);
break;
#endif
@@ -1640,12 +1624,12 @@ public:
const int procy = height_ * threadno_ / nthreads_;
height_ = height_ * (threadno_ + 1) / nthreads_ - procy;
const int inbpp = systemColorDepth >> 3;
const int inrb = out_8 ? 2 : out_16 ? 2
const int inrb = out_8 ? 4 : out_16 ? 2
: out_24 ? 0 : 1;
const int instride = (width_ + inrb) * inbpp;
const int instride32 = width_ * 4;
const int outbpp = systemColorDepth >> 3;
const int outrb = out_8 ? 2 : out_24 ? 0 : 4;
const int outrb = out_8 ? 4 : out_24 ? 0 : 4;
const int outstride = std::ceil(width_ * outbpp * scale_) + outrb;
const int outstride32 = std::ceil(width_ * 4 * scale_);
uint8_t *dest = NULL;
@@ -1708,7 +1692,7 @@ public:
pos++;
src_pos++;
}
src_pos += 2;
src_pos += 4;
}
} else if (out_16) {
uint16_t *src16_ = (uint16_t *)src_;
@@ -1761,7 +1745,7 @@ public:
pos++;
dst_pos += 4;
}
pos += 2;
pos += 4;
}
} else if (out_16) {
uint16_t *dest16_ = (uint16_t *)dest;
@@ -2003,7 +1987,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data)
// if filtering, this is filter output, retained for redraws
// if not filtering, we still retain current image for redraws
int outbpp = systemColorDepth >> 3;
int outrb = out_8 ? 2 : out_24 ? 0 : 4;
int outrb = out_8 ? 4 : out_24 ? 0 : 4;
int outstride = std::ceil(width * outbpp * scale) + outrb;
if (!pixbuf2) {
@@ -2618,7 +2602,7 @@ void SDLDrawingPanel::DrawArea()
DrawingPanelInit();
if (out_8) {
srcPitch = std::ceil(width * scale) + 2;
srcPitch = std::ceil(width * scale) + 4;
} else if (out_16) {
srcPitch = std::ceil(width * scale * 2) + 4;
} else if (out_24) {
@@ -2673,7 +2657,7 @@ void SDLDrawingPanel::DrawArea(uint8_t** data)
// if filtering, this is filter output, retained for redraws
// if not filtering, we still retain current image for redraws
int outbpp = systemColorDepth >> 3;
int outrb = out_8 ? 2 : out_24 ? 0 : 4;
int outrb = out_8 ? 4 : out_24 ? 0 : 4;
int outstride = std::ceil(width * outbpp * scale) + outrb;
// FIXME: filters race condition?
@@ -2847,7 +2831,7 @@ void BasicDrawingPanel::DrawArea(wxWindowDC& dc)
} else if (out_8) {
// scaled by filters, top/right borders, transform to 24-bit
im = new wxImage(std::ceil(width * scale), std::ceil(height * scale), false);
uint8_t* src = (uint8_t*)todraw + (int)std::ceil((width + 2) * scale); // skip top border
uint8_t* src = (uint8_t*)todraw + (int)std::ceil((width * scale) + 4); // skip top border
uint8_t* dst = im->GetData();
for (int y = 0; y < std::ceil(height * scale); y++) {
@@ -2864,7 +2848,7 @@ void BasicDrawingPanel::DrawArea(wxWindowDC& dc)
}
}
src += 2;
src += 4;
}
} else if (out_16) {
// scaled by filters, top/right borders, transform to 24-bit
@@ -3175,9 +3159,6 @@ void GLDrawingPanel::RefreshGL()
void GLDrawingPanel::DrawArea(wxWindowDC& dc)
{
uint8_t* src = NULL;
uint8_t* dst = NULL;
(void)dc; // unused params
SetContext();
RefreshGL();
@@ -3186,7 +3167,7 @@ void GLDrawingPanel::DrawArea(wxWindowDC& dc)
DrawingPanelInit();
if (todraw) {
int rowlen = std::ceil(width * scale) + (out_8 ? 0 : out_16 ? 2 : out_24 ? 0 : 1);
int rowlen = std::ceil(width * scale) + (out_8 ? 4 : out_16 ? 2 : out_24 ? 0 : 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlen);
#if wxBYTE_ORDER == wxBIG_ENDIAN
@@ -3195,24 +3176,8 @@ void GLDrawingPanel::DrawArea(wxWindowDC& dc)
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
#endif
if (out_8) {
src = (uint8_t*)todraw + (int)std::ceil((width + 2) * ((systemColorDepth >> 3) * scale)); // skip top border
dst = (uint8_t*)todraw;
for (int y = 0; y < std::ceil(height * scale); y++) {
for (int x = 0; x < std::ceil(width * scale); x++) {
*dst++ = *src++;
}
src += 2;
}
glTexImage2D(GL_TEXTURE_2D, 0, int_fmt, (int)std::ceil(width * scale), (int)std::ceil(height * scale),
0, tex_fmt, todraw);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, int_fmt, (int)std::ceil(width * scale), (int)std::ceil(height * scale),
0, tex_fmt, todraw + (int)std::ceil(rowlen * ((systemColorDepth >> 3) * scale)));
}
glTexImage2D(GL_TEXTURE_2D, 0, int_fmt, (int)std::ceil(width * scale), (int)std::ceil(height * scale),
0, tex_fmt, todraw + (int)std::ceil(rowlen * ((systemColorDepth >> 3) * scale)));
glCallList(vlist);
} else
@@ -3536,7 +3501,7 @@ void MetalDrawingPanel::DrawArea(uint8_t** data)
// if filtering, this is filter output, retained for redraws
// if not filtering, we still retain current image for redraws
int outbpp = systemColorDepth >> 3;
int outrb = out_8 ? 2 : out_24 ? 0 : 4;
int outrb = out_8 ? 4 : out_24 ? 0 : 4;
int outstride = std::ceil(width * outbpp * scale) + outrb;
// FIXME: filters race condition?