mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-13 05:50:26 +01:00
Migrate OpenGL cache and texture handler to GL pointers
this makes the OpenGL 3 driver free of GL symbol references!
This commit is contained in:
parent
7241a49566
commit
52e4d72ae2
|
@ -200,7 +200,6 @@ if(ENABLE_OPENGL3)
|
|||
if (NOT USE_SDL2)
|
||||
message(FATAL_ERROR "OpenGL 3 driver requires SDL2")
|
||||
endif()
|
||||
set(OPENGL_DIRECT_LINK TRUE) # TODO
|
||||
set(USE_SDLGL ON)
|
||||
set(USE_SDLGL3 ON)
|
||||
endif()
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "SMaterial.h"
|
||||
#include "ITexture.h"
|
||||
|
||||
#include "mt_opengl.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video
|
||||
|
@ -87,19 +89,19 @@ class COpenGLCoreCacheHandler
|
|||
|
||||
if (curTextureType != prevTextureType)
|
||||
{
|
||||
glBindTexture(prevTextureType, 0);
|
||||
GL.BindTexture(prevTextureType, 0);
|
||||
|
||||
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
|
||||
glDisable(prevTextureType);
|
||||
glEnable(curTextureType);
|
||||
GL.Disable(prevTextureType);
|
||||
GL.Enable(curTextureType);
|
||||
#endif
|
||||
}
|
||||
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
|
||||
else if (!prevTexture)
|
||||
glEnable(curTextureType);
|
||||
GL.Enable(curTextureType);
|
||||
#endif
|
||||
|
||||
glBindTexture(curTextureType, static_cast<const TOpenGLTexture*>(texture)->getOpenGLTextureName());
|
||||
GL.BindTexture(curTextureType, static_cast<const TOpenGLTexture*>(texture)->getOpenGLTextureName());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -115,10 +117,10 @@ class COpenGLCoreCacheHandler
|
|||
{
|
||||
const GLenum prevTextureType = prevTexture->getOpenGLTextureType();
|
||||
|
||||
glBindTexture(prevTextureType, 0);
|
||||
GL.BindTexture(prevTextureType, 0);
|
||||
|
||||
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
|
||||
glDisable(prevTextureType);
|
||||
GL.Disable(prevTextureType);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -222,28 +224,28 @@ public:
|
|||
ColorMask[i] = ECP_ALL;
|
||||
}
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glDisable(GL_BLEND);
|
||||
GL.BlendFunc(GL_ONE, GL_ZERO);
|
||||
GL.Disable(GL_BLEND);
|
||||
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
GL.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
glCullFace(CullFaceMode);
|
||||
glDisable(GL_CULL_FACE);
|
||||
GL.CullFace(CullFaceMode);
|
||||
GL.Disable(GL_CULL_FACE);
|
||||
|
||||
glDepthFunc(DepthFunc);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
GL.DepthFunc(DepthFunc);
|
||||
GL.DepthMask(GL_TRUE);
|
||||
GL.Disable(GL_DEPTH_TEST);
|
||||
|
||||
Driver->irrGlActiveTexture(ActiveTexture);
|
||||
|
||||
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
GL.Disable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
|
||||
const core::dimension2d<u32> ScreenSize = Driver->getScreenSize();
|
||||
ViewportWidth = ScreenSize.Width;
|
||||
ViewportHeight = ScreenSize.Height;
|
||||
glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);
|
||||
GL.Viewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);
|
||||
}
|
||||
|
||||
virtual ~COpenGLCoreCacheHandler()
|
||||
|
@ -300,7 +302,7 @@ public:
|
|||
BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination ||
|
||||
BlendFuncInvalid)
|
||||
{
|
||||
glBlendFunc(source, destination);
|
||||
GL.BlendFunc(source, destination);
|
||||
|
||||
for (GLuint i = 0; i < FrameBufferCount; ++i)
|
||||
{
|
||||
|
@ -383,9 +385,9 @@ public:
|
|||
if (Blend[0] != enable || BlendInvalid)
|
||||
{
|
||||
if (enable)
|
||||
glEnable(GL_BLEND);
|
||||
GL.Enable(GL_BLEND);
|
||||
else
|
||||
glDisable(GL_BLEND);
|
||||
GL.Disable(GL_BLEND);
|
||||
|
||||
for (GLuint i = 0; i < FrameBufferCount; ++i)
|
||||
Blend[i] = enable;
|
||||
|
@ -419,7 +421,7 @@ public:
|
|||
{
|
||||
if (ColorMask[0] != mask || ColorMaskInvalid)
|
||||
{
|
||||
glColorMask((mask & ECP_RED) ? GL_TRUE : GL_FALSE, (mask & ECP_GREEN) ? GL_TRUE : GL_FALSE, (mask & ECP_BLUE) ? GL_TRUE : GL_FALSE, (mask & ECP_ALPHA) ? GL_TRUE : GL_FALSE);
|
||||
GL.ColorMask((mask & ECP_RED) ? GL_TRUE : GL_FALSE, (mask & ECP_GREEN) ? GL_TRUE : GL_FALSE, (mask & ECP_BLUE) ? GL_TRUE : GL_FALSE, (mask & ECP_ALPHA) ? GL_TRUE : GL_FALSE);
|
||||
|
||||
for (GLuint i = 0; i < FrameBufferCount; ++i)
|
||||
ColorMask[i] = mask;
|
||||
|
@ -445,7 +447,7 @@ public:
|
|||
{
|
||||
if (CullFaceMode != mode)
|
||||
{
|
||||
glCullFace(mode);
|
||||
GL.CullFace(mode);
|
||||
CullFaceMode = mode;
|
||||
}
|
||||
}
|
||||
|
@ -455,9 +457,9 @@ public:
|
|||
if (CullFace != enable)
|
||||
{
|
||||
if (enable)
|
||||
glEnable(GL_CULL_FACE);
|
||||
GL.Enable(GL_CULL_FACE);
|
||||
else
|
||||
glDisable(GL_CULL_FACE);
|
||||
GL.Disable(GL_CULL_FACE);
|
||||
|
||||
CullFace = enable;
|
||||
}
|
||||
|
@ -469,7 +471,7 @@ public:
|
|||
{
|
||||
if (DepthFunc != mode)
|
||||
{
|
||||
glDepthFunc(mode);
|
||||
GL.DepthFunc(mode);
|
||||
DepthFunc = mode;
|
||||
}
|
||||
}
|
||||
|
@ -484,9 +486,9 @@ public:
|
|||
if (DepthMask != enable)
|
||||
{
|
||||
if (enable)
|
||||
glDepthMask(GL_TRUE);
|
||||
GL.DepthMask(GL_TRUE);
|
||||
else
|
||||
glDepthMask(GL_FALSE);
|
||||
GL.DepthMask(GL_FALSE);
|
||||
|
||||
DepthMask = enable;
|
||||
}
|
||||
|
@ -502,9 +504,9 @@ public:
|
|||
if (DepthTest != enable)
|
||||
{
|
||||
if (enable)
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
GL.Enable(GL_DEPTH_TEST);
|
||||
else
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
GL.Disable(GL_DEPTH_TEST);
|
||||
|
||||
DepthTest = enable;
|
||||
}
|
||||
|
@ -572,7 +574,7 @@ public:
|
|||
{
|
||||
if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight)
|
||||
{
|
||||
glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
|
||||
GL.Viewport(viewportX, viewportY, viewportWidth, viewportHeight);
|
||||
ViewportX = viewportX;
|
||||
ViewportY = viewportY;
|
||||
ViewportWidth = viewportWidth;
|
||||
|
|
|
@ -12,10 +12,7 @@
|
|||
#include "CImage.h"
|
||||
#include "CColorConverter.h"
|
||||
|
||||
// Check if GL version we compile with should have the glGenerateMipmap function.
|
||||
#if defined(GL_VERSION_3_0) || defined(GL_ES_VERSION_2_0)
|
||||
#define IRR_OPENGL_HAS_glGenerateMipmap
|
||||
#endif
|
||||
#include "mt_opengl.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
|
@ -90,32 +87,23 @@ public:
|
|||
tmpImages = &Images;
|
||||
}
|
||||
|
||||
glGenTextures(1, &TextureName);
|
||||
GL.GenTextures(1, &TextureName);
|
||||
|
||||
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
|
||||
glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
#ifdef GL_GENERATE_MIPMAP_HINT
|
||||
if (HasMipMaps)
|
||||
{
|
||||
if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED))
|
||||
glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
|
||||
GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
|
||||
else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY))
|
||||
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
||||
GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
||||
else
|
||||
glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(IRR_OPENGL_HAS_glGenerateMipmap) && defined(GL_GENERATE_MIPMAP)
|
||||
if (HasMipMaps)
|
||||
{
|
||||
LegacyAutoGenerateMipMaps = Driver->getTextureCreationFlag(ETCF_AUTO_GENERATE_MIP_MAPS) &&
|
||||
Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE);
|
||||
glTexParameteri(TextureType, GL_GENERATE_MIPMAP, LegacyAutoGenerateMipMaps ? GL_TRUE : GL_FALSE);
|
||||
GL.Hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -174,19 +162,19 @@ public:
|
|||
os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN?ColorFormat:ECF_UNKNOWN], ELL_ERROR);
|
||||
}
|
||||
|
||||
glGenTextures(1, &TextureName);
|
||||
GL.GenTextures(1, &TextureName);
|
||||
|
||||
const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0);
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||
|
||||
|
||||
glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(TextureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
#if defined(GL_VERSION_1_2)
|
||||
glTexParameteri(TextureType, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
GL.TexParameteri(TextureType, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
#endif
|
||||
|
||||
StatesCache.WrapU = ETC_CLAMP_TO_EDGE;
|
||||
|
@ -196,15 +184,15 @@ public:
|
|||
switch (Type)
|
||||
{
|
||||
case ETT_2D:
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
break;
|
||||
case ETT_CUBEMAP:
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
GL.TexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -220,7 +208,7 @@ public:
|
|||
virtual ~COpenGLCoreTexture()
|
||||
{
|
||||
if (TextureName)
|
||||
glDeleteTextures(1, &TextureName);
|
||||
GL.DeleteTextures(1, &TextureName);
|
||||
|
||||
if (LockImage)
|
||||
LockImage->drop();
|
||||
|
@ -278,7 +266,7 @@ public:
|
|||
tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
|
||||
}
|
||||
|
||||
glGetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData());
|
||||
GL.GetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData());
|
||||
Driver->testGLError(__LINE__);
|
||||
|
||||
if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT)
|
||||
|
@ -321,12 +309,12 @@ public:
|
|||
|
||||
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmpTexture->getOpenGLTextureName(), 0);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
GL.Clear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
Driver->draw2DImage(this, layer, true);
|
||||
|
||||
IImage* tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
|
||||
glReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
|
||||
GL.ReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
|
||||
|
||||
Driver->getCacheHandler()->setFBO(prevFBO);
|
||||
Driver->getCacheHandler()->setViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight);
|
||||
|
@ -428,9 +416,7 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifdef IRR_OPENGL_HAS_glGenerateMipmap
|
||||
Driver->irrGlGenerateMipmap(TextureType);
|
||||
#endif
|
||||
}
|
||||
|
||||
Driver->getCacheHandler()->getTextureCache().set(0, prevTexture);
|
||||
|
@ -595,9 +581,9 @@ protected:
|
|||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_CUBE_MAP:
|
||||
if (initTexture)
|
||||
glTexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, PixelFormat, PixelType, tmpData);
|
||||
GL.TexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, PixelFormat, PixelType, tmpData);
|
||||
else
|
||||
glTexSubImage2D(tmpTextureType, level, 0, 0, width, height, PixelFormat, PixelType, tmpData);
|
||||
GL.TexSubImage2D(tmpTextureType, level, 0, 0, width, height, PixelFormat, PixelType, tmpData);
|
||||
Driver->testGLError(__LINE__);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -44,6 +44,7 @@ bool COpenGLDriver::initDriver()
|
|||
ContextManager->generateContext();
|
||||
ExposedData = ContextManager->getContext();
|
||||
ContextManager->activateContext(ExposedData, false);
|
||||
GL.LoadAllProcedures(ContextManager);
|
||||
|
||||
genericDriverInit();
|
||||
|
||||
|
@ -51,8 +52,6 @@ bool COpenGLDriver::initDriver()
|
|||
extGlSwapInterval(Params.Vsync ? 1 : 0);
|
||||
#endif
|
||||
|
||||
GL.LoadAllProcedures(ContextManager);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user