mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-08-03 18:57:27 -04:00
Fix blockalloc_total_free returning too many free blocks, other small tidyups
This commit is contained in:
parent
085d4979ca
commit
f19bf483be
@ -136,28 +136,28 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
|
|||||||
|
|
||||||
static void GL_SetupVbColoured(void) {
|
static void GL_SetupVbColoured(void) {
|
||||||
GLpointer ptr = (GLpointer)VB_PTR;
|
GLpointer ptr = (GLpointer)VB_PTR;
|
||||||
_glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0);
|
glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0);
|
||||||
_glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12);
|
glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GL_SetupVbTextured(void) {
|
static void GL_SetupVbTextured(void) {
|
||||||
GLpointer ptr = (GLpointer)VB_PTR;
|
GLpointer ptr = (GLpointer)VB_PTR;
|
||||||
_glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0);
|
glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0);
|
||||||
_glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12);
|
glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12);
|
||||||
_glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16);
|
glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GL_SetupVbColoured_Range(int startVertex) {
|
static void GL_SetupVbColoured_Range(int startVertex) {
|
||||||
GLpointer ptr = (GLpointer)VB_PTR + startVertex * SIZEOF_VERTEX_COLOURED;
|
GLpointer ptr = (GLpointer)VB_PTR + startVertex * SIZEOF_VERTEX_COLOURED;
|
||||||
_glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0);
|
glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0);
|
||||||
_glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12);
|
glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GL_SetupVbTextured_Range(int startVertex) {
|
static void GL_SetupVbTextured_Range(int startVertex) {
|
||||||
GLpointer ptr = (GLpointer)VB_PTR + startVertex * SIZEOF_VERTEX_TEXTURED;
|
GLpointer ptr = (GLpointer)VB_PTR + startVertex * SIZEOF_VERTEX_TEXTURED;
|
||||||
_glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0);
|
glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0);
|
||||||
_glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12);
|
glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12);
|
||||||
_glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16);
|
glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_SetVertexFormat(VertexFormat fmt) {
|
void Gfx_SetVertexFormat(VertexFormat fmt) {
|
||||||
@ -166,14 +166,14 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
|
|||||||
gfx_stride = strideSizes[fmt];
|
gfx_stride = strideSizes[fmt];
|
||||||
|
|
||||||
if (fmt == VERTEX_FORMAT_TEXTURED) {
|
if (fmt == VERTEX_FORMAT_TEXTURED) {
|
||||||
_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
_glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
gfx_setupVBFunc = GL_SetupVbTextured;
|
gfx_setupVBFunc = GL_SetupVbTextured;
|
||||||
gfx_setupVBRangeFunc = GL_SetupVbTextured_Range;
|
gfx_setupVBRangeFunc = GL_SetupVbTextured_Range;
|
||||||
} else {
|
} else {
|
||||||
_glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
_glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
gfx_setupVBFunc = GL_SetupVbColoured;
|
gfx_setupVBFunc = GL_SetupVbColoured;
|
||||||
gfx_setupVBRangeFunc = GL_SetupVbColoured_Range;
|
gfx_setupVBRangeFunc = GL_SetupVbColoured_Range;
|
||||||
@ -182,21 +182,21 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
|
|||||||
|
|
||||||
void Gfx_DrawVb_Lines(int verticesCount) {
|
void Gfx_DrawVb_Lines(int verticesCount) {
|
||||||
gfx_setupVBFunc();
|
gfx_setupVBFunc();
|
||||||
_glDrawArrays(GL_LINES, 0, verticesCount);
|
glDrawArrays(GL_LINES, 0, verticesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex, DrawHints hints) {
|
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex, DrawHints hints) {
|
||||||
if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; }
|
if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; }
|
||||||
|
|
||||||
gfx_setupVBRangeFunc(startVertex);
|
gfx_setupVBRangeFunc(startVertex);
|
||||||
_glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices);
|
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
||||||
if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; }
|
if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; }
|
||||||
|
|
||||||
gfx_setupVBFunc();
|
gfx_setupVBFunc();
|
||||||
_glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices);
|
glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
||||||
@ -208,7 +208,7 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
|||||||
*---------------------------------------------------------Textures--------------------------------------------------------*
|
*---------------------------------------------------------Textures--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Gfx_BindTexture(GfxResourceID texId) {
|
void Gfx_BindTexture(GfxResourceID texId) {
|
||||||
_glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId));
|
glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ static int gfx_fogMode;
|
|||||||
|
|
||||||
void Gfx_SetFog(cc_bool enabled) {
|
void Gfx_SetFog(cc_bool enabled) {
|
||||||
gfx_fogEnabled = enabled;
|
gfx_fogEnabled = enabled;
|
||||||
if (enabled) { _glEnable(GL_FOG); } else { _glDisable(GL_FOG); }
|
if (enabled) { glEnable(GL_FOG); } else { glDisable(GL_FOG); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_SetFogCol(PackedCol color) {
|
void Gfx_SetFogCol(PackedCol color) {
|
||||||
@ -233,19 +233,19 @@ void Gfx_SetFogCol(PackedCol color) {
|
|||||||
rgba[2] = PackedCol_B(color) / 255.0f;
|
rgba[2] = PackedCol_B(color) / 255.0f;
|
||||||
rgba[3] = PackedCol_A(color) / 255.0f;
|
rgba[3] = PackedCol_A(color) / 255.0f;
|
||||||
|
|
||||||
_glFogfv(GL_FOG_COLOR, rgba);
|
glFogfv(GL_FOG_COLOR, rgba);
|
||||||
gfx_fogColor = color;
|
gfx_fogColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_SetFogDensity(float value) {
|
void Gfx_SetFogDensity(float value) {
|
||||||
if (value == gfx_fogDensity) return;
|
if (value == gfx_fogDensity) return;
|
||||||
_glFogf(GL_FOG_DENSITY, value);
|
glFogf(GL_FOG_DENSITY, value);
|
||||||
gfx_fogDensity = value;
|
gfx_fogDensity = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_SetFogEnd(float value) {
|
void Gfx_SetFogEnd(float value) {
|
||||||
if (value == gfx_fogEnd) return;
|
if (value == gfx_fogEnd) return;
|
||||||
_glFogf(GL_FOG_END, value);
|
glFogf(GL_FOG_END, value);
|
||||||
gfx_fogEnd = value;
|
gfx_fogEnd = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,12 +253,12 @@ void Gfx_SetFogMode(FogFunc func) {
|
|||||||
static GLint modes[3] = { GL_LINEAR, GL_EXP, GL_EXP2 };
|
static GLint modes[3] = { GL_LINEAR, GL_EXP, GL_EXP2 };
|
||||||
if (func == gfx_fogMode) return;
|
if (func == gfx_fogMode) return;
|
||||||
|
|
||||||
_glFogi(GL_FOG_MODE, modes[func]);
|
glFogi(GL_FOG_MODE, modes[func]);
|
||||||
gfx_fogMode = func;
|
gfx_fogMode = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetAlphaTest(cc_bool enabled) {
|
static void SetAlphaTest(cc_bool enabled) {
|
||||||
if (enabled) { _glEnable(GL_ALPHA_TEST); } else { _glDisable(GL_ALPHA_TEST); }
|
if (enabled) { glEnable(GL_ALPHA_TEST); } else { glDisable(GL_ALPHA_TEST); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
|
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
|
||||||
@ -266,7 +266,7 @@ void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
|
|||||||
SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1],
|
SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1],
|
||||||
enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]);
|
enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]);
|
||||||
|
|
||||||
if (enabled) { _glEnable(GL_TEXTURE_2D); } else { _glDisable(GL_TEXTURE_2D); }
|
if (enabled) { glEnable(GL_TEXTURE_2D); } else { glDisable(GL_TEXTURE_2D); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,12 +277,12 @@ static GLenum matrix_modes[] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE };
|
|||||||
static int lastMatrix;
|
static int lastMatrix;
|
||||||
|
|
||||||
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
||||||
if (type != lastMatrix) { lastMatrix = type; _glMatrixMode(matrix_modes[type]); }
|
if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); }
|
||||||
|
|
||||||
if (matrix == &Matrix_Identity) {
|
if (matrix == &Matrix_Identity) {
|
||||||
_glLoadIdentity();
|
glLoadIdentity();
|
||||||
} else {
|
} else {
|
||||||
_glLoadMatrixf((const float*)matrix);
|
glLoadMatrixf((const float*)matrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,8 +307,8 @@ void Gfx_DisableTextureOffset(void) { Gfx_LoadMatrix(2, &Matrix_Identity); }
|
|||||||
static void Gfx_FreeState(void) { FreeDefaultResources(); }
|
static void Gfx_FreeState(void) { FreeDefaultResources(); }
|
||||||
static void Gfx_RestoreState(void) {
|
static void Gfx_RestoreState(void) {
|
||||||
InitDefaultResources();
|
InitDefaultResources();
|
||||||
_glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
_glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
gfx_format = -1;
|
gfx_format = -1;
|
||||||
lastMatrix = -1;
|
lastMatrix = -1;
|
||||||
@ -319,9 +319,9 @@ static void Gfx_RestoreState(void) {
|
|||||||
gfx_fogDensity = -1.0f;
|
gfx_fogDensity = -1.0f;
|
||||||
gfx_fogMode = -1;
|
gfx_fogMode = -1;
|
||||||
|
|
||||||
_glAlphaFunc(GL_GREATER, 0.5f);
|
glAlphaFunc(GL_GREATER, 0.5f);
|
||||||
_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
_glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_bool Gfx_WarnIfNecessary(void) {
|
cc_bool Gfx_WarnIfNecessary(void) {
|
||||||
|
@ -182,19 +182,6 @@ typedef struct CCTexture_ {
|
|||||||
#define TEX_TOTAL_BLOCKS (TEX_TOTAL_SIZE / TEX_BLOCK_SIZE)
|
#define TEX_TOTAL_BLOCKS (TEX_TOTAL_SIZE / TEX_BLOCK_SIZE)
|
||||||
static cc_uint8 tex_table[TEX_TOTAL_BLOCKS / BLOCKS_PER_PAGE];
|
static cc_uint8 tex_table[TEX_TOTAL_BLOCKS / BLOCKS_PER_PAGE];
|
||||||
|
|
||||||
static void texture_alloc(CCTexture* tex, int size) {
|
|
||||||
int blocks = (size + (TEX_BLOCK_SIZE - 1)) / TEX_BLOCK_SIZE;
|
|
||||||
int addr = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks);
|
|
||||||
if (addr == -1) return;
|
|
||||||
|
|
||||||
tex->texBase = addr;
|
|
||||||
tex->texBlocks = blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void texture_release(CCTexture* tex) {
|
|
||||||
blockalloc_dealloc(tex_table, tex->texBase, tex->texBlocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Palette VRAM banks - Bank E (64 kb)
|
// Palette VRAM banks - Bank E (64 kb)
|
||||||
#define PAL_TOTAL_SIZE (64 * 1024)
|
#define PAL_TOTAL_SIZE (64 * 1024)
|
||||||
// Use 16 hwords for size of each block
|
// Use 16 hwords for size of each block
|
||||||
@ -203,19 +190,6 @@ static void texture_release(CCTexture* tex) {
|
|||||||
#define PAL_TOTAL_BLOCKS (PAL_TOTAL_SIZE / PAL_BLOCK_SIZE)
|
#define PAL_TOTAL_BLOCKS (PAL_TOTAL_SIZE / PAL_BLOCK_SIZE)
|
||||||
static cc_uint8 pal_table[PAL_TOTAL_BLOCKS / BLOCKS_PER_PAGE];
|
static cc_uint8 pal_table[PAL_TOTAL_BLOCKS / BLOCKS_PER_PAGE];
|
||||||
|
|
||||||
static void palette_alloc(CCTexture* tex, int size) {
|
|
||||||
int blocks = (size + (PAL_BLOCK_SIZE - 1)) / PAL_BLOCK_SIZE;
|
|
||||||
int addr = blockalloc_alloc(pal_table, PAL_TOTAL_BLOCKS, blocks);
|
|
||||||
if (addr == -1) return;
|
|
||||||
|
|
||||||
tex->palBase = addr;
|
|
||||||
tex->palBlocks = blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void palette_release(CCTexture* tex) {
|
|
||||||
blockalloc_dealloc(pal_table, tex->palBase, tex->palBlocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Textures--------------------------------------------------------*
|
*---------------------------------------------------------Textures--------------------------------------------------------*
|
||||||
@ -294,8 +268,8 @@ static CC_INLINE int CalcPalette(cc_uint16* palette, struct Bitmap* bmp, int row
|
|||||||
}
|
}
|
||||||
|
|
||||||
GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
|
GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
|
||||||
CCTexture* tex = Mem_TryAllocCleared(1, sizeof(CCTexture));
|
CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture));
|
||||||
if (!tex) return 0;
|
if (!tex) return NULL;
|
||||||
|
|
||||||
int dst_w = Math_NextPowOf2(bmp->width);
|
int dst_w = Math_NextPowOf2(bmp->width);
|
||||||
int dst_h = Math_NextPowOf2(bmp->height);
|
int dst_h = Math_NextPowOf2(bmp->height);
|
||||||
@ -321,12 +295,17 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
|
|||||||
tex_fmt = GL_RGBA;
|
tex_fmt = GL_RGBA;
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_alloc(tex, tex_size);
|
int blocks = SIZE_TO_BLOCKS(tex_size, TEX_BLOCK_SIZE);
|
||||||
if (!tex->texBlocks) {
|
int base = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks);
|
||||||
|
if (base < 0) {
|
||||||
Platform_Log2("No VRAM for %i x %i texture", &bmp->width, &bmp->height);
|
Platform_Log2("No VRAM for %i x %i texture", &bmp->width, &bmp->height);
|
||||||
|
Mem_Free(tex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tex->texBase = base;
|
||||||
|
tex->texBlocks = blocks;
|
||||||
|
|
||||||
int offset = tex->texBase * TEX_BLOCK_SIZE;
|
int offset = tex->texBase * TEX_BLOCK_SIZE;
|
||||||
u16* addr = (u16*)((u8*)VRAM_A + offset);
|
u16* addr = (u16*)((u8*)VRAM_A + offset);
|
||||||
u16* tmp_u16[128]; // 256 bytes
|
u16* tmp_u16[128]; // 256 bytes
|
||||||
@ -394,14 +373,18 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
|
|||||||
|
|
||||||
vramRestorePrimaryBanks(banks);
|
vramRestorePrimaryBanks(banks);
|
||||||
|
|
||||||
int sSize = (Math_ilog2(dst_w) - 3) << 20;
|
int sSize = (Math_ilog2(dst_w) - 3) << 20;
|
||||||
int tSize = (Math_ilog2(dst_h) - 3) << 23;
|
int tSize = (Math_ilog2(dst_h) - 3) << 23;
|
||||||
|
|
||||||
tex->texFormat = (offset >> 3) | sSize | tSize | (tex_fmt << 26) |
|
tex->texFormat = (offset >> 3) | sSize | tSize | (tex_fmt << 26) |
|
||||||
GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT;
|
GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT;
|
||||||
|
|
||||||
if (tex_fmt != GL_RGBA) {
|
if (tex_fmt != GL_RGBA) {
|
||||||
palette_alloc(tex, pal_count * 2);
|
blocks = SIZE_TO_BLOCKS(pal_count * 2, PAL_BLOCK_SIZE);
|
||||||
|
base = blockalloc_alloc(pal_table, PAL_TOTAL_BLOCKS, blocks);
|
||||||
|
|
||||||
|
tex->palBase = base < 0 ? 0 : base; // TODO probably not correct, but shouldn't happen in practice
|
||||||
|
tex->palBlocks = blocks;
|
||||||
offset = tex->palBase * PAL_BLOCK_SIZE;
|
offset = tex->palBase * PAL_BLOCK_SIZE;
|
||||||
|
|
||||||
vramSetBankE(VRAM_E_LCD);
|
vramSetBankE(VRAM_E_LCD);
|
||||||
@ -424,7 +407,6 @@ void Gfx_BindTexture(GfxResourceID texId) {
|
|||||||
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
|
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
|
||||||
CCTexture* tex = (CCTexture*)texId;
|
CCTexture* tex = (CCTexture*)texId;
|
||||||
|
|
||||||
int width = tex->width;
|
|
||||||
return;
|
return;
|
||||||
// TODO doesn't work without VRAM bank changing to LCD and back maybe??
|
// TODO doesn't work without VRAM bank changing to LCD and back maybe??
|
||||||
// (see what glTeximage2D does ??)
|
// (see what glTeximage2D does ??)
|
||||||
@ -445,8 +427,8 @@ void Gfx_DeleteTexture(GfxResourceID* texId) {
|
|||||||
CCTexture* tex = (CCTexture*)(*texId);
|
CCTexture* tex = (CCTexture*)(*texId);
|
||||||
|
|
||||||
if (tex) {
|
if (tex) {
|
||||||
texture_release(tex);
|
blockalloc_dealloc(tex_table, tex->texBase, tex->texBlocks);
|
||||||
palette_release(tex);
|
blockalloc_dealloc(pal_table, tex->palBase, tex->palBlocks);
|
||||||
Mem_Free(tex);
|
Mem_Free(tex);
|
||||||
}
|
}
|
||||||
*texId = NULL;
|
*texId = NULL;
|
||||||
|
@ -248,7 +248,7 @@ void FallbackFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Fallback_PlotCell(int x, int scale, const cc_uint8* rows, FallbackFont_Plotter plotter, void* ctx) {
|
static void Fallback_PlotCell(int scale, const cc_uint8* rows, FallbackFont_Plotter plotter, void* ctx) {
|
||||||
int xx, srcX, dstX;
|
int xx, srcX, dstX;
|
||||||
int yy, srcY, dstY;
|
int yy, srcY, dstY;
|
||||||
cc_uint8 src_row;
|
cc_uint8 src_row;
|
||||||
@ -260,8 +260,8 @@ static void Fallback_PlotCell(int x, int scale, const cc_uint8* rows, FallbackFo
|
|||||||
for (srcX = 0; srcX < CELL_SIZE; srcX++)
|
for (srcX = 0; srcX < CELL_SIZE; srcX++)
|
||||||
{
|
{
|
||||||
if (!(src_row & (1 << srcX))) continue;
|
if (!(src_row & (1 << srcX))) continue;
|
||||||
dstX = x + srcX * scale;
|
dstX = srcX * scale;
|
||||||
dstY = 0 + srcY * scale;
|
dstY = srcY * scale;
|
||||||
|
|
||||||
for (yy = 0; yy < scale; yy++)
|
for (yy = 0; yy < scale; yy++)
|
||||||
for (xx = 0; xx < scale; xx++)
|
for (xx = 0; xx < scale; xx++)
|
||||||
@ -272,20 +272,14 @@ static void Fallback_PlotCell(int x, int scale, const cc_uint8* rows, FallbackFo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FallbackFont_Plot(cc_string* str, FallbackFont_Plotter plotter, int scale, void* ctx) {
|
int FallbackFont_Plot(cc_uint8 c, FallbackFont_Plotter plotter, int scale, void* ctx) {
|
||||||
const cc_uint8* rows;
|
const cc_uint8* rows;
|
||||||
int i, x = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < str->length; i++)
|
if (c == ' ') return SPACE_WIDTH * scale;
|
||||||
{
|
rows = FallbackFont_GetRows(c);
|
||||||
cc_uint8 c = str->buffer[i];
|
|
||||||
if (c == ' ') { x += SPACE_WIDTH * scale; continue; }
|
|
||||||
|
|
||||||
rows = FallbackFont_GetRows(c);
|
Fallback_PlotCell(scale, rows, plotter, ctx);
|
||||||
|
return Fallback_CellWidth(rows) * scale;
|
||||||
Fallback_PlotCell(x, scale, rows, plotter, ctx);
|
|
||||||
x += Fallback_CellWidth(rows) * scale;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@ extern struct IGameComponent SystemFonts_Component;
|
|||||||
|
|
||||||
int FallbackFont_TextWidth(const struct DrawTextArgs* args);
|
int FallbackFont_TextWidth(const struct DrawTextArgs* args);
|
||||||
void FallbackFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow);
|
void FallbackFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow);
|
||||||
|
|
||||||
typedef void (*FallbackFont_Plotter)(int x, int y, void* ctx);
|
typedef void (*FallbackFont_Plotter)(int x, int y, void* ctx);
|
||||||
void FallbackFont_Plot(cc_string* str, FallbackFont_Plotter plotter, int scale, void* ctx);
|
int FallbackFont_Plot(cc_uint8 c, FallbackFont_Plotter plotter, int scale, void* ctx);
|
||||||
|
|
||||||
/* Allocates a new system font from the given arguments */
|
/* Allocates a new system font from the given arguments */
|
||||||
cc_result SysFont_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags);
|
cc_result SysFont_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags);
|
||||||
|
@ -100,7 +100,7 @@ static void Console_LoadFont(int bgId, u16* palette) {
|
|||||||
|
|
||||||
for (int i = 0; i < FONT_NUM_CHARACTERS * 8; i++)
|
for (int i = 0; i < FONT_NUM_CHARACTERS * 8; i++)
|
||||||
{
|
{
|
||||||
u8 row = default_fontTiles[i];
|
u8 row = default_fontTiles[i];
|
||||||
u32 gfx = 0;
|
u32 gfx = 0;
|
||||||
if (row & 0x01) gfx |= 0x0000000F;
|
if (row & 0x01) gfx |= 0x0000000F;
|
||||||
if (row & 0x02) gfx |= 0x000000F0;
|
if (row & 0x02) gfx |= 0x000000F0;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define blockalloc_bit(block) (1 << ((block) & 0x07))
|
#define blockalloc_bit(block) (1 << ((block) & 0x07))
|
||||||
#define BLOCKS_PER_PAGE 8
|
#define BLOCKS_PER_PAGE 8
|
||||||
|
|
||||||
|
#define SIZE_TO_BLOCKS(size, blockSize) (((size) + ((blockSize) - 1)) / (blockSize))
|
||||||
|
|
||||||
static CC_INLINE int blockalloc_can_alloc(cc_uint8* table, int beg, int blocks) {
|
static CC_INLINE int blockalloc_can_alloc(cc_uint8* table, int beg, int blocks) {
|
||||||
for (int i = beg; i < beg + blocks; i++)
|
for (int i = beg; i < beg + blocks; i++)
|
||||||
{
|
{
|
||||||
@ -44,10 +46,11 @@ static void blockalloc_dealloc(cc_uint8* table, int origin, int blocks) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: is this worth optimising to look at entire page in 0x00 and 0xFF case?
|
static CC_INLINE int blockalloc_total_free(cc_uint8* table, int maxBlocks) {
|
||||||
static int blockalloc_total_free(cc_uint8* table, int maxBlocks) {
|
|
||||||
int free_blocks = 0, i, used;
|
int free_blocks = 0, i, used;
|
||||||
cc_uint8 page;
|
cc_uint8 page;
|
||||||
|
// could be optimised to look at entire page in 0x00 and 0xFF case
|
||||||
|
// but this method is called so infrequently, not really worth it
|
||||||
|
|
||||||
for (i = 0; i < maxBlocks; i++)
|
for (i = 0; i < maxBlocks; i++)
|
||||||
{
|
{
|
||||||
@ -55,7 +58,6 @@ static int blockalloc_total_free(cc_uint8* table, int maxBlocks) {
|
|||||||
used = page & blockalloc_bit(i);
|
used = page & blockalloc_bit(i);
|
||||||
|
|
||||||
if (!used) free_blocks++;
|
if (!used) free_blocks++;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return free_blocks;
|
return free_blocks;
|
||||||
}
|
}
|
||||||
|
@ -182,24 +182,15 @@ static void texmem_free(cc_uint8* ptr, cc_uint32 size) {
|
|||||||
texmem_used[page + i] = 0;
|
texmem_used[page + i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_uint32 texmem_total_free(void) {
|
static int texmem_total_free(void) {
|
||||||
cc_uint32 free = 0;
|
int free = 0;
|
||||||
for (cc_uint32 page = 0; page < texmem_pages; page++)
|
for (cc_uint32 page = 0; page < texmem_pages; page++)
|
||||||
{
|
{
|
||||||
if (!texmem_used[page]) free += TEXMEM_PAGE_SIZE;
|
if (!texmem_used[page]) free++;
|
||||||
}
|
}
|
||||||
return free;
|
return free;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_uint32 texmem_total_used(void) {
|
|
||||||
cc_uint32 used = 0;
|
|
||||||
for (cc_uint32 page = 0; page < texmem_pages; page++)
|
|
||||||
{
|
|
||||||
if (texmem_used[page]) used += TEXMEM_PAGE_SIZE;
|
|
||||||
}
|
|
||||||
return used;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------General---------------------------------------------------------*
|
*---------------------------------------------------------General---------------------------------------------------------*
|
||||||
@ -1053,10 +1044,13 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) {
|
|||||||
|
|
||||||
void Gfx_GetApiInfo(cc_string* info) {
|
void Gfx_GetApiInfo(cc_string* info) {
|
||||||
int freeMem = texmem_total_free();
|
int freeMem = texmem_total_free();
|
||||||
int usedMem = texmem_total_used();
|
int usedMem = texmem_pages - freeMem;
|
||||||
|
|
||||||
float freeMemMB = freeMem / (1024.0 * 1024.0);
|
freeMem *= TEXMEM_PAGE_SIZE;
|
||||||
float usedMemMB = usedMem / (1024.0 * 1024.0);
|
usedMem *= TEXMEM_PAGE_SIZE;
|
||||||
|
|
||||||
|
float freeMemMB = freeMem / (1024.0f * 1024.0f);
|
||||||
|
float usedMemMB = usedMem / (1024.0f * 1024.0f);
|
||||||
|
|
||||||
String_AppendConst(info, "-- Using Dreamcast --\n");
|
String_AppendConst(info, "-- Using Dreamcast --\n");
|
||||||
String_AppendConst(info, "GPU: PowerVR2 CLX2 100mHz\n");
|
String_AppendConst(info, "GPU: PowerVR2 CLX2 100mHz\n");
|
||||||
|
@ -58,10 +58,15 @@ extern cc_bool window_inited;
|
|||||||
|
|
||||||
#define MAX_ONSCREEN_LINES 17
|
#define MAX_ONSCREEN_LINES 17
|
||||||
#define ONSCREEN_LINE_HEIGHT (24 + 2) // 8 * 3 text, plus 2 pixel padding
|
#define ONSCREEN_LINE_HEIGHT (24 + 2) // 8 * 3 text, plus 2 pixel padding
|
||||||
#define Onscreen_LineOffset(y) ((10 + y + (str_offset * ONSCREEN_LINE_HEIGHT)) * vid_mode->width)
|
#define Onscreen_LineOffset(y) ((y) * vid_mode->width)
|
||||||
|
|
||||||
|
struct LogPosition { int x, y; };
|
||||||
static void PlotOnscreen(int x, int y, void* ctx) {
|
static void PlotOnscreen(int x, int y, void* ctx) {
|
||||||
|
struct LogPosition* pos = ctx;
|
||||||
|
|
||||||
|
x += pos->x;
|
||||||
if (x >= vid_mode->width) return;
|
if (x >= vid_mode->width) return;
|
||||||
|
y += pos->y;
|
||||||
|
|
||||||
uint32 line_offset = Onscreen_LineOffset(y);
|
uint32 line_offset = Onscreen_LineOffset(y);
|
||||||
vram_s[line_offset + x] = 0xFFFF;
|
vram_s[line_offset + x] = 0xFFFF;
|
||||||
@ -77,13 +82,21 @@ static void LogOnscreen(const char* msg, int len) {
|
|||||||
if (log_timestamp) String_Format2(&str, "[%p2.%p3] ", &secs, &ms);
|
if (log_timestamp) String_Format2(&str, "[%p2.%p3] ", &secs, &ms);
|
||||||
String_AppendAll(&str, msg, len);
|
String_AppendAll(&str, msg, len);
|
||||||
|
|
||||||
short* dst = vram_s + Onscreen_LineOffset(0);
|
struct LogPosition pos;
|
||||||
|
pos.x = 0;
|
||||||
|
pos.y = 10 + (str_offset * ONSCREEN_LINE_HEIGHT);
|
||||||
|
|
||||||
|
str_offset = (str_offset + 1) % MAX_ONSCREEN_LINES;
|
||||||
|
|
||||||
|
short* dst = vram_s + Onscreen_LineOffset(pos.y);
|
||||||
int num_pixels = ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width;
|
int num_pixels = ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width;
|
||||||
for (int i = 0; i < num_pixels; i++) dst[i] = 0;
|
for (int i = 0; i < num_pixels; i++) dst[i] = 0;
|
||||||
//sq_set16(vram_s + Onscreen_LineOffset(0), 0, ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width);
|
//sq_set16(vram_s + Onscreen_LineOffset(pos.y), 0, ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width);
|
||||||
|
|
||||||
FallbackFont_Plot(&str, PlotOnscreen, 3, NULL);
|
for (int i = 0; i < str.length; i++)
|
||||||
str_offset = (str_offset + 1) % MAX_ONSCREEN_LINES;
|
{
|
||||||
|
pos.x += FallbackFont_Plot((cc_uint8)str.buffer[i], PlotOnscreen, 3, &pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_Log(const char* msg, int len) {
|
void Platform_Log(const char* msg, int len) {
|
||||||
|
@ -168,38 +168,28 @@ typedef struct CCTexture {
|
|||||||
#define TEX_TOTAL_BLOCKS (TEXTURE_REGION_SIZE / TEX_BLOCK_SIZE)
|
#define TEX_TOTAL_BLOCKS (TEXTURE_REGION_SIZE / TEX_BLOCK_SIZE)
|
||||||
static cc_uint8 tex_table[TEX_TOTAL_BLOCKS / BLOCKS_PER_PAGE];
|
static cc_uint8 tex_table[TEX_TOTAL_BLOCKS / BLOCKS_PER_PAGE];
|
||||||
|
|
||||||
static cc_bool texture_alloc(CCTexture* tex, int width, int height) {
|
|
||||||
int size = width * height * 2;
|
|
||||||
|
|
||||||
int blocks = (size + (TEX_BLOCK_SIZE - 1)) / TEX_BLOCK_SIZE;
|
|
||||||
int addr = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks);
|
|
||||||
if (addr == -1) return false;
|
|
||||||
|
|
||||||
tex->width = width;
|
|
||||||
tex->height = height;
|
|
||||||
tex->offset = addr;
|
|
||||||
tex->blocks = blocks;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void texture_release(CCTexture* tex) {
|
|
||||||
blockalloc_dealloc(tex_table, tex->offset, tex->blocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
|
GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
|
||||||
CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture));
|
CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture));
|
||||||
if (!tex) return NULL;
|
if (!tex) return NULL;
|
||||||
|
|
||||||
if (!texture_alloc(tex, bmp->width, bmp->height)) {
|
int width = bmp->width, height = bmp->height;
|
||||||
|
int blocks = SIZE_TO_BLOCKS(width * height * 2, TEX_BLOCK_SIZE);
|
||||||
|
int addr = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks);
|
||||||
|
|
||||||
|
if (addr == -1) {
|
||||||
Platform_LogConst("OUT OF VRAM");
|
Platform_LogConst("OUT OF VRAM");
|
||||||
Mem_Free(tex);
|
Mem_Free(tex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tex->width = width;
|
||||||
|
tex->height = height;
|
||||||
|
tex->offset = addr;
|
||||||
|
tex->blocks = blocks;
|
||||||
|
|
||||||
int vram_free = blockalloc_total_free(tex_table, TEX_TOTAL_BLOCKS) * TEX_BLOCK_SIZE;
|
int vram_free = blockalloc_total_free(tex_table, TEX_TOTAL_BLOCKS) * TEX_BLOCK_SIZE;
|
||||||
Platform_Log1("VRAM left: %i bytes", &vram_free);
|
Platform_Log1("VRAM left: %i bytes", &vram_free);
|
||||||
|
|
||||||
int width = bmp->width, height = bmp->height;
|
|
||||||
cc_uint8* tmp = CCTexture_Addr(tex);
|
cc_uint8* tmp = CCTexture_Addr(tex);
|
||||||
cc_uint16* src = bmp->scan0;
|
cc_uint16* src = bmp->scan0;
|
||||||
cc_uint16* dst = (cc_uint16*)tmp;
|
cc_uint16* dst = (cc_uint16*)tmp;
|
||||||
@ -226,10 +216,10 @@ void Gfx_BindTexture(GfxResourceID texId) {
|
|||||||
|
|
||||||
void Gfx_DeleteTexture(GfxResourceID* texId) {
|
void Gfx_DeleteTexture(GfxResourceID* texId) {
|
||||||
CCTexture* tex = *texId;
|
CCTexture* tex = *texId;
|
||||||
if (tex) {
|
if (!tex) return;
|
||||||
texture_release(tex);
|
|
||||||
Mem_Free(tex);
|
blockalloc_dealloc(tex_table, tex->offset, tex->blocks);
|
||||||
}
|
Mem_Free(tex);
|
||||||
*texId = NULL;
|
*texId = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user