mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Fix] (MG_State): Make uniformObj.count correct. Disable all freeIds now.
This commit is contained in:
@@ -219,7 +219,8 @@ bool BufferState::ValidateGeneratedName(GLuint buffer) {
|
|||||||
void BufferState::Delete(GLuint buffer) {
|
void BufferState::Delete(GLuint buffer) {
|
||||||
buffers_.erase(buffer);
|
buffers_.erase(buffer);
|
||||||
if (ValidateGeneratedName(buffer))
|
if (ValidateGeneratedName(buffer))
|
||||||
freeId_.emplace_back(buffer);
|
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
|
||||||
|
//freeId_.emplace_back(buffer);
|
||||||
for (auto& [target, id] : currentBindings_) {
|
for (auto& [target, id] : currentBindings_) {
|
||||||
if (id == buffer) id = 0;
|
if (id == buffer) id = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ GLenum FramebufferState::Delete(GLuint framebuffer) {
|
|||||||
if (framebuffer == 0) return GL_INVALID_VALUE;
|
if (framebuffer == 0) return GL_INVALID_VALUE;
|
||||||
|
|
||||||
if (framebuffers_.erase(framebuffer)) {
|
if (framebuffers_.erase(framebuffer)) {
|
||||||
freeIds_.insert(framebuffer);
|
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
|
||||||
|
//freeIds_.insert(framebuffer);
|
||||||
for (auto& [target, id] : currentBindings_) {
|
for (auto& [target, id] : currentBindings_) {
|
||||||
if (id == framebuffer) id = 0;
|
if (id == framebuffer) id = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ GLenum ProgramState::DeleteProgram(GLuint program) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
programs_.erase(program);
|
programs_.erase(program);
|
||||||
freeProgramIds_.insert(program);
|
//freeProgramIds_.insert(program);
|
||||||
if (currentProgram_ == program)
|
if (currentProgram_ == program)
|
||||||
currentProgram_ = 0;
|
currentProgram_ = 0;
|
||||||
MG_Util::Debug::LogD("MG_State: Program: DeleteProgram success, id=%u", program);
|
MG_Util::Debug::LogD("MG_State: Program: DeleteProgram success, id=%u", program);
|
||||||
@@ -261,6 +261,7 @@ GLenum ProgramState::SetUniform(GLuint program, GLint location, GLsizei count, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
UniformValue& uniform = prog.uniformValues[uniformName];
|
UniformValue& uniform = prog.uniformValues[uniformName];
|
||||||
|
|
||||||
uniform.setData(type, count, value);
|
uniform.setData(type, count, value);
|
||||||
MG_Util::Debug::LogD("MG_State: Program: SetUniform success: %s set", uniformName.c_str());
|
MG_Util::Debug::LogD("MG_State: Program: SetUniform success: %s set", uniformName.c_str());
|
||||||
return GL_NO_ERROR;
|
return GL_NO_ERROR;
|
||||||
@@ -303,7 +304,7 @@ GLenum ProgramState::SetUniformMatrix(GLuint program, GLint location, GLsizei co
|
|||||||
}
|
}
|
||||||
|
|
||||||
UniformValue& uniform = prog.uniformValues[uniformName];
|
UniformValue& uniform = prog.uniformValues[uniformName];
|
||||||
uniform.setData(matrixType, count * MG_Util::Program::GetMatrixElementCount(matrixType), value);
|
uniform.setData(matrixType, count, value);
|
||||||
MG_Util::Debug::LogD("MG_State: Program: SetUniformMatrix success: %s set", uniformName.c_str());
|
MG_Util::Debug::LogD("MG_State: Program: SetUniformMatrix success: %s set", uniformName.c_str());
|
||||||
return GL_NO_ERROR;
|
return GL_NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -334,15 +335,15 @@ void ProgramState::UpdateUniform##suffix##Vector1(GLint location, GLsizei count,
|
|||||||
} \
|
} \
|
||||||
void ProgramState::UpdateUniform##suffix##Vector2(GLint location, GLsizei count, const type* value) { \
|
void ProgramState::UpdateUniform##suffix##Vector2(GLint location, GLsizei count, const type* value) { \
|
||||||
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector2 called, location=%d, count=%d", location, count); \
|
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector2 called, location=%d, count=%d", location, count); \
|
||||||
SetUniform<type>(currentProgram_, location, count * 2, value, vecType); \
|
SetUniform<type>(currentProgram_, location, count, value, vecType); \
|
||||||
} \
|
} \
|
||||||
void ProgramState::UpdateUniform##suffix##Vector3(GLint location, GLsizei count, const type* value) { \
|
void ProgramState::UpdateUniform##suffix##Vector3(GLint location, GLsizei count, const type* value) { \
|
||||||
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector3 called, location=%d, count=%d", location, count); \
|
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector3 called, location=%d, count=%d", location, count); \
|
||||||
SetUniform<type>(currentProgram_, location, count * 3, value, vecType); \
|
SetUniform<type>(currentProgram_, location, count, value, vecType); \
|
||||||
} \
|
} \
|
||||||
void ProgramState::UpdateUniform##suffix##Vector4(GLint location, GLsizei count, const type* value) { \
|
void ProgramState::UpdateUniform##suffix##Vector4(GLint location, GLsizei count, const type* value) { \
|
||||||
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector4 called, location=%d, count=%d", location, count); \
|
MG_Util::Debug::LogD("MG_State: Program: UpdateUniform" #suffix "Vector4 called, location=%d, count=%d", location, count); \
|
||||||
SetUniform<type>(currentProgram_, location, count * 4, value, vecType); \
|
SetUniform<type>(currentProgram_, location, count, value, vecType); \
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_UNIFORM_FUNCTIONS(GLfloat, Float, GL_FLOAT_VEC4)
|
IMPLEMENT_UNIFORM_FUNCTIONS(GLfloat, Float, GL_FLOAT_VEC4)
|
||||||
@@ -462,16 +463,62 @@ void ProgramState::CleanupShaders_() {
|
|||||||
|
|
||||||
// UniformValue
|
// UniformValue
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void UniformValue::setData(GLenum uniformType, GLsizei numElements, const T* values) {
|
void UniformValue::setData(GLenum uniformType, GLsizei count_, const T* values) {
|
||||||
MG_Util::Debug::LogD("MG_State: Program: UniformValue::setData called, type=0x%X, count=%d", uniformType, numElements);
|
MG_Util::Debug::LogD("MG_State: Program: UniformValue::setData called, type=0x%X, count=%d", uniformType, count_);
|
||||||
//type = uniformType;
|
//type = uniformType;
|
||||||
count = numElements;
|
count = count_;
|
||||||
|
|
||||||
floatData.clear();
|
floatData.clear();
|
||||||
intData.clear();
|
intData.clear();
|
||||||
uintData.clear();
|
uintData.clear();
|
||||||
boolData.clear();
|
boolData.clear();
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case GL_FLOAT: numElements = count_ * 1; break;
|
||||||
|
case GL_FLOAT_VEC2: numElements = count_ * 2; break;
|
||||||
|
case GL_FLOAT_VEC3: numElements = count_ * 3; break;
|
||||||
|
case GL_FLOAT_VEC4: numElements = count_ * 4; break;
|
||||||
|
case GL_INT: numElements = count_ * 1; break;
|
||||||
|
case GL_INT_VEC2: numElements = count_ * 2; break;
|
||||||
|
case GL_INT_VEC3: numElements = count_ * 3; break;
|
||||||
|
case GL_INT_VEC4: numElements = count_ * 4; break;
|
||||||
|
case GL_UNSIGNED_INT: numElements = count_ * 1; break;
|
||||||
|
case GL_UNSIGNED_INT_VEC2: numElements = count_ * 2; break;
|
||||||
|
case GL_UNSIGNED_INT_VEC3: numElements = count_ * 3; break;
|
||||||
|
case GL_UNSIGNED_INT_VEC4: numElements = count_ * 4; break;
|
||||||
|
case GL_BOOL: numElements = count_ * 1; break;
|
||||||
|
case GL_BOOL_VEC2: numElements = count_ * 2; break;
|
||||||
|
case GL_BOOL_VEC3: numElements = count_ * 3; break;
|
||||||
|
case GL_BOOL_VEC4: numElements = count_ * 4; break;
|
||||||
|
case GL_FLOAT_MAT2: numElements = count_ * 4; break; // 2x2
|
||||||
|
case GL_FLOAT_MAT3: numElements = count_ * 9; break; // 3x3
|
||||||
|
case GL_FLOAT_MAT4: numElements = count_ * 16; break; // 4x4
|
||||||
|
case GL_FLOAT_MAT2x3: numElements = count_ * 6; break; // 2x3
|
||||||
|
case GL_FLOAT_MAT2x4: numElements = count_ * 8; break; // 2x4
|
||||||
|
case GL_FLOAT_MAT3x2: numElements = count_ * 6; break; // 3x2
|
||||||
|
case GL_FLOAT_MAT3x4: numElements = count_ * 12; break; // 3x4
|
||||||
|
case GL_FLOAT_MAT4x2: numElements = count_ * 8; break; // 4x2
|
||||||
|
case GL_FLOAT_MAT4x3: numElements = count_ * 12; break; // 4x3
|
||||||
|
case GL_SAMPLER_1D:
|
||||||
|
case GL_SAMPLER_2D:
|
||||||
|
case GL_SAMPLER_3D:
|
||||||
|
case GL_SAMPLER_CUBE:
|
||||||
|
case GL_SAMPLER_1D_SHADOW:
|
||||||
|
case GL_SAMPLER_2D_SHADOW:
|
||||||
|
case GL_SAMPLER_CUBE_SHADOW:
|
||||||
|
case GL_SAMPLER_1D_ARRAY:
|
||||||
|
case GL_SAMPLER_2D_ARRAY:
|
||||||
|
case GL_SAMPLER_1D_ARRAY_SHADOW:
|
||||||
|
case GL_SAMPLER_2D_ARRAY_SHADOW:
|
||||||
|
case GL_SAMPLER_BUFFER:
|
||||||
|
case GL_SAMPLER_2D_MULTISAMPLE:
|
||||||
|
case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: numElements = count_ * 1; break;
|
||||||
|
default:
|
||||||
|
MG_Util::Debug::LogW("MG_State: Program: UniformValue::setData warning: unsupported type 0x%X for numElements", uniformType);
|
||||||
|
numElements = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (GLsizei i = 0; i < numElements; ++i) {
|
for (GLsizei i = 0; i < numElements; ++i) {
|
||||||
switch (uniformType) {
|
switch (uniformType) {
|
||||||
case GL_FLOAT:
|
case GL_FLOAT:
|
||||||
|
|||||||
@@ -27,16 +27,18 @@ struct UniformValue {
|
|||||||
std::vector<GLuint> uintData;
|
std::vector<GLuint> uintData;
|
||||||
std::vector<GLboolean> boolData;
|
std::vector<GLboolean> boolData;
|
||||||
GLsizei count;
|
GLsizei count;
|
||||||
|
GLsizei numElements;
|
||||||
|
|
||||||
UniformValue() : type(0), count(0) {}
|
UniformValue() : type(0), count(0) {}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void setData(GLenum uniformType, GLsizei numElements, const T* values);
|
void setData(GLenum uniformType, GLsizei count_, const T* values);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProgramObject {
|
struct ProgramObject {
|
||||||
std::vector<GLuint> attachedShaders;
|
std::vector<GLuint> attachedShaders;
|
||||||
UncertainBool linked;
|
UncertainBool linked;
|
||||||
|
bool dirty;
|
||||||
GLint linkStatus;
|
GLint linkStatus;
|
||||||
std::string infoLog;
|
std::string infoLog;
|
||||||
std::unordered_map<std::string, GLint> attribBindings;
|
std::unordered_map<std::string, GLint> attribBindings;
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ GLenum ProgramState::DeleteShader(GLuint shader) {
|
|||||||
MG_Util::Debug::LogD("MG_State: Program: DeleteShader info: shader %u marked for deferred deletion (in use)", shader);
|
MG_Util::Debug::LogD("MG_State: Program: DeleteShader info: shader %u marked for deferred deletion (in use)", shader);
|
||||||
} else {
|
} else {
|
||||||
shaders_.erase(shader);
|
shaders_.erase(shader);
|
||||||
freeShaderIds_.insert(shader);
|
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
|
||||||
|
//freeShaderIds_.insert(shader);
|
||||||
MG_Util::Debug::LogD("MG_State: Program: DeleteShader success: shader %u deleted immediately", shader);
|
MG_Util::Debug::LogD("MG_State: Program: DeleteShader success: shader %u deleted immediately", shader);
|
||||||
}
|
}
|
||||||
return GL_NO_ERROR;
|
return GL_NO_ERROR;
|
||||||
|
|||||||
@@ -610,7 +610,7 @@ GLenum TextureState::Delete(GLuint texture) {
|
|||||||
if (it != this->textures.end()) {
|
if (it != this->textures.end()) {
|
||||||
InvalidateTextureInAllUnits_(texture);
|
InvalidateTextureInAllUnits_(texture);
|
||||||
this->textures.erase(it);
|
this->textures.erase(it);
|
||||||
freeID_.emplace_back(texture);
|
//freeID_.emplace_back(texture);
|
||||||
MG_Util::Debug::LogD("MG_State: Texture: Delete succeeded for texture=%u", texture);
|
MG_Util::Debug::LogD("MG_State: Texture: Delete succeeded for texture=%u", texture);
|
||||||
} else {
|
} else {
|
||||||
MG_Util::Debug::LogW("MG_State: Texture: Delete texture %u not found", texture);
|
MG_Util::Debug::LogW("MG_State: Texture: Delete texture %u not found", texture);
|
||||||
@@ -632,7 +632,8 @@ GLenum TextureState::DeleteN(GLsizei n, const GLuint* textures) {
|
|||||||
if (it != this->textures.end()) {
|
if (it != this->textures.end()) {
|
||||||
InvalidateTextureInAllUnits_(id);
|
InvalidateTextureInAllUnits_(id);
|
||||||
this->textures.erase(it);
|
this->textures.erase(it);
|
||||||
freeID_.emplace_back(id);
|
// TODO: Prevent the object that uses a freeId from conflicting with legacy object in the backend.
|
||||||
|
//freeID_.emplace_back(id);
|
||||||
MG_Util::Debug::LogD("MG_State: Texture: DeleteN deleted texture=%u", id);
|
MG_Util::Debug::LogD("MG_State: Texture: DeleteN deleted texture=%u", id);
|
||||||
} else {
|
} else {
|
||||||
MG_Util::Debug::LogW("MG_State: Texture: DeleteN texture %u not found", id);
|
MG_Util::Debug::LogW("MG_State: Texture: DeleteN texture %u not found", id);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace MG_Util::Program {
|
|||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "[";
|
ss << "[";
|
||||||
|
|
||||||
const size_t elemCount = std::min<size_t>(value.count, 16); // 限制最大显示元素
|
const size_t elemCount = std::min<size_t>(value.count, 16);
|
||||||
|
|
||||||
switch(value.type) {
|
switch(value.type) {
|
||||||
case GL_FLOAT:
|
case GL_FLOAT:
|
||||||
|
|||||||
@@ -395,8 +395,6 @@ namespace MG_Util::Program {
|
|||||||
prog.uniformLocations[name] = final_location;
|
prog.uniformLocations[name] = final_location;
|
||||||
UniformValue uniformValue;
|
UniformValue uniformValue;
|
||||||
uniformValue.type = gl_type;
|
uniformValue.type = gl_type;
|
||||||
uniformValue.count = spvc_type_get_array_dimension(type, 0) > 0 ?
|
|
||||||
spvc_type_get_array_dimension(type, 0) : 1;
|
|
||||||
prog.uniformValues[name] = uniformValue;
|
prog.uniformValues[name] = uniformValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user