Allow specifying palette, autosort, memory options via glKosInitEx
This commit is contained in:
parent
8f26e9c364
commit
588c082ec8
27
GL/flush.c
27
GL/flush.c
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <kos.h>
|
#include <kos.h>
|
||||||
|
|
||||||
|
#include "../include/glkos.h"
|
||||||
#include "../containers/aligned_vector.h"
|
#include "../containers/aligned_vector.h"
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
#include "profiler.h"
|
#include "profiler.h"
|
||||||
|
@ -38,14 +39,14 @@ static void pvr_list_submit(void *src, int n) {
|
||||||
d[0] = d[8] = 0;
|
d[0] = d[8] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _glInitPVR() {
|
static void _glInitPVR(GLboolean autosort) {
|
||||||
pvr_init_params_t params = {
|
pvr_init_params_t params = {
|
||||||
/* Enable opaque and translucent polygons with size 32 and 32 */
|
/* Enable opaque and translucent polygons with size 32 and 32 */
|
||||||
{PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32},
|
{PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32},
|
||||||
PVR_VERTEX_BUF_SIZE, /* Vertex buffer size */
|
PVR_VERTEX_BUF_SIZE, /* Vertex buffer size */
|
||||||
0, /* No DMA */
|
0, /* No DMA */
|
||||||
0, /* No FSAA */
|
0, /* No FSAA */
|
||||||
1 /* Disable translucent auto-sorting to match traditional GL */
|
(autosort) ? 0 : 1 /* Disable translucent auto-sorting to match traditional GL */
|
||||||
};
|
};
|
||||||
|
|
||||||
pvr_init(¶ms);
|
pvr_init(¶ms);
|
||||||
|
@ -75,10 +76,16 @@ void APIENTRY glFinish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void APIENTRY glKosInit() {
|
void APIENTRY glKosInitConfig(GLdcConfig* config) {
|
||||||
|
config->autosort_enabled = GL_FALSE;
|
||||||
|
config->initial_vbuf_capacity = 256;
|
||||||
|
config->internal_palette_format = GL_RGBA4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void APIENTRY glKosInitEx(GLdcConfig* config) {
|
||||||
TRACE();
|
TRACE();
|
||||||
|
|
||||||
_glInitPVR();
|
_glInitPVR(config->autosort_enabled);
|
||||||
|
|
||||||
_glInitMatrices();
|
_glInitMatrices();
|
||||||
_glInitAttributePointers();
|
_glInitAttributePointers();
|
||||||
|
@ -87,6 +94,8 @@ void APIENTRY glKosInit() {
|
||||||
_glInitImmediateMode();
|
_glInitImmediateMode();
|
||||||
_glInitFramebuffers();
|
_glInitFramebuffers();
|
||||||
|
|
||||||
|
_glSetInternalPaletteFormat(GL_RGBA4);
|
||||||
|
|
||||||
_glInitTextures();
|
_glInitTextures();
|
||||||
|
|
||||||
OP_LIST.list_type = PVR_LIST_OP_POLY;
|
OP_LIST.list_type = PVR_LIST_OP_POLY;
|
||||||
|
@ -96,6 +105,16 @@ void APIENTRY glKosInit() {
|
||||||
aligned_vector_init(&OP_LIST.vector, sizeof(ClipVertex));
|
aligned_vector_init(&OP_LIST.vector, sizeof(ClipVertex));
|
||||||
aligned_vector_init(&PT_LIST.vector, sizeof(ClipVertex));
|
aligned_vector_init(&PT_LIST.vector, sizeof(ClipVertex));
|
||||||
aligned_vector_init(&TR_LIST.vector, sizeof(ClipVertex));
|
aligned_vector_init(&TR_LIST.vector, sizeof(ClipVertex));
|
||||||
|
|
||||||
|
aligned_vector_reserve(&OP_LIST.vector, config->initial_vbuf_capacity);
|
||||||
|
aligned_vector_reserve(&PT_LIST.vector, config->initial_vbuf_capacity);
|
||||||
|
aligned_vector_reserve(&TR_LIST.vector, config->initial_vbuf_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void APIENTRY glKosInit() {
|
||||||
|
GLdcConfig config;
|
||||||
|
glKosInitConfig(&config);
|
||||||
|
glKosInitEx(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define QACRTA ((((unsigned int)0x10000000)>>26)<<2)&0x1c
|
#define QACRTA ((((unsigned int)0x10000000)>>26)<<2)&0x1c
|
||||||
|
|
|
@ -147,6 +147,7 @@ TextureObject* _glGetBoundTexture();
|
||||||
GLubyte _glGetActiveTexture();
|
GLubyte _glGetActiveTexture();
|
||||||
GLuint _glGetActiveClientTexture();
|
GLuint _glGetActiveClientTexture();
|
||||||
TexturePalette* _glGetSharedPalette(GLshort bank);
|
TexturePalette* _glGetSharedPalette(GLshort bank);
|
||||||
|
void _glSetInternalPaletteFormat(GLenum val);
|
||||||
|
|
||||||
GLboolean _glIsSharedTexturePaletteEnabled();
|
GLboolean _glIsSharedTexturePaletteEnabled();
|
||||||
void _glApplyColorTable(TexturePalette *palette);
|
void _glApplyColorTable(TexturePalette *palette);
|
||||||
|
|
25
GL/texture.c
25
GL/texture.c
|
@ -24,9 +24,13 @@ static GLuint _determinePVRFormat(GLint internalFormat, GLenum type);
|
||||||
|
|
||||||
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )
|
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )
|
||||||
|
|
||||||
|
|
||||||
|
#define _PACK4(v) ((v * 0xF) / 0xFF)
|
||||||
|
#define PACK_ARGB4444(a,r,g,b) (_PACK4(a) << 12) | (_PACK4(r) << 8) | (_PACK4(g) << 4) | (_PACK4(b))
|
||||||
|
|
||||||
static GLboolean BANKS_USED[4]; // Each time a 256 colour bank is used, this is set to true
|
static GLboolean BANKS_USED[4]; // Each time a 256 colour bank is used, this is set to true
|
||||||
static GLboolean SUBBANKS_USED[4][16]; // 4 counts of the used 16 colour banks within the 256 ones
|
static GLboolean SUBBANKS_USED[4][16]; // 4 counts of the used 16 colour banks within the 256 ones
|
||||||
|
static GLenum INTERNAL_PALETTE_FORMAT = GL_RGBA4;
|
||||||
|
|
||||||
static TexturePalette* _initTexturePalette() {
|
static TexturePalette* _initTexturePalette() {
|
||||||
TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette));
|
TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette));
|
||||||
|
@ -100,6 +104,17 @@ TexturePalette* _glGetSharedPalette(GLshort bank) {
|
||||||
return SHARED_PALETTES[bank];
|
return SHARED_PALETTES[bank];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _glSetInternalPaletteFormat(GLenum val) {
|
||||||
|
INTERNAL_PALETTE_FORMAT = val;
|
||||||
|
|
||||||
|
if(INTERNAL_PALETTE_FORMAT == GL_RGBA4) {
|
||||||
|
pvr_set_pal_format(PVR_PAL_ARGB4444);
|
||||||
|
} else {
|
||||||
|
assert(INTERNAL_PALETTE_FORMAT == GL_RGBA8);
|
||||||
|
pvr_set_pal_format(PVR_PAL_ARGB8888);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _glApplyColorTable(TexturePalette* src) {
|
void _glApplyColorTable(TexturePalette* src) {
|
||||||
/*
|
/*
|
||||||
* FIXME:
|
* FIXME:
|
||||||
|
@ -110,13 +125,15 @@ void _glApplyColorTable(TexturePalette* src) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pvr_set_pal_format(PVR_PAL_ARGB8888);
|
|
||||||
|
|
||||||
GLushort i;
|
GLushort i;
|
||||||
GLushort offset = src->size * src->bank;
|
GLushort offset = src->size * src->bank;
|
||||||
for(i = 0; i < src->width; ++i) {
|
for(i = 0; i < src->width; ++i) {
|
||||||
GLubyte* entry = &src->data[i * 4];
|
GLubyte* entry = &src->data[i * 4];
|
||||||
pvr_set_pal_entry(offset + i, PACK_ARGB8888(entry[3], entry[0], entry[1], entry[2]));
|
if(INTERNAL_PALETTE_FORMAT == GL_RGBA8) {
|
||||||
|
pvr_set_pal_entry(offset + i, PACK_ARGB8888(entry[3], entry[0], entry[1], entry[2]));
|
||||||
|
} else {
|
||||||
|
pvr_set_pal_entry(offset + i, PACK_ARGB4444(entry[3], entry[0], entry[1], entry[2]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -390,9 +390,6 @@ __BEGIN_DECLS
|
||||||
#define GLAPI extern
|
#define GLAPI extern
|
||||||
#define APIENTRY
|
#define APIENTRY
|
||||||
|
|
||||||
/* Initialize the GL pipeline. GL will initialize the PVR. */
|
|
||||||
GLAPI void APIENTRY glKosInit();
|
|
||||||
|
|
||||||
GLAPI void APIENTRY glFlush();
|
GLAPI void APIENTRY glFlush();
|
||||||
GLAPI void APIENTRY glFinish();
|
GLAPI void APIENTRY glFinish();
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,34 @@ __BEGIN_DECLS
|
||||||
#define GL_UNSIGNED_BYTE_TWID_KOS 0xEEFB
|
#define GL_UNSIGNED_BYTE_TWID_KOS 0xEEFB
|
||||||
|
|
||||||
|
|
||||||
GLAPI void APIENTRY glKosSwapBuffers();
|
/* Initialize the GL pipeline. GL will initialize the PVR. */
|
||||||
|
GLAPI void APIENTRY glKosInit();
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/* If GL_TRUE, enables pvr autosorting, this *will* break glDepthFunc/glDepthTest */
|
||||||
|
GLboolean autosort_enabled;
|
||||||
|
|
||||||
|
/* The internal format for paletted textures, must be GL_RGBA4 (default) or GL_RGBA8 */
|
||||||
|
GLenum internal_palette_format;
|
||||||
|
|
||||||
|
/* Initial capacity of each of the OP, TR and PT lists in vertices */
|
||||||
|
GLuint initial_vbuf_capacity;
|
||||||
|
} GLdcConfig;
|
||||||
|
|
||||||
|
|
||||||
|
GLAPI void APIENTRY glKosInitConfig(GLdcConfig* config);
|
||||||
|
|
||||||
|
/* Usage:
|
||||||
|
*
|
||||||
|
* GLdcConfig config;
|
||||||
|
* glKosInitConfig(&config);
|
||||||
|
*
|
||||||
|
* config.autosort_enabled = GL_TRUE;
|
||||||
|
*
|
||||||
|
* glKosInitEx(&config);
|
||||||
|
*/
|
||||||
|
GLAPI void APIENTRY glKosInitEx(GLdcConfig* config);
|
||||||
|
GLAPI void APIENTRY glKosSwapBuffers();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CUSTOM EXTENSION multiple_shared_palette_KOS
|
* CUSTOM EXTENSION multiple_shared_palette_KOS
|
||||||
|
|
|
@ -329,7 +329,12 @@ void DrawGLScene()
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
glKosInit();
|
GLdcConfig config;
|
||||||
|
glKosInitConfig(&config);
|
||||||
|
|
||||||
|
config.internal_palette_format = GL_RGBA8;
|
||||||
|
|
||||||
|
glKosInitEx(&config);
|
||||||
|
|
||||||
InitGL(640, 480);
|
InitGL(640, 480);
|
||||||
ReSizeGLScene(640, 480);
|
ReSizeGLScene(640, 480);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user