1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Irrlicht cleanups (mostly getting rid of core::array)

Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
sfan5 2024-08-17 19:49:11 +02:00 committed by GitHub
parent 5acc2736db
commit 5d226268df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 308 additions and 1227 deletions

View file

@ -257,7 +257,6 @@ bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d<u32> &screenS
DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Feature.MaxTextureUnits);
// DriverAttributes->setAttribute("MaxLights", MaxLights);
DriverAttributes->setAttribute("MaxAnisotropy", MaxAnisotropy);
// DriverAttributes->setAttribute("MaxUserClipPlanes", MaxUserClipPlanes);
// DriverAttributes->setAttribute("MaxAuxBuffers", MaxAuxBuffers);
// DriverAttributes->setAttribute("MaxMultipleRenderTargets", MaxMultipleRenderTargets);
DriverAttributes->setAttribute("MaxIndices", (s32)MaxIndices);
@ -268,8 +267,6 @@ bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d<u32> &screenS
GL.PixelStorei(GL_PACK_ALIGNMENT, 1);
UserClipPlane.reallocate(0);
for (s32 i = 0; i < ETS_COUNT; ++i)
setTransform(static_cast<E_TRANSFORMATION_STATE>(i), core::IdentityMatrix);
@ -916,7 +913,8 @@ void COpenGL3DriverBase::draw2DImageBatch(const video::ITexture *texture,
const irr::u32 drawCount = core::min_<u32>(positions.size(), sourceRects.size());
assert(6 * drawCount <= QuadIndexCount); // FIXME split the batch? or let it crash?
core::array<S3DVertex> vtx(drawCount * 4);
std::vector<S3DVertex> vtx;
vtx.reserve(drawCount * 4);
for (u32 i = 0; i < drawCount; i++) {
core::position2d<s32> targetPos = positions[i];
@ -939,22 +937,22 @@ void COpenGL3DriverBase::draw2DImageBatch(const video::ITexture *texture,
f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;
vtx.push_back(S3DVertex(left, top, 0.0f,
vtx.emplace_back(left, top, 0.0f,
0.0f, 0.0f, 0.0f, color,
tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y));
vtx.push_back(S3DVertex(right, top, 0.0f,
tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
vtx.emplace_back(right, top, 0.0f,
0.0f, 0.0f, 0.0f, color,
tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y));
vtx.push_back(S3DVertex(right, down, 0.0f,
tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
vtx.emplace_back(right, down, 0.0f,
0.0f, 0.0f, 0.0f, color,
tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y));
vtx.push_back(S3DVertex(left, down, 0.0f,
tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
vtx.emplace_back(left, down, 0.0f,
0.0f, 0.0f, 0.0f, color,
tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y));
tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
}
GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, QuadIndexBuffer);
drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), vtx.size(), 0, 6 * drawCount);
drawElements(GL_TRIANGLES, vt2DImage, vtx.data(), vtx.size(), 0, 6 * drawCount);
GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
if (clipRect)
@ -1104,15 +1102,14 @@ void COpenGL3DriverBase::endDraw(const VertexType &vertexType)
ITexture *COpenGL3DriverBase::createDeviceDependentTexture(const io::path &name, IImage *image)
{
core::array<IImage *> imageArray(1);
imageArray.push_back(image);
std::vector<IImage*> tmp { image };
COpenGL3Texture *texture = new COpenGL3Texture(name, imageArray, ETT_2D, this);
COpenGL3Texture *texture = new COpenGL3Texture(name, tmp, ETT_2D, this);
return texture;
}
ITexture *COpenGL3DriverBase::createDeviceDependentTextureCubemap(const io::path &name, const core::array<IImage *> &image)
ITexture *COpenGL3DriverBase::createDeviceDependentTextureCubemap(const io::path &name, const std::vector<IImage*> &image)
{
COpenGL3Texture *texture = new COpenGL3Texture(name, image, ETT_CUBEMAP, this);
@ -1876,40 +1873,6 @@ void COpenGL3DriverBase::removeTexture(ITexture *texture)
CNullDriver::removeTexture(texture);
}
//! Set/unset a clipping plane.
bool COpenGL3DriverBase::setClipPlane(u32 index, const core::plane3df &plane, bool enable)
{
if (index >= UserClipPlane.size())
UserClipPlane.push_back(SUserClipPlane());
UserClipPlane[index].Plane = plane;
UserClipPlane[index].Enabled = enable;
return true;
}
//! Enable/disable a clipping plane.
void COpenGL3DriverBase::enableClipPlane(u32 index, bool enable)
{
UserClipPlane[index].Enabled = enable;
}
//! Get the ClipPlane Count
u32 COpenGL3DriverBase::getClipPlaneCount() const
{
return UserClipPlane.size();
}
const core::plane3df &COpenGL3DriverBase::getClipPlane(irr::u32 index) const
{
if (index < UserClipPlane.size())
return UserClipPlane[index].Plane;
else {
_IRR_DEBUG_BREAK_IF(true) // invalid index
static const core::plane3df dummy;
return dummy;
}
}
core::dimension2du COpenGL3DriverBase::getMaxTextureSize() const
{
return core::dimension2du(MaxTextureSize, MaxTextureSize);

View file

@ -7,7 +7,6 @@
#pragma once
#include "SIrrCreationParameters.h"
#include "Common.h"
#include "CNullDriver.h"
#include "IMaterialRendererServices.h"
@ -227,18 +226,6 @@ public:
// Does *nothing* unless in debug mode.
bool testGLError(const char *file, int line);
//! Set/unset a clipping plane.
bool setClipPlane(u32 index, const core::plane3df &plane, bool enable = false) override;
//! returns the current amount of user clip planes set.
u32 getClipPlaneCount() const;
//! returns the 0 indexed Plane
const core::plane3df &getClipPlane(u32 index) const;
//! Enable/disable a clipping plane.
void enableClipPlane(u32 index, bool enable) override;
//! Returns the graphics card vendor name.
core::stringc getVendorInfo() override
{
@ -278,7 +265,7 @@ protected:
ITexture *createDeviceDependentTexture(const io::path &name, IImage *image) override;
ITexture *createDeviceDependentTextureCubemap(const io::path &name, const core::array<IImage *> &image) override;
ITexture *createDeviceDependentTextureCubemap(const io::path &name, const std::vector<IImage*> &image) override;
//! Map Irrlicht wrap mode to OpenGL enum
GLint getTextureWrapMode(u8 clamp) const;
@ -337,14 +324,6 @@ protected:
bool LockRenderStateMode;
u8 AntiAlias;
struct SUserClipPlane
{
core::plane3df Plane;
bool Enabled;
};
core::array<SUserClipPlane> UserClipPlane;
core::matrix4 TextureFlipMatrix;
using FColorConverter = void (*)(const void *source, s32 count, void *dest);

View file

@ -262,35 +262,30 @@ bool COpenGL3MaterialRenderer::linkProgram()
// seems that some implementations use an extra null terminator.
++maxlen;
c8 *buf = new c8[maxlen];
std::vector<c8> buf(maxlen);
UniformInfo.clear();
UniformInfo.reallocate(num);
UniformInfo.reserve(num);
for (GLint i = 0; i < num; ++i) {
SUniformInfo ui;
memset(buf, 0, maxlen);
memset(buf.data(), 0, buf.size());
GLint size;
GL.GetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar *>(buf));
core::stringc name = "";
GL.GetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar *>(buf.data()));
// array support, workaround for some bugged drivers.
for (s32 i = 0; i < maxlen; ++i) {
if (buf[i] == '[' || buf[i] == '\0')
break;
name += buf[i];
ui.name += buf[i];
}
ui.name = name;
ui.location = GL.GetUniformLocation(Program, buf);
ui.location = GL.GetUniformLocation(Program, buf.data());
UniformInfo.push_back(ui);
UniformInfo.push_back(std::move(ui));
}
delete[] buf;
}
return true;

View file

@ -4,12 +4,12 @@
#pragma once
#include <string>
#include <vector>
#include "EMaterialTypes.h"
#include "IMaterialRenderer.h"
#include "IMaterialRendererServices.h"
#include "IGPUProgrammingServices.h"
#include "irrArray.h"
#include "irrString.h"
#include "Common.h"
@ -79,13 +79,13 @@ protected:
struct SUniformInfo
{
core::stringc name;
std::string name;
GLenum type;
GLint location;
};
GLuint Program;
core::array<SUniformInfo> UniformInfo;
std::vector<SUniformInfo> UniformInfo;
s32 UserData;
};