forked from Mirrorlandia_minetest/irrlicht
OpenGL3: Add driver-dependent feature checks
This commit is contained in:
parent
ab628e641c
commit
4ee1ab261e
@ -217,7 +217,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase()
|
||||
bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer)
|
||||
{
|
||||
initVersion();
|
||||
initExtensions();
|
||||
initFeatures();
|
||||
|
||||
// reset cache handler
|
||||
delete CacheHandler;
|
||||
|
@ -288,6 +288,8 @@ namespace video
|
||||
void initVersion();
|
||||
virtual OpenGLVersion getVersionFromOpenGL() const = 0;
|
||||
|
||||
virtual void initFeatures() = 0;
|
||||
|
||||
void chooseMaterial2D();
|
||||
|
||||
ITexture* createDeviceDependentTexture(const io::path& name, IImage* image) override;
|
||||
|
@ -15,52 +15,33 @@ namespace irr
|
||||
{
|
||||
namespace video
|
||||
{
|
||||
void COpenGL3ExtensionHandler::initExtensions()
|
||||
void COpenGL3ExtensionHandler::initExtensionsOld()
|
||||
{
|
||||
GLint major, minor;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
||||
Version = 100 * major + 10 * minor;
|
||||
|
||||
GLint ext_count = 0;
|
||||
GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count);
|
||||
for (int k = 0; k < ext_count; k++) {
|
||||
auto ext_name = (char *)GL.GetStringi(GL_EXTENSIONS, k);
|
||||
for (size_t j=0; j<IRR_OGLES_Feature_Count; ++j) {
|
||||
if (!strcmp(getFeatureString(j), ext_name)) {
|
||||
FeatureAvailable[j] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto extensions_string = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
|
||||
const char *pos = extensions_string;
|
||||
while (const char *next = strchr(pos, ' ')) {
|
||||
std::string name{pos, next};
|
||||
addExtension(name.c_str());
|
||||
pos = next + 1;
|
||||
}
|
||||
|
||||
GLint val=0;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &val);
|
||||
Feature.MaxTextureUnits = static_cast<u8>(val);
|
||||
|
||||
#ifdef GL_EXT_texture_filter_anisotropic
|
||||
if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic])
|
||||
{
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
|
||||
MaxAnisotropy = static_cast<u8>(val);
|
||||
}
|
||||
#endif
|
||||
#ifdef GL_MAX_ELEMENTS_INDICES
|
||||
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &val);
|
||||
MaxIndices=val;
|
||||
#endif
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
|
||||
MaxTextureSize=static_cast<u32>(val);
|
||||
#ifdef GL_EXT_texture_lod_bias
|
||||
if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias])
|
||||
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
|
||||
#endif
|
||||
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
|
||||
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
|
||||
|
||||
Feature.MaxTextureUnits = core::min_(Feature.MaxTextureUnits, static_cast<u8>(MATERIAL_MAX_TEXTURES));
|
||||
Feature.ColorAttachment = 1;
|
||||
addExtension(pos);
|
||||
}
|
||||
|
||||
void COpenGL3ExtensionHandler::initExtensionsNew()
|
||||
{
|
||||
GLint ext_count = 0;
|
||||
GL.GetIntegerv(GL_NUM_EXTENSIONS, &ext_count);
|
||||
for (int k = 0; k < ext_count; k++)
|
||||
addExtension(reinterpret_cast<const char *>(GL.GetStringi(GL_EXTENSIONS, k)));
|
||||
}
|
||||
|
||||
void COpenGL3ExtensionHandler::addExtension(const char *name) {
|
||||
for (size_t j=0; j<IRR_OGLES_Feature_Count; ++j) {
|
||||
if (!strcmp(getFeatureString(j), name)) {
|
||||
FeatureAvailable[j] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end namespace video
|
||||
} // end namespace irr
|
||||
|
@ -24,7 +24,8 @@ namespace video
|
||||
public:
|
||||
COpenGL3ExtensionHandler() : COGLESCoreExtensionHandler() {}
|
||||
|
||||
void initExtensions();
|
||||
void initExtensionsOld();
|
||||
void initExtensionsNew();
|
||||
|
||||
bool queryFeature(video::E_VIDEO_DRIVER_FEATURE feature) const
|
||||
{
|
||||
@ -80,6 +81,12 @@ namespace video
|
||||
};
|
||||
}
|
||||
|
||||
static GLint GetInteger(GLenum key) {
|
||||
GLint val = 0;
|
||||
glGetIntegerv(key, &val);
|
||||
return val;
|
||||
};
|
||||
|
||||
inline void irrGlActiveTexture(GLenum texture)
|
||||
{
|
||||
glActiveTexture(texture);
|
||||
@ -181,6 +188,9 @@ namespace video
|
||||
inline void irrGlBlendEquationSeparateIndexed(GLuint buf, GLenum modeRGB, GLenum modeAlpha)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
void addExtension(const char *name);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,33 @@ namespace video {
|
||||
return {OpenGLSpec::Core, (u8)major, (u8)minor, 0};
|
||||
}
|
||||
|
||||
void COpenGL3Driver::initFeatures() {
|
||||
assert (Version.Spec == OpenGLSpec::Compat);
|
||||
assert (Version.Major >= 3);
|
||||
initExtensionsNew();
|
||||
|
||||
// COGLESCoreExtensionHandler::Feature
|
||||
static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed");
|
||||
Feature.BlendOperation = true;
|
||||
Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS);
|
||||
Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES;
|
||||
Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS);
|
||||
|
||||
// COGLESCoreExtensionHandler
|
||||
if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic])
|
||||
MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES);
|
||||
MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE);
|
||||
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias);
|
||||
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
|
||||
DimAliasedPoint[0] = 1.0f;
|
||||
DimAliasedPoint[1] = 1.0f;
|
||||
|
||||
GLint val = 0;
|
||||
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val);
|
||||
StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT;
|
||||
}
|
||||
|
||||
IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
|
||||
{
|
||||
os::Printer::log("Using COpenGL3Driver", ELL_INFORMATION);
|
||||
|
@ -19,6 +19,7 @@ namespace video {
|
||||
|
||||
protected:
|
||||
OpenGLVersion getVersionFromOpenGL() const override;
|
||||
void initFeatures() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,41 @@ namespace video {
|
||||
return {OpenGLSpec::ES, (u8)major, (u8)minor, 0};
|
||||
}
|
||||
|
||||
void COpenGLES2Driver::initFeatures() {
|
||||
assert (Version.Major >= 2);
|
||||
if (Version.Major >= 3)
|
||||
initExtensionsNew();
|
||||
else
|
||||
initExtensionsOld();
|
||||
|
||||
// COGLESCoreExtensionHandler::Feature
|
||||
static_assert(MATERIAL_MAX_TEXTURES <= 8, "Only up to 8 textures are guaranteed");
|
||||
Feature.BlendOperation = true;
|
||||
Feature.ColorAttachment = 1;
|
||||
if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers])
|
||||
Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS);
|
||||
Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES;
|
||||
if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_buffers])
|
||||
Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS);
|
||||
|
||||
// COGLESCoreExtensionHandler
|
||||
if (FeatureAvailable[IRR_GL_EXT_texture_filter_anisotropic])
|
||||
MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
if (Version.Major >= 3 || FeatureAvailable[IRR_GL_EXT_draw_range_elements])
|
||||
MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES);
|
||||
MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE);
|
||||
if (FeatureAvailable[IRR_GL_EXT_texture_lod_bias])
|
||||
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias);
|
||||
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec...
|
||||
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
|
||||
|
||||
if (Version.Major >= 3 || FeatureAvailable[IRR_GL_ARB_framebuffer_object]) {
|
||||
GLint val = 0;
|
||||
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &val);
|
||||
StencilBuffer = val == GL_FRAMEBUFFER_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
|
||||
{
|
||||
os::Printer::log("Using COpenGLES2Driver", ELL_INFORMATION);
|
||||
|
@ -19,6 +19,7 @@ namespace video {
|
||||
|
||||
protected:
|
||||
OpenGLVersion getVersionFromOpenGL() const override;
|
||||
void initFeatures() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user