[Feat] (DiligentEngine): Implement most rendering by DiligentEngine.

This commit is contained in:
BZLZHH
2025-06-07 19:41:32 +08:00
parent c95077f263
commit f5a14c20a9
29 changed files with 3146 additions and 313 deletions
+3 -5
View File
@@ -5,13 +5,11 @@
#ifndef MOBILEGL_BUFFERSTATE_H
#define MOBILEGL_BUFFERSTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
class BufferState {
template <typename K, typename V>
using unordered_map = ankerl::unordered_dense::map<K, V>;
public:
struct BufferObject {
GLenum usage = GL_STATIC_DRAW;
@@ -46,8 +44,8 @@ public:
void Delete(GLuint buffer);
GLuint GetCurrentBinding(GLenum target) const;
unordered_map<GLenum, GLuint> currentBindings_;
unordered_map<GLuint, BufferObject> buffers_;
MG_Global::unordered_map<GLenum, GLuint> currentBindings_;
MG_Global::unordered_map<GLuint, BufferObject> buffers_;
private:
std::vector<GLuint> freeId_;
GLuint lastId_ = 1;
+3 -4
View File
@@ -5,12 +5,11 @@
#ifndef MOBILEGL_COMMONSTATE_H
#define MOBILEGL_COMMONSTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
class CommonState {
template <typename K, typename V>
using unordered_map = ankerl::unordered_dense::map<K, V>;
public:
// Viewport
GLint viewport[4] = {0, 0, 0, 0};
@@ -19,7 +18,7 @@ public:
GLboolean colorMask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE};
// Pixel storage parameters
unordered_map<GLenum, GLint> pixelStoreParams;
MG_Global::unordered_map<GLenum, GLint> pixelStoreParams;
// Blend state
GLenum blendSrcRGB = GL_ONE;
@@ -37,7 +36,7 @@ public:
GLboolean depthMask = GL_TRUE;
// Capability enables
unordered_map<GLenum, bool> capabilities;
MG_Global::unordered_map<GLenum, bool> capabilities;
CommonState();
+1
View File
@@ -4,6 +4,7 @@
#ifndef MOBILEGL_GLSTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
@@ -47,6 +47,7 @@ GLenum FramebufferState::Bind(GLenum target, GLuint framebuffer) {
if (framebuffer != 0 && !ValidateHandle(framebuffer))
return GL_INVALID_OPERATION;
if (target == GL_FRAMEBUFFER) {
currentBindings_[GL_FRAMEBUFFER] = framebuffer;
currentBindings_[GL_READ_FRAMEBUFFER] = framebuffer;
currentBindings_[GL_DRAW_FRAMEBUFFER] = framebuffer;
} else {
@@ -60,7 +61,7 @@ GLenum FramebufferState::AttachTexture2D(GLenum target, GLenum attachment,
if (MG_Constants::Framebuffer::VALID_ATTACHMENTS.find(attachment) == MG_Constants::Framebuffer::VALID_ATTACHMENTS.end() ||
MG_Constants::Texture::VALID_TARGETS.find(textarget) == MG_Constants::Texture::VALID_TARGETS.end())
return GL_INVALID_ENUM;
if (target == GL_FRAMEBUFFER) target = GL_DRAW_FRAMEBUFFER;
// if (target == GL_FRAMEBUFFER) target = GL_DRAW_FRAMEBUFFER;
FramebufferObject* fbo = GetCurrentFBO(target);
if (!fbo) return GL_INVALID_OPERATION;
if (texture != 0 && !MG_State_T::textureState->IsTexture(texture))
@@ -85,7 +86,7 @@ GLenum FramebufferState::AttachTexture2D(GLenum target, GLenum attachment,
}
GLenum FramebufferState::ValidateCompleteness(GLenum target) {
if (target == GL_FRAMEBUFFER) target = GL_DRAW_FRAMEBUFFER;
// if (target == GL_FRAMEBUFFER) target = GL_DRAW_FRAMEBUFFER;
FramebufferObject* fbo = GetCurrentFBO(target);
if (!fbo) return GL_INVALID_OPERATION;
return fbo->status;
@@ -5,6 +5,7 @@
#ifndef MOBILEGL_FRAMEBUFFERSTATE_H
#define MOBILEGL_FRAMEBUFFERSTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
@@ -17,7 +18,7 @@ struct FramebufferAttachment {
struct FramebufferObject {
bool generated = false;
ankerl::unordered_map<GLenum, FramebufferAttachment> attachments;
MG_Global::unordered_map<GLenum, FramebufferAttachment> attachments;
GLenum status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
GLsizei width = 0;
GLsizei height = 0;
@@ -35,10 +36,10 @@ public:
GLenum ValidateCompleteness(GLenum target);
FramebufferObject* GetCurrentFBO(GLenum target);
ankerl::unordered_map<GLenum, GLuint> currentBindings_; // READ/DRAW
MG_Global::unordered_map<GLenum, GLuint> currentBindings_; // READ/DRAW
private:
ankerl::unordered_map<GLuint, FramebufferObject> framebuffers_;
MG_Global::unordered_map<GLuint, FramebufferObject> framebuffers_;
std::set<GLuint> freeIds_;
GLuint lastId_ = 0;
bool ValidateHandle(GLuint framebuffer);
+7 -6
View File
@@ -5,6 +5,7 @@
#ifndef MOBILEGL_PROGRAMSTATE_H
#define MOBILEGL_PROGRAMSTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#define MOBILEGL_PROGRAM_DEBUGTOOL_H
#define MOBILEGL_GLSLTOOL_H
@@ -41,17 +42,17 @@ struct ProgramObject {
bool dirty;
GLint linkStatus;
std::string infoLog;
ankerl::unordered_map<std::string, GLint> attribBindings;
ankerl::unordered_map<std::string, GLint> attribLocations;
ankerl::unordered_map<std::string, GLint> uniformLocations;
ankerl::unordered_map<std::string, UniformValue> uniformValues;
MG_Global::unordered_map<std::string, GLint> attribBindings;
MG_Global::unordered_map<std::string, GLint> attribLocations;
MG_Global::unordered_map<std::string, GLint> uniformLocations;
MG_Global::unordered_map<std::string, UniformValue> uniformValues;
bool markedForDeletion;
};
class ProgramState {
public:
ankerl::unordered_map<GLuint, ShaderObject> shaders_;
ankerl::unordered_map<GLuint, ProgramObject> programs_;
MG_Global::unordered_map<GLuint, ShaderObject> shaders_;
MG_Global::unordered_map<GLuint, ProgramObject> programs_;
std::set<GLuint> freeShaderIds_;
std::set<GLuint> freeProgramIds_;
GLuint lastShaderId_ = 0;
+1
View File
@@ -6,6 +6,7 @@
#define MOBILEGL_SHADEROBJECT_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
+1 -2
View File
@@ -146,7 +146,6 @@ GLenum TextureState::Bind(GLenum target, GLuint texture) {
}
}
TextureUnitState& unit = textureUnits_[activeTextureUnit_];
TextureObject* texObj = nullptr;
auto it = this->textures.find(texture);
@@ -700,7 +699,7 @@ GLenum TextureState::QueryLevelPropertyIntVector(GLenum target, GLint level, GLe
return GL_NO_ERROR;
}
unordered_map<GLuint, TextureObject>::iterator texIt;
MG_Global::unordered_map<GLuint, TextureObject>::iterator texIt;
if (!isProxyTexture) {
texIt = textures.find(boundTexture);
+8 -13
View File
@@ -5,6 +5,7 @@
#ifndef MOBILEGL_TEXTURESTATE_H
#define MOBILEGL_TEXTURESTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
@@ -19,10 +20,8 @@ struct ComponentSizes {
};
struct TextureParams {
template <typename K, typename V>
using unordered_map = ankerl::unordered_dense::map<K, V>;
unordered_map<GLenum, GLfloat> texPropertiesFloat;
unordered_map<GLenum, GLint> texPropertiesInt;
MG_Global::unordered_map<GLenum, GLfloat> texPropertiesFloat;
MG_Global::unordered_map<GLenum, GLint> texPropertiesInt;
struct MipmapLevel {
GLsizei width = 0;
GLsizei height = 0;
@@ -33,7 +32,7 @@ struct TextureParams {
bool hasData = false;
bool dirty = false; // TODO: encapsulate this with an public API to RHI
};
unordered_map<GLint, MipmapLevel> mipmapData;
MG_Global::unordered_map<GLint, MipmapLevel> mipmapData;
};
class TextureObject {
@@ -47,27 +46,23 @@ public:
};
class TextureUnitState {
template <typename K, typename V>
using unordered_map = ankerl::unordered_dense::map<K, V>;
private:
GLenum activeTarget = GL_TEXTURE_2D;
public:
unordered_map<GLenum, GLuint> boundTextures;
MG_Global::unordered_map<GLenum, GLuint> boundTextures;
void Bind(GLenum target, GLuint texture);
GLuint GetBoundTexture(GLenum target);
};
class TextureState {
template <typename K, typename V>
using unordered_map = ankerl::unordered_dense::map<K, V>;
private:
GLuint lastUsedID_ = 1;
// ankerl::unordered_set<GLuint> freeIDs_;
// MG_Global::unordered_set<GLuint> freeIDs_;
std::vector<GLuint> freeID_;
unordered_map<GLenum, TextureObject> proxyTextures_;
MG_Global::unordered_map<GLenum, TextureObject> proxyTextures_;
static GLint GetUnpackParam_(GLenum pname);
public:
@@ -75,7 +70,7 @@ public:
bool IsTextureGenerated(GLuint texture);
bool IsTexture(GLuint texture);
unordered_map<GLuint, TextureObject> textures;
MG_Global::unordered_map<GLuint, TextureObject> textures;
// Return: the validity of the operation, according to OpenGL 3 standard
GLenum BindUnit(GLenum textureUnit);
@@ -5,6 +5,7 @@
#ifndef MOBILEGL_VERTEXARRAYSTATE_H
#define MOBILEGL_VERTEXARRAYSTATE_H
#define MOBILEGL_GLSTATE_H
#define MOBILEGL_DILIGENT_EGL_IMPL_H
#include "../../../Includes.h"
@@ -24,7 +25,7 @@ struct VertexArrayObject {
bool attribDirty = false;
bool eboDirty = false;
GLuint elementBuffer = 0;
ankerl::unordered_map<GLuint, VertexAttribState> attribs;
MG_Global::unordered_map<GLuint, VertexAttribState> attribs;
};
class VertexArrayState {
@@ -50,7 +51,7 @@ public:
bool ValidateAllocatedHandle(GLuint array);
GLuint currentVao_ = 0;
ankerl::unordered_map<GLuint, VertexArrayObject> vaos_;
MG_Global::unordered_map<GLuint, VertexArrayObject> vaos_;
private:
std::set<GLuint> freeIds_;
GLuint lastId_ = 0;