mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-07 02:16:28 +00:00
REVIEWED: rlsw
module and related files
This commit is contained in:
3264
src/external/rlsw.h
vendored
3264
src/external/rlsw.h
vendored
File diff suppressed because it is too large
Load Diff
@@ -1233,7 +1233,7 @@ void SwapScreenBuffer(void)
|
|||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
// NOTE: We use a preprocessor condition here because `rlCopyFramebuffer` is only declared for software rendering
|
// NOTE: We use a preprocessor condition here because `rlCopyFramebuffer` is only declared for software rendering
|
||||||
SDL_Surface* surface = SDL_GetWindowSurface(platform.window);
|
SDL_Surface *surface = SDL_GetWindowSurface(platform.window);
|
||||||
rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, surface->pixels);
|
rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, surface->pixels);
|
||||||
SDL_UpdateWindowSurface(platform.window);
|
SDL_UpdateWindowSurface(platform.window);
|
||||||
#else
|
#else
|
||||||
|
@@ -818,14 +818,14 @@ void SwapScreenBuffer(void)
|
|||||||
platform.prevBO = bo;
|
platform.prevBO = bo;
|
||||||
#else
|
#else
|
||||||
// Software rendering buffer swap
|
// Software rendering buffer swap
|
||||||
if ((-1 == platform.fd) || !platform.connector || (platform.modeIndex < 0))
|
if ((platform.fd == -1) || !platform.connector || (platform.modeIndex < 0))
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: DRM initialization failed to swap");
|
TRACELOG(LOG_ERROR, "DISPLAY: DRM initialization failed to swap");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the software rendered color buffer
|
// Get the software rendered color buffer
|
||||||
int bufferWidth, bufferHeight;
|
int bufferWidth = 0, bufferHeight = 0;
|
||||||
void *colorBuffer = swGetColorBuffer(&bufferWidth, &bufferHeight);
|
void *colorBuffer = swGetColorBuffer(&bufferWidth, &bufferHeight);
|
||||||
if (!colorBuffer)
|
if (!colorBuffer)
|
||||||
{
|
{
|
||||||
@@ -849,7 +849,7 @@ void SwapScreenBuffer(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create a dumb buffer for software rendering
|
// Create a dumb buffer for software rendering
|
||||||
struct drm_mode_create_dumb creq = {0};
|
struct drm_mode_create_dumb creq = { 0 };
|
||||||
creq.width = width;
|
creq.width = width;
|
||||||
creq.height = height;
|
creq.height = height;
|
||||||
creq.bpp = bpp;
|
creq.bpp = bpp;
|
||||||
@@ -863,28 +863,25 @@ void SwapScreenBuffer(void)
|
|||||||
|
|
||||||
// Create framebuffer with the correct format
|
// Create framebuffer with the correct format
|
||||||
uint32_t fb = 0;
|
uint32_t fb = 0;
|
||||||
result = drmModeAddFB(platform.fd,
|
result = drmModeAddFB(platform.fd, width, height, depth, bpp, creq.pitch, creq.handle, &fb);
|
||||||
width, height,
|
|
||||||
depth, bpp, creq.pitch,
|
|
||||||
creq.handle, &fb);
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: drmModeAddFB() failed with result: %d (%s)", result, strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: drmModeAddFB() failed with result: %d (%s)", result, strerror(errno));
|
||||||
struct drm_mode_destroy_dumb dreq = {0};
|
struct drm_mode_destroy_dumb dreq = { 0 };
|
||||||
dreq.handle = creq.handle;
|
dreq.handle = creq.handle;
|
||||||
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the dumb buffer to copy our software rendered buffer
|
// Map the dumb buffer to copy our software rendered buffer
|
||||||
struct drm_mode_map_dumb mreq = {0};
|
struct drm_mode_map_dumb mreq = { 0 };
|
||||||
mreq.handle = creq.handle;
|
mreq.handle = creq.handle;
|
||||||
result = drmIoctl(platform.fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
|
result = drmIoctl(platform.fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: Failed to map dumb buffer: %s", strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: Failed to map dumb buffer: %s", strerror(errno));
|
||||||
drmModeRmFB(platform.fd, fb);
|
drmModeRmFB(platform.fd, fb);
|
||||||
struct drm_mode_destroy_dumb dreq = {0};
|
struct drm_mode_destroy_dumb dreq = { 0 };
|
||||||
dreq.handle = creq.handle;
|
dreq.handle = creq.handle;
|
||||||
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||||
return;
|
return;
|
||||||
@@ -896,7 +893,7 @@ void SwapScreenBuffer(void)
|
|||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: Failed to mmap dumb buffer: %s", strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: Failed to mmap dumb buffer: %s", strerror(errno));
|
||||||
drmModeRmFB(platform.fd, fb);
|
drmModeRmFB(platform.fd, fb);
|
||||||
struct drm_mode_destroy_dumb dreq = {0};
|
struct drm_mode_destroy_dumb dreq = { 0 };
|
||||||
dreq.handle = creq.handle;
|
dreq.handle = creq.handle;
|
||||||
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||||
return;
|
return;
|
||||||
@@ -919,10 +916,7 @@ void SwapScreenBuffer(void)
|
|||||||
|
|
||||||
// Find a CRTC compatible with the connector
|
// Find a CRTC compatible with the connector
|
||||||
uint32_t crtcId = 0;
|
uint32_t crtcId = 0;
|
||||||
if (platform.crtc)
|
if (platform.crtc) crtcId = platform.crtc->crtc_id;
|
||||||
{
|
|
||||||
crtcId = platform.crtc->crtc_id;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Find a CRTC that's compatible with this connector
|
// Find a CRTC that's compatible with this connector
|
||||||
@@ -939,10 +933,7 @@ void SwapScreenBuffer(void)
|
|||||||
|
|
||||||
// Check which CRTCs are compatible with this connector
|
// Check which CRTCs are compatible with this connector
|
||||||
drmModeEncoder *encoder = NULL;
|
drmModeEncoder *encoder = NULL;
|
||||||
if (platform.connector->encoder_id)
|
if (platform.connector->encoder_id) encoder = drmModeGetEncoder(platform.fd, platform.connector->encoder_id);
|
||||||
{
|
|
||||||
encoder = drmModeGetEncoder(platform.fd, platform.connector->encoder_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encoder && encoder->crtc_id)
|
if (encoder && encoder->crtc_id)
|
||||||
{
|
{
|
||||||
@@ -962,6 +953,7 @@ void SwapScreenBuffer(void)
|
|||||||
platform.crtc = crtc;
|
platform.crtc = crtc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crtc) drmModeFreeCrtc(crtc);
|
if (crtc) drmModeFreeCrtc(crtc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -981,9 +973,7 @@ void SwapScreenBuffer(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set CRTC with better error handling
|
// Set CRTC with better error handling
|
||||||
result = drmModeSetCrtc(platform.fd, crtcId, fb, 0, 0,
|
result = drmModeSetCrtc(platform.fd, crtcId, fb, 0, 0, &platform.connector->connector_id, 1, mode);
|
||||||
&platform.connector->connector_id, 1,
|
|
||||||
mode);
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: drmModeSetCrtc() failed with result: %d (%s)", result, strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: drmModeSetCrtc() failed with result: %d (%s)", result, strerror(errno));
|
||||||
@@ -1001,10 +991,7 @@ void SwapScreenBuffer(void)
|
|||||||
if (platform.prevFB)
|
if (platform.prevFB)
|
||||||
{
|
{
|
||||||
result = drmModeRmFB(platform.fd, platform.prevFB);
|
result = drmModeRmFB(platform.fd, platform.prevFB);
|
||||||
if (result != 0)
|
if (result != 0) TRACELOG(LOG_WARNING, "DISPLAY: drmModeRmFB() failed with result: %d", result);
|
||||||
{
|
|
||||||
TRACELOG(LOG_WARNING, "DISPLAY: drmModeRmFB() failed with result: %d", result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.prevFB = fb;
|
platform.prevFB = fb;
|
||||||
@@ -1249,7 +1236,7 @@ int InitPlatform(void)
|
|||||||
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected
|
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected
|
||||||
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output
|
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output
|
||||||
// WARNING: Accept CONNECTED, UNKNOWN and even those without encoder_id connectors for software mode
|
// WARNING: Accept CONNECTED, UNKNOWN and even those without encoder_id connectors for software mode
|
||||||
if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->count_modes > 0)//(con->encoder_id))
|
if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->count_modes > 0))
|
||||||
{
|
{
|
||||||
#if !defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if !defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
// For hardware rendering, we need an encoder_id
|
// For hardware rendering, we need an encoder_id
|
||||||
@@ -1259,10 +1246,7 @@ int InitPlatform(void)
|
|||||||
platform.connector = con;
|
platform.connector = con;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i connected but no encoder", i);
|
||||||
{
|
|
||||||
TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i connected but no encoder", i);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
// For software rendering, we can accept even without encoder_id
|
// For software rendering, we can accept even without encoder_id
|
||||||
TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i suitable for software rendering", i);
|
TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i suitable for software rendering", i);
|
||||||
|
22
src/rlgl.h
22
src/rlgl.h
@@ -776,8 +776,8 @@ RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attac
|
|||||||
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
||||||
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
RLAPI void rlCopyFramebuffer(int x, int y, int w, int h, int format, void* pixels);
|
RLAPI void rlCopyFramebuffer(int x, int y, int width, int height, int format, void *pixels); // Copy framebuffer pixel data to internal buffer
|
||||||
RLAPI void rlResizeFramebuffer(int width, int height);
|
RLAPI void rlResizeFramebuffer(int width, int height); // Resize internal framebuffer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Shaders management
|
// Shaders management
|
||||||
@@ -846,7 +846,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11)
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
#define RLSW_IMPL
|
#define RLSW_IMPLEMENTATION
|
||||||
#define SW_MALLOC(sz) RL_MALLOC(sz)
|
#define SW_MALLOC(sz) RL_MALLOC(sz)
|
||||||
#define SW_REALLOC(ptr, newSz) RL_REALLOC(ptr, newSz)
|
#define SW_REALLOC(ptr, newSz) RL_REALLOC(ptr, newSz)
|
||||||
#define SW_FREE(ptr) RL_FREE(ptr)
|
#define SW_FREE(ptr) RL_FREE(ptr)
|
||||||
@@ -2357,9 +2357,10 @@ void rlglInit(int width, int height)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
if (!swInit(width, height))
|
int result = swInit(width, height); // Initialize software renderer backend
|
||||||
|
if (result == 0)
|
||||||
{
|
{
|
||||||
TRACELOG(RL_LOG_ERROR, "RLGL: Software renderer initialization failed!");
|
TRACELOG(RL_LOG_ERROR, "RLSW: Software renderer initialization failed!");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2392,7 +2393,7 @@ void rlglClose(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
swClose();
|
swClose(); // Unload sofware renderer resources
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2703,6 +2704,7 @@ void *rlGetProcAddress(const char *procName)
|
|||||||
int rlGetVersion(void)
|
int rlGetVersion(void)
|
||||||
{
|
{
|
||||||
int glVersion = 0;
|
int glVersion = 0;
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
glVersion = RL_OPENGL_11_SOFTWARE;
|
glVersion = RL_OPENGL_11_SOFTWARE;
|
||||||
#elif defined(GRAPHICS_API_OPENGL_11)
|
#elif defined(GRAPHICS_API_OPENGL_11)
|
||||||
@@ -3747,13 +3749,15 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
void rlCopyFramebuffer(int x, int y, int w, int h, int format, void* pixels)
|
// Copy framebuffer pixel data to internal buffer
|
||||||
|
void rlCopyFramebuffer(int x, int y, int width, int height, int format, void* pixels)
|
||||||
{
|
{
|
||||||
unsigned int glInternalFormat, glFormat, glType;
|
unsigned int glInternalFormat, glFormat, glType;
|
||||||
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType); // Get OpenGL texture format
|
||||||
swCopyFramebuffer(x, y, w, h, glFormat, glType, pixels);
|
swCopyFramebuffer(x, y, width, height, glFormat, glType, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resize internal framebuffer
|
||||||
void rlResizeFramebuffer(int width, int height)
|
void rlResizeFramebuffer(int width, int height)
|
||||||
{
|
{
|
||||||
swResizeFramebuffer(width, height);
|
swResizeFramebuffer(width, height);
|
||||||
|
Reference in New Issue
Block a user