Reformat the code, using:

find -type f |  # list all regular files
  grep -E '\.(h|cpp|mm)$' |  # filter for source files
  grep -v '/mt_' |  # filter out generated files
  grep -v '/vendor/' | # and vendored GL
  grep -v '/test/image_loader_test.cpp' |  # and this file (has giant literals arrays)
  xargs -n 1 -P $(nproc) clang-format -i  # reformat everything

Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
Desour
2024-03-20 19:35:52 +01:00
parent eb4dec46c2
commit 2bf1d12353
292 changed files with 37376 additions and 42421 deletions

View File

@ -16,22 +16,20 @@ namespace video
enum ESetTextureActive
{
EST_ACTIVE_ALWAYS, // texture unit always active after set call
EST_ACTIVE_ON_CHANGE // texture unit only active after call when texture changed in cache
EST_ACTIVE_ALWAYS, // texture unit always active after set call
EST_ACTIVE_ON_CHANGE // texture unit only active after call when texture changed in cache
};
template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreCacheHandler
{
class STextureCache
{
public:
STextureCache(COpenGLCoreCacheHandler& cacheHandler, E_DRIVER_TYPE driverType, u32 textureCount) :
CacheHandler(cacheHandler), DriverType(driverType), TextureCount(textureCount)
STextureCache(COpenGLCoreCacheHandler &cacheHandler, E_DRIVER_TYPE driverType, u32 textureCount) :
CacheHandler(cacheHandler), DriverType(driverType), TextureCount(textureCount)
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
Texture[i] = 0;
}
}
@ -41,7 +39,7 @@ class COpenGLCoreCacheHandler
clear();
}
const TOpenGLTexture* operator[](int index) const
const TOpenGLTexture *operator[](int index) const
{
if (static_cast<u32>(index) < MATERIAL_MAX_TEXTURES)
return Texture[static_cast<u32>(index)];
@ -49,7 +47,7 @@ class COpenGLCoreCacheHandler
return 0;
}
const TOpenGLTexture* get(u32 index) const
const TOpenGLTexture *get(u32 index) const
{
if (index < MATERIAL_MAX_TEXTURES)
return Texture[index];
@ -57,54 +55,47 @@ class COpenGLCoreCacheHandler
return 0;
}
bool set(u32 index, const ITexture* texture, ESetTextureActive esa=EST_ACTIVE_ALWAYS)
bool set(u32 index, const ITexture *texture, ESetTextureActive esa = EST_ACTIVE_ALWAYS)
{
bool status = false;
E_DRIVER_TYPE type = DriverType;
if (index < MATERIAL_MAX_TEXTURES && index < TextureCount)
{
if ( esa == EST_ACTIVE_ALWAYS )
if (index < MATERIAL_MAX_TEXTURES && index < TextureCount) {
if (esa == EST_ACTIVE_ALWAYS)
CacheHandler.setActiveTexture(GL_TEXTURE0 + index);
const TOpenGLTexture* prevTexture = Texture[index];
const TOpenGLTexture *prevTexture = Texture[index];
if (texture != prevTexture)
{
if ( esa == EST_ACTIVE_ON_CHANGE )
if (texture != prevTexture) {
if (esa == EST_ACTIVE_ON_CHANGE)
CacheHandler.setActiveTexture(GL_TEXTURE0 + index);
if (texture)
{
if (texture) {
type = texture->getDriverType();
if (type == DriverType)
{
if (type == DriverType) {
texture->grab();
const TOpenGLTexture* curTexture = static_cast<const TOpenGLTexture*>(texture);
const TOpenGLTexture *curTexture = static_cast<const TOpenGLTexture *>(texture);
const GLenum curTextureType = curTexture->getOpenGLTextureType();
const GLenum prevTextureType = (prevTexture) ? prevTexture->getOpenGLTextureType() : curTextureType;
if (curTextureType != prevTextureType)
{
if (curTextureType != prevTextureType) {
GL.BindTexture(prevTextureType, 0);
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON))
GL.Disable(prevTextureType);
GL.Enable(curTextureType);
#endif
}
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON))
else if (!prevTexture)
GL.Enable(curTextureType);
#endif
GL.BindTexture(curTextureType, static_cast<const TOpenGLTexture*>(texture)->getOpenGLTextureName());
}
else
{
GL.BindTexture(curTextureType, static_cast<const TOpenGLTexture *>(texture)->getOpenGLTextureName());
} else {
texture = 0;
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
@ -113,18 +104,17 @@ class COpenGLCoreCacheHandler
}
}
if (!texture && prevTexture)
{
if (!texture && prevTexture) {
const GLenum prevTextureType = prevTexture->getOpenGLTextureType();
GL.BindTexture(prevTextureType, 0);
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON))
GL.Disable(prevTextureType);
#endif
}
Texture[index] = static_cast<const TOpenGLTexture*>(texture);
Texture[index] = static_cast<const TOpenGLTexture *>(texture);
if (prevTexture)
prevTexture->drop();
@ -136,15 +126,13 @@ class COpenGLCoreCacheHandler
return (status && type == DriverType);
}
void remove(ITexture* texture)
void remove(ITexture *texture)
{
if (!texture)
return;
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
if (Texture[i] == texture)
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
if (Texture[i] == texture) {
Texture[i] = 0;
texture->drop();
@ -154,11 +142,9 @@ class COpenGLCoreCacheHandler
void clear()
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
{
if (Texture[i])
{
const TOpenGLTexture* prevTexture = Texture[i];
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
if (Texture[i]) {
const TOpenGLTexture *prevTexture = Texture[i];
Texture[i] = 0;
@ -168,31 +154,31 @@ class COpenGLCoreCacheHandler
}
private:
COpenGLCoreCacheHandler& CacheHandler;
COpenGLCoreCacheHandler &CacheHandler;
E_DRIVER_TYPE DriverType;
const TOpenGLTexture* Texture[MATERIAL_MAX_TEXTURES];
const TOpenGLTexture *Texture[MATERIAL_MAX_TEXTURES];
u32 TextureCount;
};
public:
COpenGLCoreCacheHandler(TOpenGLDriver* driver) :
Driver(driver),
COpenGLCoreCacheHandler(TOpenGLDriver *driver) :
Driver(driver),
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4355) // Warning: "'this' : used in base member initializer list. ". It's OK, we don't use the reference in STextureCache constructor.
#pragma warning(disable : 4355) // Warning: "'this' : used in base member initializer list. ". It's OK, we don't use the reference in STextureCache constructor.
#endif
TextureCache(STextureCache(*this, driver->getDriverType(), driver->getFeature().MaxTextureUnits)),
TextureCache(STextureCache(*this, driver->getDriverType(), driver->getFeature().MaxTextureUnits)),
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
FrameBufferCount(0), BlendEquation(0), BlendSourceRGB(0),
BlendDestinationRGB(0), BlendSourceAlpha(0), BlendDestinationAlpha(0), Blend(0), BlendEquationInvalid(false), BlendFuncInvalid(false), BlendInvalid(false),
ColorMask(0), ColorMaskInvalid(false), CullFaceMode(GL_BACK), CullFace(false), DepthFunc(GL_LESS), DepthMask(true), DepthTest(false), FrameBufferID(0),
ProgramID(0), ActiveTexture(GL_TEXTURE0), ViewportX(0), ViewportY(0)
FrameBufferCount(0), BlendEquation(0), BlendSourceRGB(0),
BlendDestinationRGB(0), BlendSourceAlpha(0), BlendDestinationAlpha(0), Blend(0), BlendEquationInvalid(false), BlendFuncInvalid(false), BlendInvalid(false),
ColorMask(0), ColorMaskInvalid(false), CullFaceMode(GL_BACK), CullFace(false), DepthFunc(GL_LESS), DepthMask(true), DepthTest(false), FrameBufferID(0),
ProgramID(0), ActiveTexture(GL_TEXTURE0), ViewportX(0), ViewportY(0)
{
const COpenGLCoreFeature& feature = Driver->getFeature();
const COpenGLCoreFeature &feature = Driver->getFeature();
FrameBufferCount = core::max_(static_cast<GLuint>(1), static_cast<GLuint>(feature.MultipleRenderTarget));
@ -206,13 +192,11 @@ public:
// Initial OpenGL values from specification.
if (feature.BlendOperation)
{
if (feature.BlendOperation) {
Driver->irrGlBlendEquation(GL_FUNC_ADD);
}
for (u32 i = 0; i < FrameBufferCount; ++i)
{
for (u32 i = 0; i < FrameBufferCount; ++i) {
BlendEquation[i] = GL_FUNC_ADD;
BlendSourceRGB[i] = GL_ONE;
@ -238,7 +222,7 @@ public:
Driver->irrGlActiveTexture(ActiveTexture);
#if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) )
#if (defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON))
GL.Disable(GL_TEXTURE_2D);
#endif
@ -265,7 +249,7 @@ public:
return Driver->getDriverType();
}
STextureCache& getTextureCache()
STextureCache &getTextureCache()
{
return TextureCache;
}
@ -274,8 +258,7 @@ public:
void setBlendEquation(GLenum mode)
{
if (BlendEquation[0] != mode || BlendEquationInvalid)
{
if (BlendEquation[0] != mode || BlendEquationInvalid) {
Driver->irrGlBlendEquation(mode);
for (GLuint i = 0; i < FrameBufferCount; ++i)
@ -287,8 +270,7 @@ public:
void setBlendEquationIndexed(GLuint index, GLenum mode)
{
if (index < FrameBufferCount && BlendEquation[index] != mode)
{
if (index < FrameBufferCount && BlendEquation[index] != mode) {
Driver->irrGlBlendEquationIndexed(index, mode);
BlendEquation[index] = mode;
@ -299,13 +281,11 @@ public:
void setBlendFunc(GLenum source, GLenum destination)
{
if (BlendSourceRGB[0] != source || BlendDestinationRGB[0] != destination ||
BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination ||
BlendFuncInvalid)
{
BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination ||
BlendFuncInvalid) {
GL.BlendFunc(source, destination);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
for (GLuint i = 0; i < FrameBufferCount; ++i) {
BlendSourceRGB[i] = source;
BlendDestinationRGB[i] = destination;
BlendSourceAlpha[i] = source;
@ -318,16 +298,13 @@ public:
void setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha) {
if (BlendSourceRGB[0] != sourceRGB || BlendDestinationRGB[0] != destinationRGB ||
BlendSourceAlpha[0] != sourceAlpha || BlendDestinationAlpha[0] != destinationAlpha ||
BlendFuncInvalid)
{
BlendSourceAlpha[0] != sourceAlpha || BlendDestinationAlpha[0] != destinationAlpha ||
BlendFuncInvalid) {
Driver->irrGlBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
for (GLuint i = 0; i < FrameBufferCount; ++i)
{
for (GLuint i = 0; i < FrameBufferCount; ++i) {
BlendSourceRGB[i] = sourceRGB;
BlendDestinationRGB[i] = destinationRGB;
BlendSourceAlpha[i] = sourceAlpha;
@ -336,9 +313,7 @@ public:
BlendFuncInvalid = false;
}
}
else
{
} else {
setBlendFunc(sourceRGB, destinationRGB);
}
}
@ -346,8 +321,7 @@ public:
void setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination)
{
if (index < FrameBufferCount && (BlendSourceRGB[index] != source || BlendDestinationRGB[index] != destination ||
BlendSourceAlpha[index] != source || BlendDestinationAlpha[index] != destination))
{
BlendSourceAlpha[index] != source || BlendDestinationAlpha[index] != destination)) {
Driver->irrGlBlendFuncIndexed(index, source, destination);
BlendSourceRGB[index] = source;
@ -360,11 +334,9 @@ public:
void setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
{
if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha) {
if (index < FrameBufferCount && (BlendSourceRGB[index] != sourceRGB || BlendDestinationRGB[index] != destinationRGB ||
BlendSourceAlpha[index] != sourceAlpha || BlendDestinationAlpha[index] != destinationAlpha))
{
BlendSourceAlpha[index] != sourceAlpha || BlendDestinationAlpha[index] != destinationAlpha)) {
Driver->irrGlBlendFuncSeparateIndexed(index, sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);
BlendSourceRGB[index] = sourceRGB;
@ -373,17 +345,14 @@ public:
BlendDestinationAlpha[index] = destinationAlpha;
BlendFuncInvalid = true;
}
}
else
{
} else {
setBlendFuncIndexed(index, sourceRGB, destinationRGB);
}
}
void setBlend(bool enable)
{
if (Blend[0] != enable || BlendInvalid)
{
if (Blend[0] != enable || BlendInvalid) {
if (enable)
GL.Enable(GL_BLEND);
else
@ -398,8 +367,7 @@ public:
void setBlendIndexed(GLuint index, bool enable)
{
if (index < FrameBufferCount && Blend[index] != enable)
{
if (index < FrameBufferCount && Blend[index] != enable) {
if (enable)
Driver->irrGlEnableIndexed(GL_BLEND, index);
else
@ -412,15 +380,14 @@ public:
// Color Mask.
void getColorMask(u8& mask)
void getColorMask(u8 &mask)
{
mask = ColorMask[0];
}
void setColorMask(u8 mask)
{
if (ColorMask[0] != mask || ColorMaskInvalid)
{
if (ColorMask[0] != mask || ColorMaskInvalid) {
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)
@ -432,8 +399,7 @@ public:
void setColorMaskIndexed(GLuint index, u8 mask)
{
if (index < FrameBufferCount && ColorMask[index] != mask)
{
if (index < FrameBufferCount && ColorMask[index] != mask) {
Driver->irrGlColorMaskIndexed(index, (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);
ColorMask[index] = mask;
@ -445,8 +411,7 @@ public:
void setCullFaceFunc(GLenum mode)
{
if (CullFaceMode != mode)
{
if (CullFaceMode != mode) {
GL.CullFace(mode);
CullFaceMode = mode;
}
@ -454,8 +419,7 @@ public:
void setCullFace(bool enable)
{
if (CullFace != enable)
{
if (CullFace != enable) {
if (enable)
GL.Enable(GL_CULL_FACE);
else
@ -469,22 +433,20 @@ public:
void setDepthFunc(GLenum mode)
{
if (DepthFunc != mode)
{
if (DepthFunc != mode) {
GL.DepthFunc(mode);
DepthFunc = mode;
}
}
void getDepthMask(bool& depth)
void getDepthMask(bool &depth)
{
depth = DepthMask;
}
void setDepthMask(bool enable)
{
if (DepthMask != enable)
{
if (DepthMask != enable) {
if (enable)
GL.DepthMask(GL_TRUE);
else
@ -494,15 +456,14 @@ public:
}
}
void getDepthTest(bool& enable)
{
enable = DepthTest;
}
void getDepthTest(bool &enable)
{
enable = DepthTest;
}
void setDepthTest(bool enable)
{
if (DepthTest != enable)
{
if (DepthTest != enable) {
if (enable)
GL.Enable(GL_DEPTH_TEST);
else
@ -514,15 +475,14 @@ public:
// FBO calls.
void getFBO(GLuint& frameBufferID) const
void getFBO(GLuint &frameBufferID) const
{
frameBufferID = FrameBufferID;
}
void setFBO(GLuint frameBufferID)
{
if (FrameBufferID != frameBufferID)
{
if (FrameBufferID != frameBufferID) {
Driver->irrGlBindFramebuffer(GL_FRAMEBUFFER, frameBufferID);
FrameBufferID = frameBufferID;
}
@ -530,15 +490,14 @@ public:
// Shaders calls.
void getProgram(GLuint& programID) const
void getProgram(GLuint &programID) const
{
programID = ProgramID;
}
void setProgram(GLuint programID)
{
if (ProgramID != programID)
{
if (ProgramID != programID) {
Driver->irrGlUseProgram(programID);
ProgramID = programID;
}
@ -546,15 +505,14 @@ public:
// Texture calls.
void getActiveTexture(GLenum& texture) const
void getActiveTexture(GLenum &texture) const
{
texture = ActiveTexture;
}
void setActiveTexture(GLenum texture)
{
if (ActiveTexture != texture)
{
if (ActiveTexture != texture) {
Driver->irrGlActiveTexture(texture);
ActiveTexture = texture;
}
@ -562,7 +520,7 @@ public:
// Viewport calls.
void getViewport(GLint& viewportX, GLint& viewportY, GLsizei& viewportWidth, GLsizei& viewportHeight) const
void getViewport(GLint &viewportX, GLint &viewportY, GLsizei &viewportWidth, GLsizei &viewportHeight) const
{
viewportX = ViewportX;
viewportY = ViewportY;
@ -572,8 +530,7 @@ public:
void setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight)
{
if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight)
{
if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight) {
GL.Viewport(viewportX, viewportY, viewportWidth, viewportHeight);
ViewportX = viewportX;
ViewportY = viewportY;
@ -585,37 +542,34 @@ public:
//! Compare material to current cache and update it when there are differences
// Some material renderers do change the cache beyond the original material settings
// This corrects the material to represent the current cache state again.
void correctCacheMaterial(irr::video::SMaterial& material)
void correctCacheMaterial(irr::video::SMaterial &material)
{
// Fix textures which got removed
for ( u32 i=0; i < MATERIAL_MAX_TEXTURES; ++i )
{
if ( material.TextureLayers[i].Texture && !TextureCache[i] )
{
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i) {
if (material.TextureLayers[i].Texture && !TextureCache[i]) {
material.TextureLayers[i].Texture = 0;
}
}
}
protected:
TOpenGLDriver* Driver;
TOpenGLDriver *Driver;
STextureCache TextureCache;
GLuint FrameBufferCount;
GLenum* BlendEquation;
GLenum* BlendSourceRGB;
GLenum* BlendDestinationRGB;
GLenum* BlendSourceAlpha;
GLenum* BlendDestinationAlpha;
bool* Blend;
GLenum *BlendEquation;
GLenum *BlendSourceRGB;
GLenum *BlendDestinationRGB;
GLenum *BlendSourceAlpha;
GLenum *BlendDestinationAlpha;
bool *Blend;
bool BlendEquationInvalid;
bool BlendFuncInvalid;
bool BlendInvalid;
u8* ColorMask;
u8 *ColorMask;
bool ColorMaskInvalid;
GLenum CullFaceMode;