mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-23 08:51:06 +00:00
040cb17370
# Conflicts: # CMakeLists.txt # libraries/glslang/OGLCompilersDLL/CMakeLists.txt # libraries/glslang/OGLCompilersDLL/InitializeDll.cpp # libraries/glslang/OGLCompilersDLL/InitializeDll.h # libraries/glslang/glslang/CMakeLists.txt # libraries/glslang/glslang/GenericCodeGen/CodeGen.cpp # libraries/glslang/glslang/GenericCodeGen/Link.cpp # libraries/glslang/glslang/Include/BaseTypes.h # libraries/glslang/glslang/Include/Common.h # libraries/glslang/glslang/Include/ConstantUnion.h # libraries/glslang/glslang/Include/InfoSink.h # libraries/glslang/glslang/Include/InitializeGlobals.h # libraries/glslang/glslang/Include/PoolAlloc.h # libraries/glslang/glslang/Include/ResourceLimits.h # libraries/glslang/glslang/Include/ShHandle.h # libraries/glslang/glslang/Include/Types.h # libraries/glslang/glslang/Include/arrays.h # libraries/glslang/glslang/Include/intermediate.h # libraries/glslang/glslang/Include/revision.h # libraries/glslang/glslang/Include/revision.template # libraries/glslang/glslang/MachineIndependent/Constant.cpp # libraries/glslang/glslang/MachineIndependent/InfoSink.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.h # libraries/glslang/glslang/MachineIndependent/IntermTraverse.cpp # libraries/glslang/glslang/MachineIndependent/Intermediate.cpp # libraries/glslang/glslang/MachineIndependent/LiveTraverser.h # libraries/glslang/glslang/MachineIndependent/ParseContextBase.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.h # libraries/glslang/glslang/MachineIndependent/PoolAlloc.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.h # libraries/glslang/glslang/MachineIndependent/Scan.cpp # libraries/glslang/glslang/MachineIndependent/Scan.h # libraries/glslang/glslang/MachineIndependent/ScanContext.h # libraries/glslang/glslang/MachineIndependent/ShaderLang.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.h # libraries/glslang/glslang/MachineIndependent/Versions.cpp # libraries/glslang/glslang/MachineIndependent/Versions.h # libraries/glslang/glslang/MachineIndependent/attribute.cpp # libraries/glslang/glslang/MachineIndependent/attribute.h # libraries/glslang/glslang/MachineIndependent/gl_types.h # libraries/glslang/glslang/MachineIndependent/glslang.y # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp.h # libraries/glslang/glslang/MachineIndependent/intermOut.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.h # libraries/glslang/glslang/MachineIndependent/limits.cpp # libraries/glslang/glslang/MachineIndependent/linkValidate.cpp # libraries/glslang/glslang/MachineIndependent/localintermediate.h # libraries/glslang/glslang/MachineIndependent/parseConst.cpp # libraries/glslang/glslang/MachineIndependent/parseVersions.h # libraries/glslang/glslang/MachineIndependent/pch.cpp # libraries/glslang/glslang/MachineIndependent/pch.h # libraries/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.h # libraries/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.cpp # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.h # libraries/glslang/glslang/MachineIndependent/reflection.cpp # libraries/glslang/glslang/MachineIndependent/reflection.h # libraries/glslang/glslang/OSDependent/Unix/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Unix/ossource.cpp # libraries/glslang/glslang/OSDependent/Windows/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Windows/main.cpp # libraries/glslang/glslang/OSDependent/Windows/ossource.cpp # libraries/glslang/glslang/OSDependent/osinclude.h # libraries/glslang/glslang/Public/ShaderLang.h # libraries/glslang/glslang/updateGrammar # libraries/glslang/spirv/CMakeLists.txt # libraries/glslang/spirv/GLSL.ext.AMD.h # libraries/glslang/spirv/GLSL.ext.EXT.h # libraries/glslang/spirv/GLSL.ext.KHR.h # libraries/glslang/spirv/GLSL.ext.NV.h # libraries/glslang/spirv/GLSL.std.450.h # libraries/glslang/spirv/GlslangToSpv.cpp # libraries/glslang/spirv/GlslangToSpv.h # libraries/glslang/spirv/InReadableOrder.cpp # libraries/glslang/spirv/Logger.cpp # libraries/glslang/spirv/Logger.h # libraries/glslang/spirv/SPVRemapper.cpp # libraries/glslang/spirv/SPVRemapper.h # libraries/glslang/spirv/SpvBuilder.cpp # libraries/glslang/spirv/SpvBuilder.h # libraries/glslang/spirv/SpvPostProcess.cpp # libraries/glslang/spirv/SpvTools.cpp # libraries/glslang/spirv/SpvTools.h # libraries/glslang/spirv/bitutils.h # libraries/glslang/spirv/disassemble.cpp # libraries/glslang/spirv/disassemble.h # libraries/glslang/spirv/doc.cpp # libraries/glslang/spirv/doc.h # libraries/glslang/spirv/hex_float.h # libraries/glslang/spirv/spirv.hpp # libraries/glslang/spirv/spvIR.h # src/CMakeLists.txt
418 lines
5.6 KiB
C
418 lines
5.6 KiB
C
/* _______ ____ __ ___ ___
|
|
* \ _ \ \ / \ / \ \ / / ' ' '
|
|
* | | \ \ | | || | \/ | . .
|
|
* | | | | | | || ||\ /| |
|
|
* | | | | | | || || \/ | | ' ' '
|
|
* | | | | | | || || | | . .
|
|
* | |_/ / \ \__// || | |
|
|
* /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
|
|
* / \
|
|
* / . \
|
|
* dumbfile.c - Hookable, strictly sequential / / \ \
|
|
* file input functions. | < / \_
|
|
* | \/ /\ /
|
|
* By entheh. \_ / > /
|
|
* | \ / /
|
|
* | ' /
|
|
* \__/
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "dumb.h"
|
|
|
|
|
|
|
|
static const DUMBFILE_SYSTEM *the_dfs = NULL;
|
|
|
|
|
|
|
|
void DUMBEXPORT register_dumbfile_system(const DUMBFILE_SYSTEM *dfs)
|
|
{
|
|
ASSERT(dfs);
|
|
ASSERT(dfs->open);
|
|
ASSERT(dfs->getc);
|
|
ASSERT(dfs->close);
|
|
ASSERT(dfs->seek);
|
|
ASSERT(dfs->get_size);
|
|
the_dfs = dfs;
|
|
}
|
|
|
|
|
|
|
|
#include "internal/dumbfile.h"
|
|
|
|
|
|
|
|
DUMBFILE *DUMBEXPORT dumbfile_open(const char *filename)
|
|
{
|
|
DUMBFILE *f;
|
|
|
|
ASSERT(the_dfs);
|
|
|
|
f = (DUMBFILE *) malloc(sizeof(*f));
|
|
|
|
if (!f)
|
|
return NULL;
|
|
|
|
f->dfs = the_dfs;
|
|
|
|
f->file = (*the_dfs->open)(filename);
|
|
|
|
if (!f->file) {
|
|
free(f);
|
|
return NULL;
|
|
}
|
|
|
|
f->pos = 0;
|
|
|
|
return f;
|
|
}
|
|
|
|
|
|
|
|
DUMBFILE *DUMBEXPORT dumbfile_open_ex(void *file, const DUMBFILE_SYSTEM *dfs)
|
|
{
|
|
DUMBFILE *f;
|
|
|
|
ASSERT(dfs);
|
|
ASSERT(dfs->getc);
|
|
ASSERT(file);
|
|
|
|
f = (DUMBFILE *) malloc(sizeof(*f));
|
|
|
|
if (!f) {
|
|
if (dfs->close)
|
|
(*dfs->close)(file);
|
|
return NULL;
|
|
}
|
|
|
|
f->dfs = dfs;
|
|
f->file = file;
|
|
|
|
f->pos = 0;
|
|
|
|
return f;
|
|
}
|
|
|
|
|
|
|
|
int32 DUMBEXPORT dumbfile_pos(DUMBFILE *f)
|
|
{
|
|
ASSERT(f);
|
|
|
|
return f->pos;
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_skip(DUMBFILE *f, long n)
|
|
{
|
|
int rv;
|
|
|
|
ASSERT(f);
|
|
ASSERT(n >= 0);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
f->pos += n;
|
|
|
|
if (f->dfs->skip) {
|
|
rv = (*f->dfs->skip)(f->file, n);
|
|
if (rv) {
|
|
f->pos = -1;
|
|
return rv;
|
|
}
|
|
} else {
|
|
while (n) {
|
|
rv = (*f->dfs->getc)(f->file);
|
|
if (rv < 0) {
|
|
f->pos = -1;
|
|
return rv;
|
|
}
|
|
n--;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_getc(DUMBFILE *f)
|
|
{
|
|
int rv;
|
|
|
|
ASSERT(f);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
rv = (*f->dfs->getc)(f->file);
|
|
|
|
if (rv < 0) {
|
|
f->pos = -1;
|
|
return rv;
|
|
}
|
|
|
|
f->pos++;
|
|
|
|
return rv;
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_igetw(DUMBFILE *f)
|
|
{
|
|
int l, h;
|
|
|
|
ASSERT(f);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
l = (*f->dfs->getc)(f->file);
|
|
if (l < 0) {
|
|
f->pos = -1;
|
|
return l;
|
|
}
|
|
|
|
h = (*f->dfs->getc)(f->file);
|
|
if (h < 0) {
|
|
f->pos = -1;
|
|
return h;
|
|
}
|
|
|
|
f->pos += 2;
|
|
|
|
return l | (h << 8);
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_mgetw(DUMBFILE *f)
|
|
{
|
|
int l, h;
|
|
|
|
ASSERT(f);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
h = (*f->dfs->getc)(f->file);
|
|
if (h < 0) {
|
|
f->pos = -1;
|
|
return h;
|
|
}
|
|
|
|
l = (*f->dfs->getc)(f->file);
|
|
if (l < 0) {
|
|
f->pos = -1;
|
|
return l;
|
|
}
|
|
|
|
f->pos += 2;
|
|
|
|
return l | (h << 8);
|
|
}
|
|
|
|
|
|
|
|
int32 DUMBEXPORT dumbfile_igetl(DUMBFILE *f)
|
|
{
|
|
uint32 rv, b;
|
|
|
|
ASSERT(f);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
rv = (*f->dfs->getc)(f->file);
|
|
if ((sint32)rv < 0) {
|
|
f->pos = -1;
|
|
return rv;
|
|
}
|
|
|
|
b = (*f->dfs->getc)(f->file);
|
|
if ((sint32)b < 0) {
|
|
f->pos = -1;
|
|
return b;
|
|
}
|
|
rv |= b << 8;
|
|
|
|
b = (*f->dfs->getc)(f->file);
|
|
if ((sint32)b < 0) {
|
|
f->pos = -1;
|
|
return b;
|
|
}
|
|
rv |= b << 16;
|
|
|
|
b = (*f->dfs->getc)(f->file);
|
|
if ((sint32)b < 0) {
|
|
f->pos = -1;
|
|
return b;
|
|
}
|
|
rv |= b << 24;
|
|
|
|
f->pos += 4;
|
|
|
|
return rv;
|
|
}
|
|
|
|
|
|
|
|
int32 DUMBEXPORT dumbfile_mgetl(DUMBFILE *f)
|
|
{
|
|
uint32 rv, b;
|
|
|
|
ASSERT(f);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
rv = (*f->dfs->getc)(f->file);
|
|
if ((sint32)rv < 0) {
|
|
f->pos = -1;
|
|
return rv;
|
|
}
|
|
rv <<= 24;
|
|
|
|
b = (*f->dfs->getc)(f->file);
|
|
if ((sint32)b < 0) {
|
|
f->pos = -1;
|
|
return b;
|
|
}
|
|
rv |= b << 16;
|
|
|
|
b = (*f->dfs->getc)(f->file);
|
|
if ((sint32)b < 0) {
|
|
f->pos = -1;
|
|
return b;
|
|
}
|
|
rv |= b << 8;
|
|
|
|
b = (*f->dfs->getc)(f->file);
|
|
if ((sint32)b < 0) {
|
|
f->pos = -1;
|
|
return b;
|
|
}
|
|
rv |= b;
|
|
|
|
f->pos += 4;
|
|
|
|
return rv;
|
|
}
|
|
|
|
|
|
|
|
uint32 DUMBEXPORT dumbfile_cgetul(DUMBFILE *f)
|
|
{
|
|
uint32 rv = 0;
|
|
int v;
|
|
|
|
do {
|
|
v = dumbfile_getc(f);
|
|
|
|
if (v < 0)
|
|
return v;
|
|
|
|
rv <<= 7;
|
|
rv |= v & 0x7F;
|
|
} while (v & 0x80);
|
|
|
|
return rv;
|
|
}
|
|
|
|
|
|
|
|
sint32 DUMBEXPORT dumbfile_cgetsl(DUMBFILE *f)
|
|
{
|
|
uint32 rv = dumbfile_cgetul(f);
|
|
|
|
if (f->pos < 0)
|
|
return rv;
|
|
|
|
return (rv >> 1) | (rv << 31);
|
|
}
|
|
|
|
|
|
|
|
int32 DUMBEXPORT dumbfile_getnc(char *ptr, int32 n, DUMBFILE *f)
|
|
{
|
|
int32 rv;
|
|
|
|
ASSERT(f);
|
|
ASSERT(n >= 0);
|
|
|
|
if (f->pos < 0)
|
|
return -1;
|
|
|
|
if (f->dfs->getnc) {
|
|
rv = (*f->dfs->getnc)(ptr, n, f->file);
|
|
if (rv < n) {
|
|
f->pos = -1;
|
|
return MAX(rv, 0);
|
|
}
|
|
} else {
|
|
for (rv = 0; rv < n; rv++) {
|
|
int c = (*f->dfs->getc)(f->file);
|
|
if (c < 0) {
|
|
f->pos = -1;
|
|
return rv;
|
|
}
|
|
*ptr++ = c;
|
|
}
|
|
}
|
|
|
|
f->pos += rv;
|
|
|
|
return rv;
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_seek(DUMBFILE *f, long n, int origin)
|
|
{
|
|
switch ( origin )
|
|
{
|
|
case DFS_SEEK_CUR: n += f->pos; break;
|
|
case DFS_SEEK_END: n += (*f->dfs->get_size)(f->file); break;
|
|
}
|
|
f->pos = n;
|
|
return (*f->dfs->seek)(f->file, n);
|
|
}
|
|
|
|
|
|
|
|
int32 DUMBEXPORT dumbfile_get_size(DUMBFILE *f)
|
|
{
|
|
return (*f->dfs->get_size)(f->file);
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_error(DUMBFILE *f)
|
|
{
|
|
ASSERT(f);
|
|
|
|
return f->pos < 0;
|
|
}
|
|
|
|
|
|
|
|
int DUMBEXPORT dumbfile_close(DUMBFILE *f)
|
|
{
|
|
int rv;
|
|
|
|
ASSERT(f);
|
|
|
|
rv = f->pos < 0;
|
|
|
|
if (f->dfs->close)
|
|
(*f->dfs->close)(f->file);
|
|
|
|
free(f);
|
|
|
|
return rv;
|
|
}
|