mirror of
https://github.com/raysan5/raylib.git
synced 2026-05-25 14:10:27 -04:00
Compare commits
6 Commits
5aa3de194c
...
43366d1c6a
| Author | SHA1 | Date | |
|---|---|---|---|
| 43366d1c6a | |||
| f35f4b9fad | |||
| c4b4fcc17e | |||
| fbf132d1d1 | |||
| e274c195af | |||
| fd28dc5644 |
58
src/external/rlsw.h
vendored
58
src/external/rlsw.h
vendored
@ -166,16 +166,15 @@
|
||||
|
||||
// Fast power-of-two texture wrap (SW_REPEAT mode only)
|
||||
// When defined, textures whose width/height are powers of two use a bitmask
|
||||
// wrap (`x & (size-1)`) instead of `floorf`-based fractional wrap or the
|
||||
// signed `%` chain in the linear sampler. Saves a software divide on Xtensa
|
||||
// and a few instructions everywhere. NPOT textures keep using the original
|
||||
// path via a runtime `(size & (size-1)) == 0` check, so SW_REPEAT remains
|
||||
// correct for them. The only observable behavior change is for POT textures
|
||||
// sampled with negative UV coordinates: bitmask wrap (two's complement) can
|
||||
// differ from `sw_fract` by one texel. Off by default to keep bit-for-bit
|
||||
// behavior; opt in if you control your asset UVs.
|
||||
// wrap (`x & (size-1)`) instead of `floorf`-based fractional wrap or the signed `%` chain in the linear sampler
|
||||
// Saves a software divide on Xtensa and a few instructions everywhere
|
||||
// NPOT textures keep using the original path via a runtime `(size & (size-1)) == 0` check,
|
||||
// so SW_REPEAT remains correct for them
|
||||
// The only observable behavior change is for POT textures sampled with negative UV coordinates:
|
||||
// bitmask wrap (two's complement) can differ from `sw_fract` by one texel
|
||||
// Off by default to keep bit-for-bit behavior; opt in if you control your asset UVs
|
||||
//
|
||||
// #define SW_TEXTURE_REPEAT_POT_FAST
|
||||
//#define SW_TEXTURE_REPEAT_POT_FAST
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// OpenGL Compatibility Types
|
||||
@ -860,11 +859,9 @@ SWAPI void swGetFramebufferAttachmentParameteriv(SWattachment attachment, SWatta
|
||||
#endif
|
||||
|
||||
// ESP-DSP acceleration: ESP-IDF ships an optimized math library that includes
|
||||
// `dspm_mult_4x4x4_f32` (4x4 matrix multiply) and `dspm_mult_4x4x1_f32`
|
||||
// (matrix * vector). These are S3-tuned hand-vectorized kernels that beat the
|
||||
// scalar versions for both throughput and code-size. Detection is opt-in to
|
||||
// keep the dependency optional: define SW_USE_ESP_DSP from your build system
|
||||
// (or rely on the `idf_component.yml` example shown in the rlsw docs).
|
||||
// `dspm_mult_4x4x4_f32` (4x4 matrix multiply) and `dspm_mult_4x4x1_f32` (matrix * vector)
|
||||
// These are S3-tuned hand-vectorized kernels that beat the scalar versions for both throughput and code-size
|
||||
// Detection is opt-in to keep the dependency optional: define SW_USE_ESP_DSP from your build system
|
||||
#if defined(ESP_PLATFORM) && defined(SW_USE_ESP_DSP)
|
||||
#define SW_HAS_ESP_DSP
|
||||
#include "dspm_mult.h"
|
||||
@ -884,10 +881,10 @@ SWAPI void swGetFramebufferAttachmentParameteriv(SWattachment attachment, SWatta
|
||||
#define SW_DEG2RAD (SW_PI/180.0f)
|
||||
#define SW_RAD2DEG (180.0f/SW_PI)
|
||||
|
||||
// When clipping a convex polygon against a plane, at most one vertex is added.
|
||||
// When clipping a convex polygon against a plane, at most one vertex is added
|
||||
// Starting from a quadrilateral (4 vertices), clipped sequentially against
|
||||
// the frustum (6 planes) then the scissor rectangle (4 planes):
|
||||
// 4 + 6 + 4 = 14 vertices maximum.
|
||||
// 4 + 6 + 4 = 14 vertices maximum
|
||||
#define SW_MAX_CLIPPED_POLYGON_VERTICES 14
|
||||
#define SW_CLIP_EPSILON 1e-4f
|
||||
|
||||
@ -1175,7 +1172,7 @@ static inline void sw_matrix_mul_rst(float *SW_RESTRICT dst, const float *SW_RES
|
||||
// column-major, so passing them flat is equivalent to passing transposes:
|
||||
// dspm_mult(L^T, R^T) computes (L^T)*(R^T) = (R*L)^T, written back into a
|
||||
// flat array gives the same bit pattern as the column-major product (R*L)
|
||||
// -- exactly the semantic the scalar fallback below has.
|
||||
// -- exactly the semantic the scalar fallback below has
|
||||
dspm_mult_4x4x4_f32(left, right, dst);
|
||||
#else
|
||||
float l00 = left[0], l01 = left[1], l02 = left[2], l03 = left[3];
|
||||
@ -1248,12 +1245,12 @@ static inline float sw_fract(float x)
|
||||
return (x - floorf(x));
|
||||
}
|
||||
|
||||
// Fast reciprocal: 1-ULP accurate in ~7 instructions on Xtensa using the
|
||||
// hardware `recip0.s` seed + two Newton-Raphson refinement steps. All work
|
||||
// stays in FPU registers — no `__divsf3` software call. Hot-path divisions
|
||||
// in the rasterizer (span/triangle setup, perspective divide, etc.) call
|
||||
// this. On non-Xtensa targets it transparently expands to `1.0f / x`, so
|
||||
// generated code is identical to before.
|
||||
// Xtensa architecture optimization
|
||||
// Fast reciprocal: 1-ULP accurate in ~7 instructions using the
|
||||
// hardware `recip0.s` seed + two Newton-Raphson refinement steps
|
||||
// All work stays in FPU registers — no `__divsf3` software call
|
||||
// Hot-path divisions in the rasterizer (span/triangle setup, perspective divide, etc.) call this
|
||||
// On non-Xtensa targets it transparently expands to `1.0f / x`, so generated code is identical to before
|
||||
#if defined(__XTENSA__)
|
||||
__attribute__((always_inline))
|
||||
static inline float sw_rcp(float x)
|
||||
@ -3558,8 +3555,8 @@ static inline bool sw_quad_face_culling(void)
|
||||
// winding in the projected space when all w > 0
|
||||
// A value of 0 for sgnArea means P0, P1, P2 are collinear in (x, y, w)
|
||||
// space, which corresponds to a degenerate triangle projection
|
||||
// Such quads might also be degenerate or non-planar. They are typically
|
||||
// not culled by this test (0 < 0 is false, 0 > 0 is false)
|
||||
// Such quads might also be degenerate or non-planar
|
||||
// They are typically not culled by this test (0 < 0 is false, 0 > 0 is false)
|
||||
// and should be handled by the clipper if necessary
|
||||
|
||||
return (RLSW.cullFace == SW_FRONT)? (sgnArea < 0.0f) : (sgnArea > 0.0f); // Cull if winding is "clockwise" : "counter-clockwise"
|
||||
@ -3879,8 +3876,7 @@ static inline void sw_poly_fill_render(uint32_t state)
|
||||
//-------------------------------------------------------------------------------------------
|
||||
static void sw_immediate_begin(SWdraw mode)
|
||||
{
|
||||
// NOTE: Any checks to ensure command recording can start
|
||||
// must be performed before calling this function.
|
||||
// NOTE: Any checks to ensure command recording can start must be performed before calling this function
|
||||
|
||||
// Recalculate the MVP if this is needed
|
||||
if (RLSW.isDirtyMVP)
|
||||
@ -3891,8 +3887,8 @@ static void sw_immediate_begin(SWdraw mode)
|
||||
|
||||
#ifdef SW_HAS_ESP_DSP
|
||||
// Pre-transpose to row-major so dspm_mult_4x4x1_f32(matMVP_rm, v, out)
|
||||
// computes M*v directly in the per-vertex hot path. 16 scalar copies
|
||||
// per MVP update vs. saving ~20 cycles per vertex transform.
|
||||
// computes M*v directly in the per-vertex hot path; 16 scalar copies
|
||||
// per MVP update vs saving ~20 cycles per vertex transform
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
@ -3955,7 +3951,7 @@ static void sw_immediate_push_vertex(const float position[4])
|
||||
// Calculate clip coordinates
|
||||
#ifdef SW_HAS_ESP_DSP
|
||||
// dspm_mult_4x4x1_f32 declares its inputs non-const; rlsw treats them as
|
||||
// read-only and the cast is safe (the kernel only loads from B).
|
||||
// read-only and the cast is safe (the kernel only loads from B)
|
||||
dspm_mult_4x4x1_f32(RLSW.matMVP_rm, (float *)position, vertex->position);
|
||||
#else
|
||||
const float *m = RLSW.matMVP;
|
||||
@ -5567,7 +5563,7 @@ static void SW_RASTER_TRIANGLE(const sw_vertex_t *v0, const sw_vertex_t *v1, con
|
||||
if (v0->position[1] > v1->position[1]) { const sw_vertex_t *tmp = v0; v0 = v1; v1 = tmp; }
|
||||
|
||||
// Extracting coordinates from the sorted vertices
|
||||
// Put x away for safe keeping. Only y is used right now. Silences warnings.
|
||||
// Put x away for safe keeping; only y is used right now; silences warnings
|
||||
float y0 = v0->position[1];
|
||||
float y1 = v1->position[1];
|
||||
float y2 = v2->position[1];
|
||||
|
||||
@ -810,8 +810,8 @@ void SetWindowSize(int width, int height)
|
||||
RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window);
|
||||
CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f);
|
||||
|
||||
CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.width = CORE.Window.screen.width*currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height*currentMonitor->pixelRatio;
|
||||
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
||||
CORE.Window.currentFbo.height = CORE.Window.render.height;
|
||||
#else
|
||||
@ -1132,16 +1132,16 @@ void SwapScreenBuffer(void)
|
||||
{
|
||||
if (platform.surface)
|
||||
{
|
||||
// copy rlsw pixel data to the surface framebuffer
|
||||
swReadPixels(0, 0, platform.surfaceWidth, platform.surfaceHeight, SW_RGBA, SW_UNSIGNED_BYTE, platform.surfacePixels);
|
||||
// Copy rlsw pixel data to the surface framebuffer
|
||||
rlCopyFramebuffer(0, 0, platform.surfaceWidth, platform.surfaceHeight, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, platform.surfacePixels);
|
||||
|
||||
// Mac wants a different pixel order. I cant seem to get this to work any other way
|
||||
#if defined(__APPLE__)
|
||||
unsigned char temp = 0;
|
||||
unsigned char *p = NULL;
|
||||
for (int i = 0; i < (platform.surfaceWidth * platform.surfaceHeight); i += 1)
|
||||
for (int i = 0; i < (platform.surfaceWidth*platform.surfaceHeight); i += 1)
|
||||
{
|
||||
p = platform.surfacePixels + (i * 4);
|
||||
p = platform.surfacePixels + (i*4);
|
||||
temp = p[0];
|
||||
p[0] = p[2];
|
||||
p[2] = temp;
|
||||
@ -1357,13 +1357,13 @@ void PollInputEvents(void)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window);
|
||||
SetupViewport(platform.window->w * currentMonitor->pixelRatio, platform.window->h * currentMonitor->pixelRatio);
|
||||
SetupViewport(platform.window->w*currentMonitor->pixelRatio, platform.window->h*currentMonitor->pixelRatio);
|
||||
CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f);
|
||||
|
||||
CORE.Window.screen.width = platform.window->w;
|
||||
CORE.Window.screen.height = platform.window->h;
|
||||
CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.width = CORE.Window.screen.width*currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height*currentMonitor->pixelRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1406,10 +1406,10 @@ void PollInputEvents(void)
|
||||
#if defined(__APPLE__)
|
||||
RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window);
|
||||
CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f);
|
||||
SetupViewport(platform.window->w * currentMonitor->pixelRatio, platform.window->h * currentMonitor->pixelRatio);
|
||||
SetupViewport(platform.window->w*currentMonitor->pixelRatio, platform.window->h*currentMonitor->pixelRatio);
|
||||
|
||||
CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.width = CORE.Window.screen.width*currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height*currentMonitor->pixelRatio;
|
||||
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
||||
CORE.Window.currentFbo.height = CORE.Window.render.height;
|
||||
#endif
|
||||
@ -1427,7 +1427,7 @@ void PollInputEvents(void)
|
||||
if (platform.surfacePixels != NULL)
|
||||
{
|
||||
RL_FREE(platform.surfacePixels);
|
||||
platform.surfacePixels = RL_MALLOC(platform.surfaceWidth * platform.surfaceHeight * 4);
|
||||
platform.surfacePixels = RL_MALLOC(platform.surfaceWidth*platform.surfaceHeight*4);
|
||||
}
|
||||
|
||||
if (platform.surface != NULL)
|
||||
@ -1743,8 +1743,8 @@ int InitPlatform(void)
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
CORE.Window.screen.width = CORE.Window.screen.width * GetWindowScaleDPI().x;
|
||||
CORE.Window.screen.height = CORE.Window.screen.height * GetWindowScaleDPI().y;
|
||||
CORE.Window.screen.width = CORE.Window.screen.width*GetWindowScaleDPI().x;
|
||||
CORE.Window.screen.height = CORE.Window.screen.height*GetWindowScaleDPI().y;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1828,8 +1828,8 @@ int InitPlatform(void)
|
||||
RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window);
|
||||
CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f);
|
||||
|
||||
CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.width = CORE.Window.screen.width*currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height*currentMonitor->pixelRatio;
|
||||
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
||||
CORE.Window.currentFbo.height = CORE.Window.render.height;
|
||||
#else
|
||||
@ -1846,8 +1846,8 @@ int InitPlatform(void)
|
||||
RGFW_monitor* currentMonitor = RGFW_window_getMonitor(platform.window);
|
||||
CORE.Window.screenScale = MatrixScale(currentMonitor->pixelRatio, currentMonitor->pixelRatio, 1.0f);
|
||||
|
||||
CORE.Window.render.width = CORE.Window.screen.width * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height * currentMonitor->pixelRatio;
|
||||
CORE.Window.render.width = CORE.Window.screen.width*currentMonitor->pixelRatio;
|
||||
CORE.Window.render.height = CORE.Window.screen.height*currentMonitor->pixelRatio;
|
||||
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
||||
CORE.Window.currentFbo.height = CORE.Window.render.height;
|
||||
#endif
|
||||
@ -1855,7 +1855,7 @@ int InitPlatform(void)
|
||||
platform.surfaceWidth = CORE.Window.currentFbo.width;
|
||||
platform.surfaceHeight = CORE.Window.currentFbo.height;
|
||||
|
||||
platform.surfacePixels = RL_MALLOC(platform.surfaceWidth * platform.surfaceHeight * 4);
|
||||
platform.surfacePixels = RL_MALLOC(platform.surfaceWidth*platform.surfaceHeight*4);
|
||||
if (platform.surfacePixels == NULL)
|
||||
{
|
||||
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize software pixel buffer");
|
||||
|
||||
@ -374,6 +374,8 @@ double GetTime(void)
|
||||
unsigned long long nanoSeconds = (unsigned long long)ts.tv_sec*1000000000LLU + (unsigned long long)ts.tv_nsec;
|
||||
|
||||
time = (double)(nanoSeconds - CORE.Time.base)*1e-9; // Elapsed time since InitTimer()
|
||||
#elif defined(PICO_RP2350)
|
||||
time = (double)to_ms_since_boot(get_absolute_time())/1000.0;
|
||||
#endif
|
||||
return time;
|
||||
}
|
||||
|
||||
@ -506,6 +506,7 @@ __declspec(dllimport) void __stdcall Sleep(unsigned long msTimeout); // Required
|
||||
const char *TextFormat(const char *text, ...); // Formatting of text with variables to 'embed'
|
||||
#endif
|
||||
|
||||
// NOTE: PLATFORM_DESKTOP defaults to GLFW backend
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
#define PLATFORM_DESKTOP_GLFW
|
||||
#endif
|
||||
|
||||
@ -580,8 +580,13 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
|
||||
|
||||
TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount);
|
||||
}
|
||||
else font = GetFontDefault();
|
||||
else
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "FONT: Font is not supported by LoadFontEx/LoadFontFromMemory or no glyphs found, reverted to default font");
|
||||
font = GetFontDefault();
|
||||
}
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "FONT: Font is not supported by LoadFontEx/LoadFontFromMemory or no glyphs found, reverted to default font");
|
||||
font = GetFontDefault();
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user