mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Document web requests/responses directly in LWeb.c
This commit is contained in:
parent
c45a8149f7
commit
39627876d2
11 changed files with 123 additions and 157 deletions
|
@ -273,7 +273,7 @@ static void InitWebSounds(void) {
|
||||||
board = &digBoard;
|
board = &digBoard;
|
||||||
} else {
|
} else {
|
||||||
group = &board->groups[sounds_list[i].group];
|
group = &board->groups[sounds_list[i].group];
|
||||||
group->sounds[group->count++].data = sounds_list[i].name;
|
group->sounds[group->count++].chunk.data = sounds_list[i].name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "../third_party/gldc/gldc.h"
|
|
||||||
#include "../third_party/gldc/src/private.h"
|
|
||||||
#include "../third_party/gldc/src/sh4.h"
|
#include "../third_party/gldc/src/sh4.h"
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <kos.h>
|
#include <kos.h>
|
||||||
|
@ -337,7 +335,8 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8
|
||||||
GLuint texId = gldcGenTexture();
|
GLuint texId = gldcGenTexture();
|
||||||
gldcBindTexture(texId);
|
gldcBindTexture(texId);
|
||||||
|
|
||||||
gldcAllocTexture(bmp->width, bmp->height, PVR_TXRFMT_ARGB4444);
|
int res = gldcAllocTexture(bmp->width, bmp->height, PVR_TXRFMT_ARGB4444);
|
||||||
|
if (res) { Platform_LogConst("Out of PVR VRAM!"); return 0; }
|
||||||
|
|
||||||
void* pixels;
|
void* pixels;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
43
src/LWeb.c
43
src/LWeb.c
|
@ -211,6 +211,7 @@ static cc_bool Json_Handle(cc_uint8* data, cc_uint32 len,
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static char servicesBuffer[FILENAME_SIZE];
|
static char servicesBuffer[FILENAME_SIZE];
|
||||||
static cc_string servicesServer = String_FromArray(servicesBuffer);
|
static cc_string servicesServer = String_FromArray(servicesBuffer);
|
||||||
|
static struct StringsBuffer ccCookies;
|
||||||
|
|
||||||
static void LWebTask_Reset(struct LWebTask* task) {
|
static void LWebTask_Reset(struct LWebTask* task) {
|
||||||
task->completed = false;
|
task->completed = false;
|
||||||
|
@ -244,7 +245,16 @@ void LWebTasks_Init(void) {
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------GetTokenTask------------------------------------------------------*
|
*-------------------------------------------------------GetTokenTask------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static struct StringsBuffer ccCookies;
|
/*
|
||||||
|
< GET /api/login/
|
||||||
|
|
||||||
|
> {
|
||||||
|
> "username": null,
|
||||||
|
> "authenticated": false,
|
||||||
|
> "token": "f033ab37c30201f73f142449d037028d",
|
||||||
|
> "errors": []
|
||||||
|
>}
|
||||||
|
*/
|
||||||
struct GetTokenTaskData GetTokenTask;
|
struct GetTokenTaskData GetTokenTask;
|
||||||
|
|
||||||
static void GetTokenTask_OnValue(struct JsonContext* ctx, const cc_string* str) {
|
static void GetTokenTask_OnValue(struct JsonContext* ctx, const cc_string* str) {
|
||||||
|
@ -286,6 +296,17 @@ void GetTokenTask_Run(void) {
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*--------------------------------------------------------SignInTask-------------------------------------------------------*
|
*--------------------------------------------------------SignInTask-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
/*
|
||||||
|
< POST /api/login/
|
||||||
|
< username=AndrewPH&password=examplePassW0rd&token=f033ab37c30201f73f142449d037028d
|
||||||
|
|
||||||
|
> {
|
||||||
|
> "username": "AndrewPH",
|
||||||
|
> "authenticated": true,
|
||||||
|
> "token": "33e75ff09dd601bbe69f351039152189",
|
||||||
|
> "errors": []
|
||||||
|
> }
|
||||||
|
*/
|
||||||
struct SignInTaskData SignInTask;
|
struct SignInTaskData SignInTask;
|
||||||
|
|
||||||
static void SignInTask_LogError(const cc_string* str) {
|
static void SignInTask_LogError(const cc_string* str) {
|
||||||
|
@ -356,6 +377,13 @@ void SignInTask_Run(const cc_string* user, const cc_string* pass, const cc_strin
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------FetchServerTask-----------------------------------------------------*
|
*-----------------------------------------------------FetchServerTask-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
/*
|
||||||
|
< GET /api/server/a709fabdf836a2a102c952442bf2dab1
|
||||||
|
|
||||||
|
> { "servers" : [
|
||||||
|
> {"hash": "a709fabdf836a2a102c952442bf2dab1", "maxplayers": 70, "name": "Freebuild server", "players": 5, "software": "MCGalaxy", "uptime": 185447, "country_abbr": "CA"},
|
||||||
|
> ]}
|
||||||
|
*/
|
||||||
struct FetchServerData FetchServerTask;
|
struct FetchServerData FetchServerTask;
|
||||||
static struct ServerInfo* curServer;
|
static struct ServerInfo* curServer;
|
||||||
|
|
||||||
|
@ -429,6 +457,14 @@ void FetchServerTask_Run(const cc_string* hash) {
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------FetchServersTask----------------------------------------------------*
|
*-----------------------------------------------------FetchServersTask----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
/*
|
||||||
|
< GET /api/servers/
|
||||||
|
|
||||||
|
> { "servers" : [
|
||||||
|
> {"hash": "a709fabdf836a2a102c952442bf2dab1", "maxplayers": 70, "name": "Freebuild server", "players": 5, "software": "MCGalaxy", "uptime": 185447, "country_abbr": "CA"},
|
||||||
|
> {"hash": "23860c5e192cbaa4698408338efd61cc", "maxplayers": 30, "name": "Other server", "players": 0, software: "", "uptime": 54661, "country_abbr": "T1"}
|
||||||
|
> ]}
|
||||||
|
*/
|
||||||
struct FetchServersData FetchServersTask;
|
struct FetchServersData FetchServersTask;
|
||||||
static void FetchServersTask_Count(struct JsonContext* ctx) {
|
static void FetchServersTask_Count(struct JsonContext* ctx) {
|
||||||
/* JSON is expected in this format: */
|
/* JSON is expected in this format: */
|
||||||
|
@ -496,6 +532,11 @@ void FetchServersTask_ResetOrder(void) {
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------CheckUpdateTask-----------------------------------------------------*
|
*-----------------------------------------------------CheckUpdateTask-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
/*
|
||||||
|
< GET /builds.json
|
||||||
|
|
||||||
|
> {"latest_ts": 1718187640.9587102, "release_ts": 1693265172.020421, "release_version": "1.3.6"}
|
||||||
|
*/
|
||||||
struct CheckUpdateData CheckUpdateTask;
|
struct CheckUpdateData CheckUpdateTask;
|
||||||
static char relVersionBuffer[16];
|
static char relVersionBuffer[16];
|
||||||
|
|
||||||
|
|
84
third_party/gldc/gldc.h
vendored
84
third_party/gldc/gldc.h
vendored
|
@ -1,84 +0,0 @@
|
||||||
/* KallistiGL for KallistiOS ##version##
|
|
||||||
|
|
||||||
libgl/gl.h
|
|
||||||
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
|
|
||||||
Copyright (C) 2014, 2016 Lawrence Sebald
|
|
||||||
|
|
||||||
Some functionality adapted from the original KOS libgl:
|
|
||||||
Copyright (C) 2001 Dan Potter
|
|
||||||
Copyright (C) 2002 Benoit Miller
|
|
||||||
|
|
||||||
This API implements much but not all of the OpenGL 1.1 for KallistiOS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GL_GL_H
|
|
||||||
#define __GL_GL_H
|
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
__BEGIN_DECLS
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
/* Scissor box */
|
|
||||||
#define GL_SCISSOR_TEST 0x0008 /* capability bit */
|
|
||||||
|
|
||||||
/* TextureMagFilter */
|
|
||||||
#define GL_NEAREST 0x2600
|
|
||||||
#define GL_LINEAR 0x2601
|
|
||||||
|
|
||||||
#define GL_SHADE_MODEL 0x0b54
|
|
||||||
#define GL_FLAT 0x1d00
|
|
||||||
#define GL_SMOOTH 0x1d01
|
|
||||||
|
|
||||||
/* Data types */
|
|
||||||
#define GL_BYTE 0x1400
|
|
||||||
#define GL_UNSIGNED_BYTE 0x1401
|
|
||||||
#define GL_SHORT 0x1402
|
|
||||||
#define GL_UNSIGNED_SHORT 0x1403
|
|
||||||
#define GL_INT 0x1404
|
|
||||||
#define GL_UNSIGNED_INT 0x1405
|
|
||||||
#define GL_FLOAT 0x1406
|
|
||||||
|
|
||||||
/* ErrorCode */
|
|
||||||
#define GL_INVALID_VALUE 0x0501
|
|
||||||
#define GL_OUT_OF_MEMORY 0x0505
|
|
||||||
|
|
||||||
#define GLushort unsigned short
|
|
||||||
#define GLuint unsigned int
|
|
||||||
#define GLenum unsigned int
|
|
||||||
#define GLubyte unsigned char
|
|
||||||
#define GLboolean unsigned char
|
|
||||||
|
|
||||||
#define GL_FALSE 0
|
|
||||||
#define GL_TRUE 1
|
|
||||||
|
|
||||||
#define GLAPI extern
|
|
||||||
#define APIENTRY
|
|
||||||
#define GL_NEARZ_CLIPPING_KOS 0xEEFA
|
|
||||||
|
|
||||||
/* Depth Testing */
|
|
||||||
GLAPI void glClearDepth(float depth);
|
|
||||||
|
|
||||||
GLAPI GLuint gldcGenTexture(void);
|
|
||||||
GLAPI void gldcDeleteTexture(GLuint texture);
|
|
||||||
GLAPI void gldcBindTexture(GLuint texture);
|
|
||||||
|
|
||||||
/* Loads texture from SH4 RAM into PVR VRAM */
|
|
||||||
GLAPI int gldcAllocTexture(int w, int h, int format);
|
|
||||||
GLAPI void gldcGetTexture(void** data, int* width, int* height);
|
|
||||||
|
|
||||||
GLAPI void glViewport(int x, int y, int width, int height);
|
|
||||||
|
|
||||||
GLAPI void glScissor(int x, int y, int width, int height);
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize the GL pipeline. GL will initialize the PVR. */
|
|
||||||
GLAPI void glKosInit();
|
|
||||||
GLAPI void glKosSwapBuffers();
|
|
||||||
|
|
||||||
/* Memory allocation extension (GL_KOS_texture_memory_management) */
|
|
||||||
GLAPI void glDefragmentTextureMemory_KOS(void);
|
|
||||||
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif /* !__GL_GL_H */
|
|
4
third_party/gldc/src/flush.c
vendored
4
third_party/gldc/src/flush.c
vendored
|
@ -15,7 +15,7 @@ PolyList TR_LIST;
|
||||||
|
|
||||||
#define FAST_MODE GL_FALSE
|
#define FAST_MODE GL_FALSE
|
||||||
|
|
||||||
void APIENTRY glKosInit() {
|
void glKosInit() {
|
||||||
TRACE();
|
TRACE();
|
||||||
|
|
||||||
_glInitContext();
|
_glInitContext();
|
||||||
|
@ -35,7 +35,7 @@ void APIENTRY glKosInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void APIENTRY glKosSwapBuffers() {
|
void glKosSwapBuffers() {
|
||||||
TRACE();
|
TRACE();
|
||||||
|
|
||||||
pvr_scene_begin();
|
pvr_scene_begin();
|
||||||
|
|
20
third_party/gldc/src/gl_assert.h
vendored
20
third_party/gldc/src/gl_assert.h
vendored
|
@ -1,20 +0,0 @@
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
/* We're debugging, use normal assert */
|
|
||||||
#include <assert.h>
|
|
||||||
#define gl_assert assert
|
|
||||||
#else
|
|
||||||
/* Release mode, use our custom assert */
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define gl_assert(x) \
|
|
||||||
do {\
|
|
||||||
if(!(x)) {\
|
|
||||||
fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
|
|
||||||
exit(1);\
|
|
||||||
}\
|
|
||||||
} while(0); \
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
46
third_party/gldc/src/private.h
vendored
46
third_party/gldc/src/private.h
vendored
|
@ -4,17 +4,45 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "gl_assert.h"
|
|
||||||
#include "sh4.h"
|
#include "sh4.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#include "../gldc.h"
|
|
||||||
|
|
||||||
#include "aligned_vector.h"
|
#include "aligned_vector.h"
|
||||||
|
|
||||||
#define MAX_TEXTURE_COUNT 768
|
#define MAX_TEXTURE_COUNT 768
|
||||||
|
|
||||||
|
|
||||||
|
#define GL_SCISSOR_TEST 0x0008
|
||||||
|
#define GL_NEAREST 0x2600
|
||||||
|
#define GL_LINEAR 0x2601
|
||||||
|
#define GL_OUT_OF_MEMORY 0x0505
|
||||||
|
|
||||||
|
#define GLushort unsigned short
|
||||||
|
#define GLuint unsigned int
|
||||||
|
#define GLenum unsigned int
|
||||||
|
#define GLubyte unsigned char
|
||||||
|
#define GLboolean unsigned char
|
||||||
|
|
||||||
|
#define GL_FALSE 0
|
||||||
|
#define GL_TRUE 1
|
||||||
|
|
||||||
|
|
||||||
|
void glClearDepth(float depth);
|
||||||
|
|
||||||
|
GLuint gldcGenTexture(void);
|
||||||
|
void gldcDeleteTexture(GLuint texture);
|
||||||
|
void gldcBindTexture(GLuint texture);
|
||||||
|
|
||||||
|
/* Loads texture from SH4 RAM into PVR VRAM */
|
||||||
|
int gldcAllocTexture(int w, int h, int format);
|
||||||
|
void gldcGetTexture(void** data, int* width, int* height);
|
||||||
|
|
||||||
|
void glViewport(int x, int y, int width, int height);
|
||||||
|
void glScissor( int x, int y, int width, int height);
|
||||||
|
|
||||||
|
void glKosInit();
|
||||||
|
void glKosSwapBuffers();
|
||||||
|
|
||||||
|
|
||||||
extern void* memcpy4 (void *dest, const void *src, size_t count);
|
extern void* memcpy4 (void *dest, const void *src, size_t count);
|
||||||
|
|
||||||
#define GL_NO_INSTRUMENT inline __attribute__((no_instrument_function))
|
#define GL_NO_INSTRUMENT inline __attribute__((no_instrument_function))
|
||||||
|
@ -109,7 +137,6 @@ void _glInitTextures();
|
||||||
extern TextureObject* TEXTURE_ACTIVE;
|
extern TextureObject* TEXTURE_ACTIVE;
|
||||||
extern GLboolean TEXTURES_ENABLED;
|
extern GLboolean TEXTURES_ENABLED;
|
||||||
|
|
||||||
extern GLenum DEPTH_FUNC;
|
|
||||||
extern GLboolean DEPTH_TEST_ENABLED;
|
extern GLboolean DEPTH_TEST_ENABLED;
|
||||||
extern GLboolean DEPTH_MASK_ENABLED;
|
extern GLboolean DEPTH_MASK_ENABLED;
|
||||||
|
|
||||||
|
@ -138,9 +165,12 @@ GL_FORCE_INLINE PolyList* _glActivePolyList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint _glFreeTextureMemory();
|
/* Memory allocation extension (GL_KOS_texture_memory_management) */
|
||||||
GLuint _glUsedTextureMemory();
|
void glDefragmentTextureMemory_KOS(void);
|
||||||
GLuint _glFreeContiguousTextureMemory();
|
|
||||||
|
GLuint _glFreeTextureMemory(void);
|
||||||
|
GLuint _glUsedTextureMemory(void);
|
||||||
|
GLuint _glFreeContiguousTextureMemory(void);
|
||||||
|
|
||||||
void _glApplyScissor(int force);
|
void _glApplyScissor(int force);
|
||||||
|
|
||||||
|
|
2
third_party/gldc/src/sh4.c
vendored
2
third_party/gldc/src/sh4.c
vendored
|
@ -1,4 +1,6 @@
|
||||||
|
#include <math.h>
|
||||||
#include "sh4.h"
|
#include "sh4.h"
|
||||||
|
#include "sh4_math.h"
|
||||||
|
|
||||||
#define CLIP_DEBUG 0
|
#define CLIP_DEBUG 0
|
||||||
|
|
||||||
|
|
5
third_party/gldc/src/sh4.h
vendored
5
third_party/gldc/src/sh4.h
vendored
|
@ -1,14 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <kos.h>
|
#include <kos.h>
|
||||||
#include <dc/matrix.h>
|
|
||||||
#include <dc/pvr.h>
|
#include <dc/pvr.h>
|
||||||
#include <dc/vec3f.h>
|
|
||||||
#include <dc/fmath.h>
|
|
||||||
#include <dc/matrix3d.h>
|
|
||||||
|
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
#include "sh4_math.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#ifndef GL_FORCE_INLINE
|
#ifndef GL_FORCE_INLINE
|
||||||
|
|
12
third_party/gldc/src/state.c
vendored
12
third_party/gldc/src/state.c
vendored
|
@ -1,4 +1,4 @@
|
||||||
#include <stddef.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ GLboolean FOG_ENABLED = GL_FALSE;
|
||||||
GLboolean ALPHA_TEST_ENABLED = GL_FALSE;
|
GLboolean ALPHA_TEST_ENABLED = GL_FALSE;
|
||||||
|
|
||||||
GLboolean SCISSOR_TEST_ENABLED = GL_FALSE;
|
GLboolean SCISSOR_TEST_ENABLED = GL_FALSE;
|
||||||
GLenum SHADE_MODEL = GL_SMOOTH;
|
GLenum SHADE_MODEL = PVR_SHADE_GOURAUD;
|
||||||
|
|
||||||
GLboolean BLEND_ENABLED = GL_FALSE;
|
GLboolean BLEND_ENABLED = GL_FALSE;
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ void _glInitContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Depth Testing */
|
/* Depth Testing */
|
||||||
GLAPI void APIENTRY glClearDepth(float depth) {
|
void glClearDepth(float depth) {
|
||||||
/* We reverse because using invW means that farther Z == lower number */
|
/* We reverse because using invW means that farther Z == lower number */
|
||||||
pvr_set_zclip(MIN(1.0f - depth, PVR_MIN_Z));
|
pvr_set_zclip(MIN(1.0f - depth, PVR_MIN_Z));
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glScissor(int x, int y, int width, int height) {
|
void glScissor(int x, int y, int width, int height) {
|
||||||
|
|
||||||
if(scissor_rect.x == x &&
|
if(scissor_rect.x == x &&
|
||||||
scissor_rect.y == y &&
|
scissor_rect.y == y &&
|
||||||
|
@ -130,7 +130,7 @@ void _glApplyScissor(int force) {
|
||||||
Viewport VIEWPORT;
|
Viewport VIEWPORT;
|
||||||
|
|
||||||
/* Set the GL viewport */
|
/* Set the GL viewport */
|
||||||
void APIENTRY glViewport(int x, int y, int width, int height) {
|
void glViewport(int x, int y, int width, int height) {
|
||||||
VIEWPORT.hwidth = width * 0.5f;
|
VIEWPORT.hwidth = width * 0.5f;
|
||||||
VIEWPORT.hheight = height * -0.5f;
|
VIEWPORT.hheight = height * -0.5f;
|
||||||
VIEWPORT.x_plus_hwidth = x + width * 0.5f;
|
VIEWPORT.x_plus_hwidth = x + width * 0.5f;
|
||||||
|
@ -150,7 +150,7 @@ void apply_poly_header(PolyHeader* dst, PolyList* activePolyList) {
|
||||||
int depth_comp = DEPTH_TEST_ENABLED ? PVR_DEPTHCMP_GEQUAL : PVR_DEPTHCMP_ALWAYS;
|
int depth_comp = DEPTH_TEST_ENABLED ? PVR_DEPTHCMP_GEQUAL : PVR_DEPTHCMP_ALWAYS;
|
||||||
int depth_write = DEPTH_MASK_ENABLED ? PVR_DEPTHWRITE_ENABLE : PVR_DEPTHWRITE_DISABLE;
|
int depth_write = DEPTH_MASK_ENABLED ? PVR_DEPTHWRITE_ENABLE : PVR_DEPTHWRITE_DISABLE;
|
||||||
|
|
||||||
int gen_shading = (SHADE_MODEL == GL_SMOOTH) ? PVR_SHADE_GOURAUD : PVR_SHADE_FLAT;
|
int gen_shading = SHADE_MODEL;
|
||||||
int gen_clip_mode = SCISSOR_TEST_ENABLED ? PVR_USERCLIP_INSIDE : PVR_USERCLIP_DISABLE;
|
int gen_clip_mode = SCISSOR_TEST_ENABLED ? PVR_USERCLIP_INSIDE : PVR_USERCLIP_DISABLE;
|
||||||
int gen_fog_type = FOG_ENABLED ? PVR_FOG_TABLE : PVR_FOG_DISABLE;
|
int gen_fog_type = FOG_ENABLED ? PVR_FOG_TABLE : PVR_FOG_DISABLE;
|
||||||
|
|
||||||
|
|
57
third_party/gldc/src/texture.c
vendored
57
third_party/gldc/src/texture.c
vendored
|
@ -8,6 +8,26 @@
|
||||||
#include "sh4.h"
|
#include "sh4.h"
|
||||||
#include "yalloc/yalloc.h"
|
#include "yalloc/yalloc.h"
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
/* We're debugging, use normal assert */
|
||||||
|
#include <assert.h>
|
||||||
|
#define gl_assert assert
|
||||||
|
#else
|
||||||
|
/* Release mode, use our custom assert */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define gl_assert(x) \
|
||||||
|
do {\
|
||||||
|
if(!(x)) {\
|
||||||
|
fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
|
||||||
|
exit(1);\
|
||||||
|
}\
|
||||||
|
} while(0); \
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* We always leave this amount of vram unallocated to prevent
|
/* We always leave this amount of vram unallocated to prevent
|
||||||
* issues with the allocator */
|
* issues with the allocator */
|
||||||
#define PVR_MEM_BUFFER_SIZE (64 * 1024)
|
#define PVR_MEM_BUFFER_SIZE (64 * 1024)
|
||||||
|
@ -100,9 +120,7 @@ void _glInitTextures() {
|
||||||
yalloc_init(YALLOC_BASE, YALLOC_SIZE);
|
yalloc_init(YALLOC_BASE, YALLOC_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint APIENTRY gldcGenTexture(void) {
|
GLuint gldcGenTexture(void) {
|
||||||
TRACE();
|
|
||||||
|
|
||||||
GLuint id = texture_id_map_alloc();
|
GLuint id = texture_id_map_alloc();
|
||||||
gl_assert(id); // Generated IDs must never be zero
|
gl_assert(id); // Generated IDs must never be zero
|
||||||
|
|
||||||
|
@ -114,9 +132,7 @@ GLuint APIENTRY gldcGenTexture(void) {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY gldcDeleteTexture(GLuint id) {
|
void gldcDeleteTexture(GLuint id) {
|
||||||
TRACE();
|
|
||||||
|
|
||||||
if(id == 0) return;
|
if(id == 0) return;
|
||||||
/* Zero is the "default texture" and we never allow deletion of it */
|
/* Zero is the "default texture" and we never allow deletion of it */
|
||||||
|
|
||||||
|
@ -138,9 +154,7 @@ void APIENTRY gldcDeleteTexture(GLuint id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY gldcBindTexture(GLuint id) {
|
void gldcBindTexture(GLuint id) {
|
||||||
TRACE();
|
|
||||||
|
|
||||||
gl_assert(texture_id_map_used(id));
|
gl_assert(texture_id_map_used(id));
|
||||||
TextureObject* txr = &TEXTURE_LIST[id];
|
TextureObject* txr = &TEXTURE_LIST[id];
|
||||||
|
|
||||||
|
@ -150,14 +164,12 @@ void APIENTRY gldcBindTexture(GLuint id) {
|
||||||
STATE_DIRTY = GL_TRUE;
|
STATE_DIRTY = GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int APIENTRY gldcAllocTexture(int w, int h, int format) {
|
int gldcAllocTexture(int w, int h, int format) {
|
||||||
TRACE();
|
|
||||||
|
|
||||||
TextureObject* active = TEXTURE_ACTIVE;
|
TextureObject* active = TEXTURE_ACTIVE;
|
||||||
|
|
||||||
if(active->data) {
|
if (active->data) {
|
||||||
/* pre-existing texture - check if changed */
|
/* pre-existing texture - check if changed */
|
||||||
if(active->width != w || active->height != h) {
|
if (active->width != w || active->height != h) {
|
||||||
/* changed - free old texture memory */
|
/* changed - free old texture memory */
|
||||||
yalloc_free(YALLOC_BASE, active->data);
|
yalloc_free(YALLOC_BASE, active->data);
|
||||||
active->data = NULL;
|
active->data = NULL;
|
||||||
|
@ -173,25 +185,16 @@ int APIENTRY gldcAllocTexture(int w, int h, int format) {
|
||||||
|
|
||||||
if(!active->data) {
|
if(!active->data) {
|
||||||
/* need texture memory */
|
/* need texture memory */
|
||||||
active->data = yalloc_alloc_and_defrag(bytes);
|
active->data = yalloc_alloc_and_defrag(bytes);
|
||||||
}
|
|
||||||
|
|
||||||
gl_assert(active->data);
|
|
||||||
|
|
||||||
/* If we run out of PVR memory just return */
|
|
||||||
if(!active->data) {
|
|
||||||
fprintf(stderr, "Out of texture memory\n");
|
|
||||||
return GL_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
if (!active->data) return GL_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* Mark level 0 as set in the mipmap bitmask */
|
/* Mark level 0 as set in the mipmap bitmask */
|
||||||
active->mipmap |= (1 << 0);
|
active->mipmap |= (1 << 0);
|
||||||
|
|
||||||
STATE_DIRTY = GL_TRUE;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLAPI void APIENTRY gldcGetTexture(void** data, int* width, int* height) {
|
void gldcGetTexture(void** data, int* width, int* height) {
|
||||||
TextureObject* active = TEXTURE_ACTIVE;
|
TextureObject* active = TEXTURE_ACTIVE;
|
||||||
*data = active->data;
|
*data = active->data;
|
||||||
*width = active->width;
|
*width = active->width;
|
||||||
|
@ -214,7 +217,7 @@ GLuint _glFreeContiguousTextureMemory() {
|
||||||
return yalloc_count_continuous(YALLOC_BASE);
|
return yalloc_count_continuous(YALLOC_BASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLAPI void APIENTRY glDefragmentTextureMemory_KOS(void) {
|
void glDefragmentTextureMemory_KOS(void) {
|
||||||
yalloc_defrag_start(YALLOC_BASE);
|
yalloc_defrag_start(YALLOC_BASE);
|
||||||
|
|
||||||
GLuint id;
|
GLuint id;
|
||||||
|
|
Loading…
Reference in a new issue