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

@ -23,8 +23,9 @@ template <class TOpenGLDriver, class TOpenGLTexture>
class COpenGLCoreRenderTarget : public IRenderTarget
{
public:
COpenGLCoreRenderTarget(TOpenGLDriver* driver) : AssignedDepth(false), AssignedStencil(false), RequestTextureUpdate(false), RequestDepthStencilUpdate(false),
BufferID(0), ColorAttachment(0), MultipleRenderTarget(0), Driver(driver)
COpenGLCoreRenderTarget(TOpenGLDriver *driver) :
AssignedDepth(false), AssignedStencil(false), RequestTextureUpdate(false), RequestDepthStencilUpdate(false),
BufferID(0), ColorAttachment(0), MultipleRenderTarget(0), Driver(driver)
{
#ifdef _DEBUG
setDebugName("COpenGLCoreRenderTarget");
@ -51,8 +52,7 @@ public:
if (ColorAttachment > 0 && BufferID != 0)
Driver->irrGlDeleteFramebuffers(1, &BufferID);
for (u32 i = 0; i < Textures.size(); ++i)
{
for (u32 i = 0; i < Textures.size(); ++i) {
if (Textures[i])
Textures[i]->drop();
}
@ -61,19 +61,17 @@ public:
DepthStencil->drop();
}
void setTextures(ITexture* const * textures, u32 numTextures, ITexture* depthStencil, const E_CUBE_SURFACE* cubeSurfaces, u32 numCubeSurfaces) override
void setTextures(ITexture *const *textures, u32 numTextures, ITexture *depthStencil, const E_CUBE_SURFACE *cubeSurfaces, u32 numCubeSurfaces) override
{
bool needSizeUpdate = false;
// Set color attachments.
if (!Textures.equals(textures, numTextures) || !CubeSurfaces.equals(cubeSurfaces, numCubeSurfaces))
{
if (!Textures.equals(textures, numTextures) || !CubeSurfaces.equals(cubeSurfaces, numCubeSurfaces)) {
needSizeUpdate = true;
core::array<ITexture*> prevTextures(Textures);
core::array<ITexture *> prevTextures(Textures);
if (numTextures > static_cast<u32>(ColorAttachment))
{
if (numTextures > static_cast<u32>(ColorAttachment)) {
core::stringc message = "This GPU supports up to ";
message += static_cast<u32>(ColorAttachment);
message += " textures per render target.";
@ -83,30 +81,24 @@ public:
Textures.set_used(core::min_(numTextures, static_cast<u32>(ColorAttachment)));
for (u32 i = 0; i < Textures.size(); ++i)
{
TOpenGLTexture* currentTexture = (textures[i] && textures[i]->getDriverType() == DriverType) ? static_cast<TOpenGLTexture*>(textures[i]) : 0;
for (u32 i = 0; i < Textures.size(); ++i) {
TOpenGLTexture *currentTexture = (textures[i] && textures[i]->getDriverType() == DriverType) ? static_cast<TOpenGLTexture *>(textures[i]) : 0;
GLuint textureID = 0;
if (currentTexture)
{
if (currentTexture) {
textureID = currentTexture->getOpenGLTextureName();
}
if (textureID != 0)
{
if (textureID != 0) {
Textures[i] = textures[i];
Textures[i]->grab();
}
else
{
} else {
Textures[i] = 0;
}
}
for (u32 i = 0; i < prevTextures.size(); ++i)
{
for (u32 i = 0; i < prevTextures.size(); ++i) {
if (prevTextures[i])
prevTextures[i]->drop();
}
@ -114,43 +106,33 @@ public:
RequestTextureUpdate = true;
}
if (!CubeSurfaces.equals(cubeSurfaces, numCubeSurfaces))
{
if (!CubeSurfaces.equals(cubeSurfaces, numCubeSurfaces)) {
CubeSurfaces.set_data(cubeSurfaces, numCubeSurfaces);
RequestTextureUpdate = true;
}
// Set depth and stencil attachments.
if (DepthStencil != depthStencil)
{
if (DepthStencil)
{
if (DepthStencil != depthStencil) {
if (DepthStencil) {
DepthStencil->drop();
DepthStencil = 0;
}
needSizeUpdate = true;
TOpenGLTexture* currentTexture = (depthStencil && depthStencil->getDriverType() == DriverType) ? static_cast<TOpenGLTexture*>(depthStencil) : 0;
TOpenGLTexture *currentTexture = (depthStencil && depthStencil->getDriverType() == DriverType) ? static_cast<TOpenGLTexture *>(depthStencil) : 0;
if (currentTexture)
{
if (currentTexture->getType() == ETT_2D)
{
if (currentTexture) {
if (currentTexture->getType() == ETT_2D) {
GLuint textureID = currentTexture->getOpenGLTextureName();
const ECOLOR_FORMAT textureFormat = (textureID != 0) ? depthStencil->getColorFormat() : ECF_UNKNOWN;
if (IImage::isDepthFormat(textureFormat))
{
if (IImage::isDepthFormat(textureFormat)) {
DepthStencil = depthStencil;
DepthStencil->grab();
}
else
{
} else {
os::Printer::log("Ignoring depth/stencil texture without depth color format.", ELL_WARNING);
}
}
else
{
} else {
os::Printer::log("This driver doesn't support depth/stencil to cubemaps.", ELL_WARNING);
}
}
@ -158,16 +140,14 @@ public:
RequestDepthStencilUpdate = true;
}
if (needSizeUpdate)
{
if (needSizeUpdate) {
// Set size required for a viewport.
ITexture* firstTexture = getTexture();
ITexture *firstTexture = getTexture();
if (firstTexture)
Size = firstTexture->getSize();
else
{
else {
if (DepthStencil)
Size = DepthStencil->getSize();
else
@ -178,32 +158,26 @@ public:
void update()
{
if (RequestTextureUpdate || RequestDepthStencilUpdate)
{
if (RequestTextureUpdate || RequestDepthStencilUpdate) {
// Set color attachments.
if (RequestTextureUpdate)
{
if (RequestTextureUpdate) {
// Set new color textures.
const u32 textureSize = core::min_(Textures.size(), AssignedTextures.size());
for (u32 i = 0; i < textureSize; ++i)
{
TOpenGLTexture* currentTexture = static_cast<TOpenGLTexture*>(Textures[i]);
for (u32 i = 0; i < textureSize; ++i) {
TOpenGLTexture *currentTexture = static_cast<TOpenGLTexture *>(Textures[i]);
GLuint textureID = currentTexture ? currentTexture->getOpenGLTextureName() : 0;
if (textureID != 0)
{
if (textureID != 0) {
AssignedTextures[i] = GL_COLOR_ATTACHMENT0 + i;
GLenum textarget = currentTexture->getType() == ETT_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)CubeSurfaces[i];
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], textarget, textureID, 0);
#ifdef _DEBUG
Driver->testGLError(__LINE__);
#endif
}
else if (AssignedTextures[i] != GL_NONE)
{
} else if (AssignedTextures[i] != GL_NONE) {
AssignedTextures[i] = GL_NONE;
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], GL_TEXTURE_2D, 0, 0);
@ -213,10 +187,8 @@ public:
// Reset other render target channels.
for (u32 i = textureSize; i < AssignedTextures.size(); ++i)
{
if (AssignedTextures[i] != GL_NONE)
{
for (u32 i = textureSize; i < AssignedTextures.size(); ++i) {
if (AssignedTextures[i] != GL_NONE) {
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], GL_TEXTURE_2D, 0, 0);
AssignedTextures[i] = GL_NONE;
}
@ -227,37 +199,29 @@ public:
// Set depth and stencil attachments.
if (RequestDepthStencilUpdate)
{
if (RequestDepthStencilUpdate) {
const ECOLOR_FORMAT textureFormat = (DepthStencil) ? DepthStencil->getColorFormat() : ECF_UNKNOWN;
if (IImage::isDepthFormat(textureFormat))
{
GLuint textureID = static_cast<TOpenGLTexture*>(DepthStencil)->getOpenGLTextureName();
if (IImage::isDepthFormat(textureFormat)) {
GLuint textureID = static_cast<TOpenGLTexture *>(DepthStencil)->getOpenGLTextureName();
#ifdef _IRR_EMSCRIPTEN_PLATFORM_ // The WEBGL_depth_texture extension does not allow attaching stencil+depth separate.
if (textureFormat == ECF_D24S8)
{
#ifdef _IRR_EMSCRIPTEN_PLATFORM_ // The WEBGL_depth_texture extension does not allow attaching stencil+depth separate.
if (textureFormat == ECF_D24S8) {
GLenum attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, textureID, 0);
AssignedStencil = true;
}
else
{
} else {
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0);
AssignedStencil = false;
}
#else
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0);
if (textureFormat == ECF_D24S8)
{
if (textureFormat == ECF_D24S8) {
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textureID, 0);
AssignedStencil = true;
}
else
{
} else {
if (AssignedStencil)
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
@ -265,9 +229,7 @@ public:
}
#endif
AssignedDepth = true;
}
else
{
} else {
if (AssignedDepth)
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
@ -286,16 +248,14 @@ public:
// Configure drawing operation.
if (ColorAttachment > 0 && BufferID != 0)
{
if (ColorAttachment > 0 && BufferID != 0) {
const u32 textureSize = Textures.size();
if (textureSize == 0)
Driver->irrGlDrawBuffer(GL_NONE);
else if (textureSize == 1 || MultipleRenderTarget == 0)
Driver->irrGlDrawBuffer(GL_COLOR_ATTACHMENT0);
else
{
else {
const u32 bufferCount = core::min_(MultipleRenderTarget, core::min_(textureSize, AssignedTextures.size()));
Driver->irrGlDrawBuffers(bufferCount, AssignedTextures.pointer());
@ -304,7 +264,6 @@ public:
#ifdef _DEBUG
Driver->testGLError(__LINE__);
#endif
}
#ifdef _DEBUG
@ -318,15 +277,14 @@ public:
return BufferID;
}
const core::dimension2d<u32>& getSize() const
const core::dimension2d<u32> &getSize() const
{
return Size;
}
ITexture* getTexture() const
ITexture *getTexture() const
{
for (u32 i = 0; i < Textures.size(); ++i)
{
for (u32 i = 0; i < Textures.size(); ++i) {
if (Textures[i])
return Textures[i];
}
@ -335,41 +293,40 @@ public:
}
protected:
bool checkFBO(TOpenGLDriver* driver)
bool checkFBO(TOpenGLDriver *driver)
{
if (ColorAttachment == 0)
return true;
GLenum status = driver->irrGlCheckFramebufferStatus(GL_FRAMEBUFFER);
switch (status)
{
case GL_FRAMEBUFFER_COMPLETE:
return true;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
os::Printer::log("FBO has invalid read buffer", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
os::Printer::log("FBO has invalid draw buffer", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
os::Printer::log("FBO missing an image attachment", ELL_ERROR);
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
os::Printer::log("FBO format unsupported", ELL_ERROR);
break;
default:
os::Printer::log("FBO error", ELL_ERROR);
break;
switch (status) {
case GL_FRAMEBUFFER_COMPLETE:
return true;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
os::Printer::log("FBO has invalid read buffer", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
os::Printer::log("FBO has invalid draw buffer", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
os::Printer::log("FBO missing an image attachment", ELL_ERROR);
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
os::Printer::log("FBO format unsupported", ELL_ERROR);
break;
default:
os::Printer::log("FBO error", ELL_ERROR);
break;
}
return false;
@ -389,7 +346,7 @@ protected:
u32 ColorAttachment;
u32 MultipleRenderTarget;
TOpenGLDriver* Driver;
TOpenGLDriver *Driver;
};
}