runtime caps for opengl

This commit is contained in:
aap 2020-11-17 15:05:47 +01:00
parent 7e80d45cdb
commit cea326a4ce
5 changed files with 33 additions and 1 deletions

View File

@ -19,4 +19,6 @@ ECODE(ERR_ENGINESTART,
ECODE(ERR_INVRASTER, ECODE(ERR_INVRASTER,
"Invalid raster format"), "Invalid raster format"),
ECODE(ERR_NOTEXTURE, ECODE(ERR_NOTEXTURE,
"Could not create texture") "Could not create texture"),
ECODE(ERR_FORMAT_UNSUPPORTED,
"Unsupported raster format")

View File

@ -59,6 +59,8 @@ struct GlGlobals
const char *winTitle; const char *winTitle;
} glGlobals; } glGlobals;
Gl3Caps gl3Caps;
int32 alphaFunc; int32 alphaFunc;
float32 alphaRef; float32 alphaRef;
@ -1498,6 +1500,18 @@ stopGLFW(void)
static int static int
initOpenGL(void) initOpenGL(void)
{ {
memset(&gl3Caps, 0, sizeof(gl3Caps));
int numExt;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);
for(int i = 0; i < numExt; i++){
const char *ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
if(strcmp(ext, "GL_EXT_texture_compression_s3tc") == 0)
gl3Caps.dxtSupported = true;
else if(strcmp(ext, "GL_KHR_texture_compression_astc_ldr") == 0)
gl3Caps.astcSupported = true;
// printf("%d %s\n", i, ext);
}
#ifndef RW_GL_USE_UBOS #ifndef RW_GL_USE_UBOS
u_alphaRef = registerUniform("u_alphaRef"); u_alphaRef = registerUniform("u_alphaRef");
u_fogData = registerUniform("u_fogData"); u_fogData = registerUniform("u_fogData");

View File

@ -769,6 +769,11 @@ readNativeTexture(Stream *stream)
Raster *raster; Raster *raster;
Gl3Raster *natras; Gl3Raster *natras;
if(flags & 2){ if(flags & 2){
if(!gl3Caps.dxtSupported){
tex->destroy();
RWERROR((ERR_FORMAT_UNSUPPORTED));
return nil;
}
raster = Raster::create(width, height, depth, format | Raster::TEXTURE | Raster::DONTALLOCATE, PLATFORM_GL3); raster = Raster::create(width, height, depth, format | Raster::TEXTURE | Raster::DONTALLOCATE, PLATFORM_GL3);
allocateDXT(raster, compression, numLevels, flags & 1); allocateDXT(raster, compression, numLevels, flags & 1);
}else{ }else{

View File

@ -246,6 +246,14 @@ struct Gl3Raster
Raster *fboMate; // color or zbuffer raster mate of this one Raster *fboMate; // color or zbuffer raster mate of this one
}; };
struct Gl3Caps
{
// TODO: put more stuff into this
bool dxtSupported;
bool astcSupported; // not used yet
};
extern Gl3Caps gl3Caps;
void allocateDXT(Raster *raster, int32 dxt, int32 numLevels, bool32 hasAlpha); void allocateDXT(Raster *raster, int32 dxt, int32 numLevels, bool32 hasAlpha);
Texture *readNativeTexture(Stream *stream); Texture *readNativeTexture(Stream *stream);

View File

@ -419,6 +419,9 @@ d3d_to_gl3(rw::Raster *ras)
#ifdef RW_GL3 #ifdef RW_GL3
using namespace rw; using namespace rw;
if(!gl3::gl3Caps.dxtSupported)
return nil;
int dxt = 0; int dxt = 0;
d3d::D3dRaster *d3dras = GETD3DRASTEREXT(ras); d3d::D3dRaster *d3dras = GETD3DRASTEREXT(ras);
if(d3dras->customFormat){ if(d3dras->customFormat){