mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-08 23:10:52 -04:00
Dreamcast: Textures can load from disc, and don't have red/blue swapped now
This commit is contained in:
parent
13c79e1e50
commit
07bf145ad7
@ -365,6 +365,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
|
||||
if (res) return res;
|
||||
if (!Png_Detect(tmp, PNG_SIG_SIZE)) return PNG_ERR_INVALID_SIG;
|
||||
|
||||
col = 0xFF; /* Unknown colour space */
|
||||
trnsCol = BITMAPCOLOR_BLACK;
|
||||
for (i = 0; i < PNG_PALETTE; i++) { palette[i] = BITMAPCOLOR_BLACK; }
|
||||
|
||||
|
@ -278,6 +278,12 @@ typedef cc_uint8 cc_bool;
|
||||
#define CC_BUILD_PSVITA
|
||||
#define CC_BUILD_LOWMEM
|
||||
#undef CC_BUILD_FREETYPE
|
||||
#elif defined _arch_dreamcast
|
||||
#define CC_BUILD_HTTPCLIENT
|
||||
#define CC_BUILD_OPENAL
|
||||
#define CC_BUILD_DREAMCAST
|
||||
#define CC_BUILD_LOWMEM
|
||||
#undef CC_BUILD_FREETYPE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "GL/glkos.h"
|
||||
#include "GL/glext.h"
|
||||
#include <malloc.h>
|
||||
#define PIXEL_FORMAT GL_RGBA
|
||||
|
||||
#define TRANSFER_FORMAT GL_UNSIGNED_BYTE
|
||||
/* Current format and size of vertices */
|
||||
@ -224,48 +223,43 @@ void Gfx_BindTexture(GfxResourceID texId) {
|
||||
int tex = texId;
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)texId);
|
||||
}
|
||||
static void ConvertTexture(cc_uint16* dst, struct Bitmap* bmp) {
|
||||
cc_uint8* src = (cc_uint8*)bmp->scan0;
|
||||
|
||||
for (int y = 0; y < bmp->height; y++)
|
||||
{
|
||||
for (int x = 0; x < bmp->width; x++, dst++, src += 4)
|
||||
{
|
||||
// B8 G8 R8 A8 > B4 G4 R4 A4
|
||||
*dst = ((src[0] & 0xF0) >> 4) | (src[1] & 0xF0) | ((src[2] & 0xF0) << 4) | ((src[3] & 0xF0) << 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) {
|
||||
GLuint texId;
|
||||
glGenTextures(1, &texId);
|
||||
glBindTexture(GL_TEXTURE_2D, texId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
if (!Math_IsPowOf2(bmp->width) || !Math_IsPowOf2(bmp->height)) {
|
||||
Logger_Abort("Textures must have power of two dimensions");
|
||||
}
|
||||
|
||||
void* temp = Mem_Alloc(bmp->width * bmp->height, 2, "texture conversion buffer");
|
||||
ConvertTexture(temp, bmp);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp->width, bmp->height, 0, GL_BGRA,
|
||||
GL_UNSIGNED_SHORT_4_4_4_4_REV, temp);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp->width, bmp->height, 0, PIXEL_FORMAT, GL_UNSIGNED_BYTE, bmp->scan0);
|
||||
|
||||
Mem_Free(temp);
|
||||
return texId;
|
||||
}
|
||||
|
||||
#define UPDATE_FAST_SIZE (64 * 64)
|
||||
static CC_NOINLINE void UpdateTextureSlow(int x, int y, struct Bitmap* part, int rowWidth) {
|
||||
BitmapCol buffer[UPDATE_FAST_SIZE];
|
||||
void* ptr = (void*)buffer;
|
||||
int count = part->width * part->height;
|
||||
|
||||
/* cannot allocate memory on the stack for very big updates */
|
||||
if (count > UPDATE_FAST_SIZE) {
|
||||
ptr = Mem_Alloc(count, 4, "Gfx_UpdateTexture temp");
|
||||
}
|
||||
|
||||
CopyTextureData(ptr, part->width << 2, part, rowWidth << 2);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, part->width, part->height, PIXEL_FORMAT, GL_UNSIGNED_BYTE, ptr);
|
||||
if (count > UPDATE_FAST_SIZE) Mem_Free(ptr);
|
||||
}
|
||||
|
||||
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)texId);
|
||||
/* TODO: Use GL_UNPACK_ROW_LENGTH for Desktop OpenGL */
|
||||
|
||||
if (part->width == rowWidth) {
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, part->width, part->height, PIXEL_FORMAT, GL_UNSIGNED_BYTE, part->scan0);
|
||||
} else {
|
||||
UpdateTextureSlow(x, y, part, rowWidth);
|
||||
}
|
||||
// TODO: Doesn't work and triggers assertion failure
|
||||
// https://github.com/Kazade/GLdc/blob/master/GL/texture.c#L1895
|
||||
}
|
||||
|
||||
void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* part, cc_bool mipmaps) {
|
||||
@ -321,7 +315,7 @@ void Gfx_SetFogEnd(float value) {
|
||||
}
|
||||
|
||||
void Gfx_SetFogMode(FogFunc func) {
|
||||
static GLint modes[3] = { GL_LINEAR, GL_EXP, GL_EXP2 };
|
||||
static GLint modes[] = { GL_LINEAR, GL_EXP, GL_EXP2 };
|
||||
if (func == gfx_fogMode) return;
|
||||
|
||||
glFogi(GL_FOG_MODE, modes[func]);
|
||||
|
@ -51,6 +51,7 @@ void Gfx_Create(void) {
|
||||
Gfx.MaxTexWidth = 512;
|
||||
Gfx.MaxTexHeight = 512;
|
||||
Gfx.Created = true;
|
||||
gfx_vsync = true;
|
||||
|
||||
InitGX();
|
||||
Gfx_RestoreState();
|
||||
|
@ -71,8 +71,14 @@ void DateTime_CurrentLocal(struct DateTime* t) {
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static const cc_string root_path = String_FromConst("/cd/");
|
||||
|
||||
static void GetNativePath(char* str, const cc_string* path) {
|
||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||
str += root_path.length;
|
||||
|
||||
String_EncodeUtf8(str, path);
|
||||
|
||||
}
|
||||
|
||||
cc_result Directory_Create(const cc_string* path) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user