mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 22:28:32 +09:00
[Feat] (MG_Impl/Program): use helper functions to simplify the code
This commit is contained in:
@@ -4,6 +4,58 @@
|
|||||||
|
|
||||||
namespace MobileGL {
|
namespace MobileGL {
|
||||||
namespace MG_Impl::GLImpl {
|
namespace MG_Impl::GLImpl {
|
||||||
|
static bool CheckShaderNameValidity(Uint shader) {
|
||||||
|
if (!MG_State::pGLContext->ValidateShaderName(shader)) {
|
||||||
|
MG_State::pGLContext->RecordError(
|
||||||
|
ErrorCode::InvalidValue,
|
||||||
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||||
|
"`shader` is not a value generated by OpenGL."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SharedPtr<MG_State::GLState::ShaderObject> TryToGetShaderObject(Uint shader) {
|
||||||
|
if (!CheckShaderNameValidity(shader))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto shaderObject = MG_State::pGLContext->GetShaderObject(shader);
|
||||||
|
if (!shaderObject) {
|
||||||
|
MG_State::pGLContext->RecordError(
|
||||||
|
ErrorCode::InvalidOperation,
|
||||||
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||||
|
"`shader` is not a shader object."));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return shaderObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool CheckProgramNameValidity(GLuint program) {
|
||||||
|
if (!MG_State::pGLContext->ValidateProgramName(program)) {
|
||||||
|
MG_State::pGLContext->RecordError(
|
||||||
|
ErrorCode::InvalidValue,
|
||||||
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||||
|
"`program` is not a value generated by OpenGL"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SharedPtr<MG_State::GLState::ProgramObject> TryToGetProgramObject(GLuint program) {
|
||||||
|
if (!CheckProgramNameValidity(program))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto programObject = MG_State::pGLContext->GetProgramObject(program);
|
||||||
|
if (!programObject) {
|
||||||
|
MG_State::pGLContext->RecordError(
|
||||||
|
ErrorCode::InvalidOperation,
|
||||||
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||||
|
"`program` is not a program object."));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return programObject;
|
||||||
|
}
|
||||||
|
|
||||||
void AttachShader_State(GLuint program, GLuint shader) {
|
void AttachShader_State(GLuint program, GLuint shader) {
|
||||||
THROW_UNIMPL_EXCEPTION;
|
THROW_UNIMPL_EXCEPTION;
|
||||||
}
|
}
|
||||||
@@ -13,22 +65,9 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CompileShader_State(GLuint shader) {
|
void CompileShader_State(GLuint shader) {
|
||||||
if (!MG_State::pGLContext->ValidateShaderName(shader)) {
|
auto shaderObject = TryToGetShaderObject(shader);
|
||||||
MG_State::pGLContext->RecordError(
|
if (!shaderObject)
|
||||||
ErrorCode::InvalidValue,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"`shader` is not a value generated by OpenGL."));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
auto shaderObject = MG_State::pGLContext->GetShaderObject(shader);
|
|
||||||
if (!shaderObject) {
|
|
||||||
MG_State::pGLContext->RecordError(
|
|
||||||
ErrorCode::InvalidOperation,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"`shader` is not a shader object."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
shaderObject->Compile();
|
shaderObject->Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,54 +88,24 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeleteProgram_State(GLuint program) {
|
void DeleteProgram_State(GLuint program) {
|
||||||
if (!MG_State::pGLContext->ValidateProgramName(program)) {
|
if (!CheckProgramNameValidity(program))
|
||||||
MG_State::pGLContext->RecordError(
|
|
||||||
ErrorCode::InvalidValue,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"`program` is not a value generated by OpenGL"));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
MG_State::pGLContext->MarkProgramForDeletion(program);
|
MG_State::pGLContext->MarkProgramForDeletion(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteShader_State(GLuint shader) {
|
void DeleteShader_State(GLuint shader) {
|
||||||
if (!MG_State::pGLContext->ValidateShaderName(shader)) {
|
if (!CheckProgramNameValidity(shader))
|
||||||
MG_State::pGLContext->RecordError(
|
|
||||||
ErrorCode::InvalidValue,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"`shader` is not a value generated by OpenGL"));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
MG_State::pGLContext->MarkShaderForDeletion(shader);
|
MG_State::pGLContext->MarkShaderForDeletion(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetachShader_State(GLuint program, GLuint shader) {
|
void DetachShader_State(GLuint program, GLuint shader) {
|
||||||
if (!MG_State::pGLContext->ValidateProgramName(program) ||
|
auto shaderObject = TryToGetShaderObject(shader);
|
||||||
!MG_State::pGLContext->ValidateShaderName(shader)) {
|
if (!shaderObject)
|
||||||
MG_State::pGLContext->RecordError(
|
|
||||||
ErrorCode::InvalidValue,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"Either `program` or `shader` is a value that was not generated by OpenGL"));
|
|
||||||
return;
|
return;
|
||||||
}
|
auto programObject = TryToGetProgramObject(program);
|
||||||
|
if (!programObject)
|
||||||
auto programObject = MG_State::pGLContext->GetProgramObject(program);
|
|
||||||
if (!programObject) {
|
|
||||||
MG_State::pGLContext->RecordError(
|
|
||||||
ErrorCode::InvalidOperation,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"`program` is not a program object."));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
auto shaderObject = MG_State::pGLContext->GetShaderObject(shader);
|
|
||||||
if (!shaderObject) {
|
|
||||||
MG_State::pGLContext->RecordError(
|
|
||||||
ErrorCode::InvalidOperation,
|
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
|
||||||
"`shader` is not a shader object."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto count = programObject->DetachShader(shaderObject);
|
auto count = programObject->DetachShader(shaderObject);
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
@@ -163,7 +172,7 @@ namespace MobileGL {
|
|||||||
* A program object marked for deletion with glDeleteProgram but still in use as part of current
|
* A program object marked for deletion with glDeleteProgram but still in use as part of current
|
||||||
* rendering state is still considered a program object and glIsProgram will return GL_TRUE.
|
* rendering state is still considered a program object and glIsProgram will return GL_TRUE.
|
||||||
*/
|
*/
|
||||||
return MG_State::pGLContext->ValidateProgramName(program);
|
return CheckProgramNameValidity(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLboolean IsShader_State(GLuint shader) {
|
GLboolean IsShader_State(GLuint shader) {
|
||||||
@@ -171,11 +180,14 @@ namespace MobileGL {
|
|||||||
* A shader object marked for deletion with glDeleteShader but still attached to a program object is still
|
* A shader object marked for deletion with glDeleteShader but still attached to a program object is still
|
||||||
* considered a shader object and glIsShader will return GL_TRUE.
|
* considered a shader object and glIsShader will return GL_TRUE.
|
||||||
*/
|
*/
|
||||||
return MG_State::pGLContext->ValidateShaderName(shader);
|
return CheckShaderNameValidity(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkProgram_State(GLuint program) {
|
void LinkProgram_State(GLuint program) {
|
||||||
THROW_UNIMPL_EXCEPTION;
|
auto programObject = TryToGetProgramObject(program);
|
||||||
|
if (!programObject)
|
||||||
|
return;
|
||||||
|
programObject->Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderSource_State(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length) {
|
void ShaderSource_State(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user