mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-01 23:07:45 +08:00
[N-Gage] Remove optimisations except for native texture handling prior to some rework of the rendering back-end
[N-Gage] Set proper brush style to draw filled rects properly. [N-Gage] Add persistent buffers to avoid per-frame memory allocations (which are expensive) [N-Gage] Add support for SDL_TEXTURE_ACCESS_TARGET, fixes #13165 [N-Gage] Update README, add hint that the compiler does not support aggregate initializations for structs (knowing this, avoids a lot of headache during debugging) [N-Gage] Add basic fast-path optimisations for render operations. [N-Gage] Fix line drawing.
This commit is contained in:
@@ -33,14 +33,6 @@ software renderer has been removed.
|
|||||||
The outcome is a significantly leaner and more efficient SDL port, which we hope
|
The outcome is a significantly leaner and more efficient SDL port, which we hope
|
||||||
will breathe new life into this beloved yet obscure platform.
|
will breathe new life into this beloved yet obscure platform.
|
||||||
|
|
||||||
## To the Stubborn Legends of the DC Scene
|
|
||||||
|
|
||||||
This port is lovingly dedicated to the ever-nostalgic Dreamcast homebrew scene --
|
|
||||||
because if we managed to pull this off for the N-Gage (yes, the N-Gage), surely
|
|
||||||
you guys can stop clinging to SDL2 like it's a rare Shenmue prototype and finally
|
|
||||||
make the leap to SDL3. It's 2025, not 1999 -- and let's be honest, you're rocking
|
|
||||||
a state-of-the-art C23 compiler. The irony writes itself.
|
|
||||||
|
|
||||||
## Existing Issues and Limitations
|
## Existing Issues and Limitations
|
||||||
|
|
||||||
- For now, the new
|
- For now, the new
|
||||||
@@ -62,3 +54,6 @@ a state-of-the-art C23 compiler. The irony writes itself.
|
|||||||
expected to be resolved in a future update.
|
expected to be resolved in a future update.
|
||||||
|
|
||||||
- Dependency tracking is currently non-functional.
|
- Dependency tracking is currently non-functional.
|
||||||
|
|
||||||
|
- The compiler doesn't support aggregate initialization for structs, so
|
||||||
|
each field must be assigned explicitly.
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ static bool NGAGE_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NGAGE_CreateTextureData(data, texture->w, texture->h)) {
|
if (!NGAGE_CreateTextureData(data, texture->w, texture->h, texture->access)) {
|
||||||
SDL_free(data);
|
SDL_free(data);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -283,8 +283,12 @@ static bool NGAGE_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SD
|
|||||||
verts->dstrect.h = (int)dstrect->h;
|
verts->dstrect.h = (int)dstrect->h;
|
||||||
|
|
||||||
verts->angle = Real2Fix(angle);
|
verts->angle = Real2Fix(angle);
|
||||||
verts->center.x = Real2Fix(center->x);
|
// Convert center from destination-space to source-space.
|
||||||
verts->center.y = Real2Fix(center->y);
|
// Center is relative to dstrect, but rotation is applied in source texture space.
|
||||||
|
float center_x_src = (center->x / dstrect->w) * srcquad->w;
|
||||||
|
float center_y_src = (center->y / dstrect->h) * srcquad->h;
|
||||||
|
verts->center.x = Real2Fix(center_x_src);
|
||||||
|
verts->center.y = Real2Fix(center_y_src);
|
||||||
verts->scale_x = Real2Fix(scale_x);
|
verts->scale_x = Real2Fix(scale_x);
|
||||||
verts->scale_y = Real2Fix(scale_y);
|
verts->scale_y = Real2Fix(scale_y);
|
||||||
|
|
||||||
@@ -444,27 +448,24 @@ static bool NGAGE_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, co
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *bitmapData = NGAGE_GetBitmapDataAddress(phdata);
|
Uint8 *dst = (Uint8 *)NGAGE_GetBitmapDataAddress(phdata);
|
||||||
int bitmapPitch = NGAGE_GetBitmapPitch(phdata);
|
if (!dst) {
|
||||||
|
|
||||||
if (!bitmapData || bitmapPitch == 0) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8 *src = (Uint8 *)pixels;
|
const int bytes_per_pixel = 2;
|
||||||
Uint8 *dst = (Uint8 *)bitmapData + rect->y * bitmapPitch + rect->x * 2; // 2 bytes per pixel for EColor4K
|
const int bitmap_pitch = texture->w * bytes_per_pixel;
|
||||||
|
|
||||||
size_t length = (size_t)rect->w * 2; // 2 bytes per pixel for EColor4K
|
const Uint8 *src = (const Uint8 *)pixels;
|
||||||
|
dst += rect->y * bitmap_pitch + rect->x * bytes_per_pixel;
|
||||||
|
|
||||||
|
const size_t length = (size_t)rect->w * bytes_per_pixel;
|
||||||
for (int row = 0; row < rect->h; ++row) {
|
for (int row = 0; row < rect->h; ++row) {
|
||||||
SDL_memcpy(dst, src, length);
|
SDL_memcpy(dst, src, length);
|
||||||
src += pitch;
|
src += pitch;
|
||||||
dst += bitmapPitch;
|
dst += bitmap_pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark texture as dirty.
|
|
||||||
phdata->isDirty = true;
|
|
||||||
phdata->dirtyRect = *rect;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,34 +477,39 @@ static bool NGAGE_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, cons
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *bitmapData = NGAGE_GetBitmapDataAddress(phdata);
|
Uint8 *data = (Uint8 *)NGAGE_GetBitmapDataAddress(phdata);
|
||||||
int bitmapPitch = NGAGE_GetBitmapPitch(phdata);
|
if (!data) {
|
||||||
|
|
||||||
if (!bitmapData || bitmapPitch == 0) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pixels = (void *)((Uint8 *)bitmapData + rect->y * bitmapPitch + rect->x * 2); // 2 bytes per pixel for EColor4K
|
const int bytes_per_pixel = 2;
|
||||||
*pitch = bitmapPitch;
|
const int bitmap_pitch = texture->w * bytes_per_pixel;
|
||||||
|
|
||||||
// Store the lock rectangle for dirty tracking.
|
|
||||||
phdata->dirtyRect = *rect;
|
|
||||||
|
|
||||||
|
*pixels = (void *)(data + rect->y * bitmap_pitch + rect->x * bytes_per_pixel);
|
||||||
|
*pitch = bitmap_pitch;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NGAGE_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
static void NGAGE_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||||
{
|
{
|
||||||
NGAGE_TextureData *phdata = (NGAGE_TextureData *)texture->internal;
|
|
||||||
|
|
||||||
if (phdata) {
|
|
||||||
// Mark texture as dirty after unlock (assume it was modified).
|
|
||||||
phdata->isDirty = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool NGAGE_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
static bool NGAGE_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||||
{
|
{
|
||||||
|
NGAGE_RendererData *data = (NGAGE_RendererData *)renderer->internal;
|
||||||
|
|
||||||
|
if (texture) {
|
||||||
|
NGAGE_TextureData *texturedata = (NGAGE_TextureData *)texture->internal;
|
||||||
|
if (!texturedata || !texturedata->gc) {
|
||||||
|
return SDL_SetError("Texture is not a render target");
|
||||||
|
}
|
||||||
|
data->current_target = texture;
|
||||||
|
NGAGE_SetRenderTargetInternal(texturedata);
|
||||||
|
} else {
|
||||||
|
data->current_target = NULL;
|
||||||
|
NGAGE_SetRenderTargetInternal(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,7 @@ extern "C" {
|
|||||||
typedef struct NGAGE_RendererData
|
typedef struct NGAGE_RendererData
|
||||||
{
|
{
|
||||||
SDL_Rect *viewport;
|
SDL_Rect *viewport;
|
||||||
|
SDL_Texture *current_target;
|
||||||
|
|
||||||
} NGAGE_RendererData;
|
} NGAGE_RendererData;
|
||||||
|
|
||||||
@@ -54,23 +55,14 @@ typedef struct NGAGE_Vertex
|
|||||||
} NGAGE_Vertex;
|
} NGAGE_Vertex;
|
||||||
|
|
||||||
typedef struct CFbsBitmap CFbsBitmap;
|
typedef struct CFbsBitmap CFbsBitmap;
|
||||||
|
typedef struct CFbsBitGc CFbsBitGc;
|
||||||
|
typedef struct CFbsDevice CFbsDevice;
|
||||||
|
|
||||||
typedef struct NGAGE_TextureData
|
typedef struct NGAGE_TextureData
|
||||||
{
|
{
|
||||||
CFbsBitmap *bitmap;
|
CFbsBitmap *bitmap;
|
||||||
|
CFbsBitGc *gc;
|
||||||
// Cached properties to avoid repeated API calls.
|
CFbsDevice *device;
|
||||||
int cachedWidth;
|
|
||||||
int cachedHeight;
|
|
||||||
int cachedPitch;
|
|
||||||
void *cachedDataAddress;
|
|
||||||
|
|
||||||
// Cardinal rotation cache (0°, 90°, 180°, 270°) - created on demand.
|
|
||||||
CFbsBitmap *cardinalRotations[4];
|
|
||||||
|
|
||||||
// Dirty tracking to avoid redundant rendering.
|
|
||||||
bool isDirty;
|
|
||||||
SDL_Rect dirtyRect;
|
|
||||||
|
|
||||||
} NGAGE_TextureData;
|
} NGAGE_TextureData;
|
||||||
|
|
||||||
@@ -99,12 +91,9 @@ void NGAGE_Clear(const Uint32 color);
|
|||||||
Uint32 NGAGE_ConvertColor(float r, float g, float b, float a, float color_scale);
|
Uint32 NGAGE_ConvertColor(float r, float g, float b, float a, float color_scale);
|
||||||
bool NGAGE_Copy(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect *srcrect, SDL_Rect *dstrect);
|
bool NGAGE_Copy(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect *srcrect, SDL_Rect *dstrect);
|
||||||
bool NGAGE_CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, NGAGE_CopyExData *copydata);
|
bool NGAGE_CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, NGAGE_CopyExData *copydata);
|
||||||
bool NGAGE_CreateTextureData(NGAGE_TextureData *data, const int width, const int height);
|
bool NGAGE_CreateTextureData(NGAGE_TextureData *data, const int width, const int height, const int access);
|
||||||
void NGAGE_DestroyTextureData(NGAGE_TextureData *data);
|
void NGAGE_DestroyTextureData(NGAGE_TextureData *data);
|
||||||
void *NGAGE_GetBitmapDataAddress(NGAGE_TextureData *data);
|
void* NGAGE_GetBitmapDataAddress(NGAGE_TextureData *data);
|
||||||
int NGAGE_GetBitmapPitch(NGAGE_TextureData *data);
|
|
||||||
int NGAGE_GetBitmapWidth(NGAGE_TextureData *data);
|
|
||||||
int NGAGE_GetBitmapHeight(NGAGE_TextureData *data);
|
|
||||||
void NGAGE_DrawLines(NGAGE_Vertex *verts, const int count);
|
void NGAGE_DrawLines(NGAGE_Vertex *verts, const int count);
|
||||||
void NGAGE_DrawPoints(NGAGE_Vertex *verts, const int count);
|
void NGAGE_DrawPoints(NGAGE_Vertex *verts, const int count);
|
||||||
void NGAGE_FillRects(NGAGE_Vertex *verts, const int count);
|
void NGAGE_FillRects(NGAGE_Vertex *verts, const int count);
|
||||||
@@ -113,6 +102,7 @@ void NGAGE_SetClipRect(const SDL_Rect *rect);
|
|||||||
void NGAGE_SetDrawColor(const Uint32 color);
|
void NGAGE_SetDrawColor(const Uint32 color);
|
||||||
void NGAGE_PumpEventsInternal(void);
|
void NGAGE_PumpEventsInternal(void);
|
||||||
void NGAGE_SuspendScreenSaverInternal(bool suspend);
|
void NGAGE_SuspendScreenSaverInternal(bool suspend);
|
||||||
|
void NGAGE_SetRenderTargetInternal(NGAGE_TextureData *target);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#define ngage_video_render_ngage_c_hpp
|
#define ngage_video_render_ngage_c_hpp
|
||||||
|
|
||||||
#include "SDL_render_ngage_c.h"
|
#include "SDL_render_ngage_c.h"
|
||||||
#include <3dtypes.h>
|
|
||||||
#include <NRenderer.h>
|
#include <NRenderer.h>
|
||||||
#include <e32std.h>
|
#include <e32std.h>
|
||||||
#include <w32std.h>
|
#include <w32std.h>
|
||||||
@@ -38,7 +37,7 @@ class CRenderer : public MDirectScreenAccess
|
|||||||
void Clear(TUint32 iColor);
|
void Clear(TUint32 iColor);
|
||||||
bool Copy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect);
|
bool Copy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect);
|
||||||
bool CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const NGAGE_CopyExData *copydata);
|
bool CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const NGAGE_CopyExData *copydata);
|
||||||
bool CreateTextureData(NGAGE_TextureData *aTextureData, const TInt aWidth, const TInt aHeight);
|
bool CreateTextureData(NGAGE_TextureData *aTextureData, const TInt aWidth, const TInt aHeight, const TInt aAccess);
|
||||||
void DrawLines(NGAGE_Vertex *aVerts, const TInt aCount);
|
void DrawLines(NGAGE_Vertex *aVerts, const TInt aCount);
|
||||||
void DrawPoints(NGAGE_Vertex *aVerts, const TInt aCount);
|
void DrawPoints(NGAGE_Vertex *aVerts, const TInt aCount);
|
||||||
void FillRects(NGAGE_Vertex *aVerts, const TInt aCount);
|
void FillRects(NGAGE_Vertex *aVerts, const TInt aCount);
|
||||||
@@ -48,6 +47,10 @@ class CRenderer : public MDirectScreenAccess
|
|||||||
void UpdateFPS();
|
void UpdateFPS();
|
||||||
void SuspendScreenSaver(TBool aSuspend);
|
void SuspendScreenSaver(TBool aSuspend);
|
||||||
|
|
||||||
|
// Render target management.
|
||||||
|
void SetRenderTarget(NGAGE_TextureData *aTarget);
|
||||||
|
CFbsBitGc* GetCurrentGc();
|
||||||
|
|
||||||
// Event handling.
|
// Event handling.
|
||||||
void DisableKeyBlocking();
|
void DisableKeyBlocking();
|
||||||
void HandleEvent(const TWsEvent &aWsEvent);
|
void HandleEvent(const TWsEvent &aWsEvent);
|
||||||
@@ -88,38 +91,15 @@ class CRenderer : public MDirectScreenAccess
|
|||||||
// Screen saver.
|
// Screen saver.
|
||||||
TBool iSuspendScreenSaver;
|
TBool iSuspendScreenSaver;
|
||||||
|
|
||||||
// Work buffers for texture transformations (reusable to avoid per-frame allocations).
|
// Render target.
|
||||||
void *iWorkBuffer1;
|
NGAGE_TextureData *iCurrentRenderTarget;
|
||||||
void *iWorkBuffer2;
|
|
||||||
TInt iWorkBufferSize;
|
|
||||||
|
|
||||||
// Temporary render bitmap to avoid destroying source textures.
|
// Persistent buffers to avoid per-frame allocations.
|
||||||
CFbsBitmap *iTempRenderBitmap;
|
void *iPixelBufferA;
|
||||||
TInt iTempRenderBitmapWidth;
|
void *iPixelBufferB;
|
||||||
TInt iTempRenderBitmapHeight;
|
TInt iPixelBufferSize;
|
||||||
|
TPoint *iPointsBuffer;
|
||||||
// Color modulation lookup tables (pre-calculated to avoid per-pixel FixMul).
|
TInt iPointsBufferSize;
|
||||||
TUint8 iColorModLUT[768]; // 256 entries each for R, G, B
|
|
||||||
TFixed iLastColorR;
|
|
||||||
TFixed iLastColorG;
|
|
||||||
TFixed iLastColorB;
|
|
||||||
|
|
||||||
// Reusable line points buffer to avoid per-frame allocations in DrawLines.
|
|
||||||
TPoint *iLinePointsBuffer;
|
|
||||||
TInt iLinePointsBufferCapacity;
|
|
||||||
|
|
||||||
// Cached draw color to avoid redundant SetPenColor/SetBrushColor calls.
|
|
||||||
TUint32 iLastDrawColor;
|
|
||||||
|
|
||||||
// Cached clear color to avoid redundant SetBrushColor calls.
|
|
||||||
TUint32 iLastClearColor;
|
|
||||||
|
|
||||||
// Helper methods.
|
|
||||||
bool EnsureWorkBufferCapacity(TInt aRequiredSize);
|
|
||||||
bool EnsureTempBitmapCapacity(TInt aWidth, TInt aHeight);
|
|
||||||
bool EnsureLinePointsCapacity(TInt aRequiredCount);
|
|
||||||
void BuildColorModLUT(TFixed rf, TFixed gf, TFixed bf);
|
|
||||||
CFbsBitmap *GetCardinalRotation(NGAGE_TextureData *aTextureData, TInt aAngleIndex);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ngage_video_render_ngage_c_hpp
|
#endif // ngage_video_render_ngage_c_hpp
|
||||||
|
|||||||
+230
-285
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include <3dtypes.h>
|
#include <3dtypes.h>
|
||||||
|
|
||||||
void ApplyColorMod(void *dest, void *source, int pitch, int width, int height, SDL_FColor color, const TUint8 *colorLUT);
|
void ApplyColorMod(void *dest, void *source, int pitch, int width, int height, SDL_FColor color);
|
||||||
void ApplyFlip(void *dest, void *source, int pitch, int width, int height, SDL_FlipMode flip);
|
void ApplyFlip(void *dest, void *source, int pitch, int width, int height, SDL_FlipMode flip);
|
||||||
void ApplyRotation(void *dest, void *source, int pitch, int width, int height, TFixed center_x, TFixed center_y, TFixed angle);
|
void ApplyRotation(void *dest, void *source, int pitch, int width, int height, TFixed center_x, TFixed center_y, TFixed angle);
|
||||||
void ApplyScale(void *dest, void *source, int pitch, int width, int height, TFixed center_x, TFixed center_y, TFixed scale_x, TFixed scale_y);
|
void ApplyScale(void *dest, void *source, int pitch, int width, int height, TFixed center_x, TFixed center_y, TFixed scale_x, TFixed scale_y);
|
||||||
|
|||||||
Reference in New Issue
Block a user