diff --git a/src/base.err b/src/base.err index 507b26c..2d413e8 100644 --- a/src/base.err +++ b/src/base.err @@ -19,4 +19,6 @@ ECODE(ERR_ENGINESTART, ECODE(ERR_INVRASTER, "Invalid raster format"), ECODE(ERR_NOTEXTURE, - "Could not create texture") + "Could not create texture"), +ECODE(ERR_FORMAT_UNSUPPORTED, + "Unsupported raster format") diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index 13792b8..21b162c 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -59,6 +59,8 @@ struct GlGlobals const char *winTitle; } glGlobals; +Gl3Caps gl3Caps; + int32 alphaFunc; float32 alphaRef; @@ -1498,6 +1500,18 @@ stopGLFW(void) static int 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 u_alphaRef = registerUniform("u_alphaRef"); u_fogData = registerUniform("u_fogData"); diff --git a/src/gl/gl3raster.cpp b/src/gl/gl3raster.cpp index 2298fdd..5088cc6 100644 --- a/src/gl/gl3raster.cpp +++ b/src/gl/gl3raster.cpp @@ -769,6 +769,11 @@ readNativeTexture(Stream *stream) Raster *raster; Gl3Raster *natras; 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); allocateDXT(raster, compression, numLevels, flags & 1); }else{ diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index fd62541..f55d237 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -246,6 +246,14 @@ struct Gl3Raster 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); Texture *readNativeTexture(Stream *stream); diff --git a/src/raster.cpp b/src/raster.cpp index 021855f..fbce2e4 100644 --- a/src/raster.cpp +++ b/src/raster.cpp @@ -419,6 +419,9 @@ d3d_to_gl3(rw::Raster *ras) #ifdef RW_GL3 using namespace rw; + if(!gl3::gl3Caps.dxtSupported) + return nil; + int dxt = 0; d3d::D3dRaster *d3dras = GETD3DRASTEREXT(ras); if(d3dras->customFormat){