mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Misc] (All): Run format_code.sh
This commit is contained in:
@@ -10,7 +10,8 @@ namespace MobileGL {
|
||||
"<unknown renderer of MobileGL>", // Renderer Name
|
||||
"<unknown backend>", // Backend Name
|
||||
", <unknown>", // Extra vendor
|
||||
{ // OpenGL Info
|
||||
{
|
||||
// OpenGL Info
|
||||
{3, 3, 0}, // Target OpenGL Version
|
||||
{4, 6, 0}, // Target Shading Language Version
|
||||
{}, // OpenGL Extensions
|
||||
@@ -30,7 +31,8 @@ namespace MobileGL {
|
||||
"MobileGlued-vk", // Renderer Name
|
||||
"Diligent Engine (Vulkan)", // Backend Name
|
||||
Nullopt, // Extra vendor
|
||||
{ // OpenGL Info
|
||||
{
|
||||
// OpenGL Info
|
||||
{3, 3, 0}, // Target OpenGL Version
|
||||
{4, 6, 0}, // Target Shading Language Version
|
||||
{V_OpenGL30, V_OpenGL31, V_OpenGL32, // OpenGL Extensions
|
||||
@@ -44,7 +46,8 @@ namespace MobileGL {
|
||||
"MobileGlued-mtl", // Renderer Name
|
||||
"Diligent Engine (Metal)", // Backend Name
|
||||
Nullopt, // Extra vendor
|
||||
{ // OpenGL Info
|
||||
{
|
||||
// OpenGL Info
|
||||
{3, 3, 0}, // Target OpenGL Version
|
||||
{4, 6, 0}, // Target Shading Language Version
|
||||
{V_OpenGL30, V_OpenGL31, V_OpenGL32, // OpenGL Extensions
|
||||
|
||||
@@ -227,7 +227,6 @@ static void BM_CompileAndLink(benchmark::State& state) {
|
||||
DeleteShader(fs);
|
||||
}
|
||||
|
||||
|
||||
// Set the counter for Compiles/Second
|
||||
state.counters["VS_Compiles/Second"] = state.iterations();
|
||||
state.counters["FS_Compiles/Second"] = state.iterations();
|
||||
|
||||
@@ -10,20 +10,17 @@ static void Sanity_VectorResize(benchmark::State& state) {
|
||||
v[i] = i;
|
||||
}
|
||||
}
|
||||
state.SetBytesProcessed(int64_t(state.iterations()) *
|
||||
int64_t(state.range(0)));
|
||||
state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(state.range(0)));
|
||||
}
|
||||
BENCHMARK(Sanity_VectorResize)->Arg(2 << 5)->Arg(2 << 10)->Arg(2 << 20);
|
||||
|
||||
|
||||
static void Sanity_memcpy(benchmark::State& state) {
|
||||
char* src = new char[state.range(0)];
|
||||
char* dst = new char[state.range(0)];
|
||||
memset(src, 'x', state.range(0));
|
||||
for (auto _ : state)
|
||||
memcpy(dst, src, state.range(0));
|
||||
state.SetBytesProcessed(int64_t(state.iterations()) *
|
||||
int64_t(state.range(0)));
|
||||
state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(state.range(0)));
|
||||
delete[] src;
|
||||
delete[] dst;
|
||||
}
|
||||
|
||||
@@ -17,15 +17,13 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
static SharedPtr<MG_State::GLState::ShaderObject> TryToGetShaderObject(Uint shader) {
|
||||
if (!CheckShaderNameValidity(shader))
|
||||
return nullptr;
|
||||
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."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`shader` is not a shader object."));
|
||||
return nullptr;
|
||||
}
|
||||
return shaderObject;
|
||||
@@ -43,15 +41,13 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
static SharedPtr<MG_State::GLState::ProgramObject> TryToGetProgramObject(GLuint program) {
|
||||
if (!CheckProgramNameValidity(program))
|
||||
return nullptr;
|
||||
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."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`program` is not a program object."));
|
||||
return nullptr;
|
||||
}
|
||||
return programObject;
|
||||
@@ -59,8 +55,7 @@ namespace MobileGL {
|
||||
|
||||
void CopyStr(GLsizei bufSize, GLsizei* length, GLchar* dst, const char* src, GLsizei srcLength) {
|
||||
auto sz = std::min(bufSize - 1, srcLength);
|
||||
if (length)
|
||||
*length = sz;
|
||||
if (length) *length = sz;
|
||||
|
||||
if (bufSize == 0) return;
|
||||
|
||||
@@ -70,11 +65,9 @@ namespace MobileGL {
|
||||
|
||||
void AttachShader_State(GLuint program, GLuint shader) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
if (!programObject->AttachShader(shaderObject)) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
@@ -102,16 +95,14 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
|
||||
programObject->SetExplicitAttribLocation(index, name);
|
||||
}
|
||||
|
||||
void CompileShader_State(GLuint shader) {
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
shaderObject->Compile();
|
||||
}
|
||||
|
||||
@@ -120,43 +111,38 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
GLuint CreateShader_State(GLenum type) {
|
||||
auto shaderId = MG_State::pGLContext->CreateShader(MG_State::GLState::ConvertMGLShaderStageByGLShaderType(type));
|
||||
auto shaderId =
|
||||
MG_State::pGLContext->CreateShader(MG_State::GLState::ConvertMGLShaderStageByGLShaderType(type));
|
||||
if (shaderId == 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`shaderType` is not an accepted value."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`shaderType` is not an accepted value."));
|
||||
return 0;
|
||||
}
|
||||
return shaderId;
|
||||
}
|
||||
|
||||
void DeleteProgram_State(GLuint program) {
|
||||
if (!CheckProgramNameValidity(program))
|
||||
return;
|
||||
if (!CheckProgramNameValidity(program)) return;
|
||||
MG_State::pGLContext->MarkProgramForDeletion(program);
|
||||
}
|
||||
|
||||
void DeleteShader_State(GLuint shader) {
|
||||
if (!CheckProgramNameValidity(shader))
|
||||
return;
|
||||
if (!CheckProgramNameValidity(shader)) return;
|
||||
MG_State::pGLContext->MarkShaderForDeletion(shader);
|
||||
}
|
||||
|
||||
void DetachShader_State(GLuint program, GLuint shader) {
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
|
||||
auto count = programObject->DetachShader(shaderObject);
|
||||
if (count <= 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"Shader is not attached to program."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "Shader is not attached to program."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -166,23 +152,21 @@ namespace MobileGL {
|
||||
if (bufSize < 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`bufSize` is less than 0."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`bufSize` is less than 0."));
|
||||
return;
|
||||
}
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
auto attribCount = programObject->GetActiveAttributesCount();
|
||||
if (index >= attribCount) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
MakeShared<GenericErrorInfo>(
|
||||
"MG_Impl/GLImpl", __func__,
|
||||
"`index` is greater than or equal to the number of active attribute variables in `program`."));
|
||||
return;
|
||||
}
|
||||
if (type != nullptr)
|
||||
*type = programObject->GetAttribType(index);
|
||||
if (type != nullptr) *type = programObject->GetAttribType(index);
|
||||
if (bufSize == 0) return;
|
||||
auto& attribName = programObject->GetAttribName(index);
|
||||
CopyStr(bufSize, length, name, attribName.c_str(), attribName.length());
|
||||
@@ -193,24 +177,22 @@ namespace MobileGL {
|
||||
if (bufSize < 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`bufSize` is less than 0."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`bufSize` is less than 0."));
|
||||
return;
|
||||
}
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
auto uniformCount = programObject->GetUniformCount();
|
||||
if (index >= uniformCount) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
MakeShared<GenericErrorInfo>(
|
||||
"MG_Impl/GLImpl", __func__,
|
||||
"`index` is greater than or equal to the number of active uniform variables in `program`."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (type != nullptr)
|
||||
*type = programObject->GetUniformType(index);
|
||||
if (type != nullptr) *type = programObject->GetUniformType(index);
|
||||
if (bufSize == 0) return;
|
||||
auto& uniformName = programObject->GetUniformName(index);
|
||||
CopyStr(bufSize, length, name, uniformName.c_str(), uniformName.length());
|
||||
@@ -220,17 +202,14 @@ namespace MobileGL {
|
||||
if (maxCount < 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`maxCount` is less than 0."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`maxCount` is less than 0."));
|
||||
return;
|
||||
}
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
const auto& s = programObject->GetAttachedShaders();
|
||||
GLsizei c = std::min((GLsizei)s.size(), maxCount);
|
||||
if (count)
|
||||
*count = c;
|
||||
if (count) *count = c;
|
||||
for (GLsizei i = 0; i < c; ++i) {
|
||||
shaders[i] = s[i]->GetId();
|
||||
}
|
||||
@@ -238,19 +217,15 @@ namespace MobileGL {
|
||||
|
||||
GLint GetAttribLocation_State(GLuint program, const GLchar* name) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return -1;
|
||||
if (strncmp(name, "gl_", 3) == 0)
|
||||
return -1;
|
||||
if (!programObject->GetLinkStatus())
|
||||
return -1;
|
||||
if (!programObject) return -1;
|
||||
if (strncmp(name, "gl_", 3) == 0) return -1;
|
||||
if (!programObject->GetLinkStatus()) return -1;
|
||||
return programObject->GetAttributeLocation(name);
|
||||
}
|
||||
|
||||
void GetProgramiv_State(GLuint program, GLenum pname, GLint* params) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
|
||||
switch (pname) {
|
||||
case GL_DELETE_STATUS:
|
||||
@@ -306,16 +281,14 @@ namespace MobileGL {
|
||||
default:
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidEnum,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`pname` is not an accepted value."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`pname` is not an accepted value."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void GetProgramInfoLog_State(GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
|
||||
const auto& log = programObject->GetInfoLog();
|
||||
CopyStr(bufSize, length, infoLog, log.c_str(), log.length());
|
||||
@@ -323,8 +296,7 @@ namespace MobileGL {
|
||||
|
||||
void GetShaderiv_State(GLuint shader, GLenum pname, GLint* params) {
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
|
||||
switch (pname) {
|
||||
case GL_SHADER_TYPE:
|
||||
@@ -345,16 +317,14 @@ namespace MobileGL {
|
||||
default:
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidEnum,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`pname` is not an accepted value."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`pname` is not an accepted value."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void GetShaderInfoLog_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
|
||||
const auto& log = shaderObject->GetInfoLog();
|
||||
CopyStr(bufSize, length, infoLog, log.c_str(), log.length());
|
||||
@@ -364,13 +334,11 @@ namespace MobileGL {
|
||||
if (bufSize < 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`bufSize` is less than 0."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`bufSize` is less than 0."));
|
||||
}
|
||||
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
|
||||
auto& src = shaderObject->GetShaderSource();
|
||||
CopyStr(bufSize, length, source, src.c_str(), src.length());
|
||||
@@ -378,15 +346,13 @@ namespace MobileGL {
|
||||
|
||||
GLint GetUniformLocation_State(GLuint program, const GLchar* name) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return -1;
|
||||
if (!programObject) return -1;
|
||||
return programObject->GetUniformLocation(name);
|
||||
}
|
||||
|
||||
void GetUniform_State(GLuint program, GLint location, void* params) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
|
||||
if (!programObject->GetLinkStatus()) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
@@ -401,7 +367,8 @@ namespace MobileGL {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`location` does not correspond to a valid uniform variable location for the specified program object."));
|
||||
"`location` does not correspond to a valid uniform variable location "
|
||||
"for the specified program object."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -411,7 +378,8 @@ namespace MobileGL {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`location` does not correspond to a valid uniform variable location for the specified program object."));
|
||||
"`location` does not correspond to a valid uniform variable location "
|
||||
"for the specified program object."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -452,8 +420,7 @@ namespace MobileGL {
|
||||
|
||||
void LinkProgram_State(GLuint program) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
programObject->Link();
|
||||
}
|
||||
|
||||
@@ -461,19 +428,16 @@ namespace MobileGL {
|
||||
if (count < 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`count` is less than 0."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "`count` is less than 0."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
if (!shaderObject) return;
|
||||
|
||||
std::string src;
|
||||
for (GLsizei i = 0; i < count; i++) {
|
||||
src +=
|
||||
(length == nullptr || length[i] <= 0) ? string[i] : std::string(string[i], length[i]);
|
||||
src += (length == nullptr || length[i] <= 0) ? string[i] : std::string(string[i], length[i]);
|
||||
}
|
||||
shaderObject->SetShaderSource(Move(src));
|
||||
}
|
||||
@@ -485,8 +449,7 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
if (!programObject) return;
|
||||
MG_State::pGLContext->UseProgram(program);
|
||||
}
|
||||
|
||||
@@ -500,15 +463,13 @@ namespace MobileGL {
|
||||
|
||||
template <GLsizei VecCount, typename T>
|
||||
void Uniformv_State(GLint location, GLsizei count, T* value) {
|
||||
if (location == -1)
|
||||
return;
|
||||
if (location == -1) return;
|
||||
|
||||
auto programObject = MG_State::pGLContext->GetCurrentProgram();
|
||||
if (programObject == nullptr) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"There is no current program object."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "There is no current program object."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -516,7 +477,8 @@ namespace MobileGL {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
|
||||
"`location` is an invalid uniform location for the current program "
|
||||
"object and `location` is not equal to -1."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -628,15 +590,13 @@ namespace MobileGL {
|
||||
void UniformMatrix2fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
// For 2x2 matrices, we have 4 elements per matrix
|
||||
// If transpose is GL_TRUE, we need to transpose the matrix data
|
||||
if (location == -1)
|
||||
return;
|
||||
if (location == -1) return;
|
||||
|
||||
auto programObject = MG_State::pGLContext->GetCurrentProgram();
|
||||
if (programObject == nullptr) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"There is no current program object."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "There is no current program object."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -644,7 +604,8 @@ namespace MobileGL {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
|
||||
"`location` is an invalid uniform location for the current program "
|
||||
"object and `location` is not equal to -1."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -665,15 +626,13 @@ namespace MobileGL {
|
||||
void UniformMatrix3fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
// For 3x3 matrices, we have 9 elements per matrix
|
||||
// If transpose is GL_TRUE, we need to transpose the matrix data
|
||||
if (location == -1)
|
||||
return;
|
||||
if (location == -1) return;
|
||||
|
||||
auto programObject = MG_State::pGLContext->GetCurrentProgram();
|
||||
if (programObject == nullptr) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"There is no current program object."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "There is no current program object."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -681,7 +640,8 @@ namespace MobileGL {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
|
||||
"`location` is an invalid uniform location for the current program "
|
||||
"object and `location` is not equal to -1."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -702,15 +662,13 @@ namespace MobileGL {
|
||||
void UniformMatrix4fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
// For 4x4 matrices, we have 16 elements per matrix
|
||||
// If transpose is GL_TRUE, we need to transpose the matrix data
|
||||
if (location == -1)
|
||||
return;
|
||||
if (location == -1) return;
|
||||
|
||||
auto programObject = MG_State::pGLContext->GetCurrentProgram();
|
||||
if (programObject == nullptr) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"There is no current program object."));
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "There is no current program object."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -718,7 +676,8 @@ namespace MobileGL {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"`location` is an invalid uniform location for the current program object and `location` is not equal to -1."));
|
||||
"`location` is an invalid uniform location for the current program "
|
||||
"object and `location` is not equal to -1."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,4 @@ namespace MobileGL {
|
||||
StackUnderflow,
|
||||
StackOverflow
|
||||
};
|
||||
}
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -112,8 +112,7 @@ namespace MobileGL {
|
||||
assert(location < m_attribs.size());
|
||||
if (m_attribs[location] != name) {
|
||||
auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
|
||||
if (it == m_attribs.end())
|
||||
continue;
|
||||
if (it == m_attribs.end()) continue;
|
||||
std::swap(m_attribs[location], m_attribs[std::distance(m_attribs.begin(), it)]);
|
||||
std::swap(m_attribTypes[location], m_attribTypes[std::distance(m_attribs.begin(), it)]);
|
||||
}
|
||||
@@ -140,10 +139,7 @@ namespace MobileGL {
|
||||
auto shaderType = ConvertGLShaderTypeByMGLShaderStage(m_shaders[i]->GetShaderStage());
|
||||
shaderTypes[i] = shaderType;
|
||||
ShaderAttrib attrib{
|
||||
.shaderType = shaderType,
|
||||
.sourceStr = m_shaders[i]->GetShaderSource(),
|
||||
.flags = 0
|
||||
};
|
||||
.shaderType = shaderType, .sourceStr = m_shaders[i]->GetShaderSource(), .flags = 0};
|
||||
auto res = ShaderCompiler::CompileShader(attrib);
|
||||
assert(res);
|
||||
shaders[i] = res.value();
|
||||
@@ -187,8 +183,7 @@ namespace MobileGL {
|
||||
// assert(m_uniformSizesInBytes.size() == GetUniformCount());
|
||||
}
|
||||
|
||||
void ProgramObject::WaitUntilGenerationCompleted() {
|
||||
}
|
||||
void ProgramObject::WaitUntilGenerationCompleted() {}
|
||||
|
||||
void ProgramObject::SetExplicitAttribLocation(Uint index, const char* name) {
|
||||
m_explicitAttribLocations[name] = index;
|
||||
|
||||
@@ -27,20 +27,12 @@ namespace MobileGL {
|
||||
const auto it = m_uniformLocations.find(name);
|
||||
return (it == m_uniformLocations.end()) ? -1 : (Int)it->second;
|
||||
}
|
||||
GLenum GetUniformType(Uint index) const {
|
||||
return m_uniformTypes[index];
|
||||
}
|
||||
GLenum GetUniformType(Uint index) const { return m_uniformTypes[index]; }
|
||||
|
||||
Bool IsUniformOpaqueAtLocation(Uint location) const {
|
||||
return m_uniformIsOpaqueType[location];
|
||||
}
|
||||
Bool IsUniformOpaqueAtLocation(Uint location) const { return m_uniformIsOpaqueType[location]; }
|
||||
|
||||
const String& GetUniformName(Uint index) const {
|
||||
return m_uniformNames[index];
|
||||
}
|
||||
Uint GetUniformOffset(Uint location) const {
|
||||
return m_uniformOffsets[location];
|
||||
}
|
||||
const String& GetUniformName(Uint index) const { return m_uniformNames[index]; }
|
||||
Uint GetUniformOffset(Uint location) const { return m_uniformOffsets[location]; }
|
||||
Uint GetUniformSizesInBytes(Uint location) const {
|
||||
return MG_Util::GetGLTypeSize(m_uniformTypes[location]);
|
||||
}
|
||||
@@ -49,15 +41,9 @@ namespace MobileGL {
|
||||
const auto it = std::find(m_attribs.begin(), m_attribs.end(), name);
|
||||
return (it == m_attribs.end()) ? -1 : std::distance(m_attribs.begin(), it);
|
||||
}
|
||||
GLenum GetAttribType(Uint index) const {
|
||||
return m_attribTypes[index];
|
||||
}
|
||||
const String& GetAttribName(Uint index) const {
|
||||
return m_attribs[index];
|
||||
}
|
||||
void* MapUBO() {
|
||||
return m_uboScratch.data();
|
||||
}
|
||||
GLenum GetAttribType(Uint index) const { return m_attribTypes[index]; }
|
||||
const String& GetAttribName(Uint index) const { return m_attribs[index]; }
|
||||
void* MapUBO() { return m_uboScratch.data(); }
|
||||
|
||||
Bool GetDeleteStatus() const { return m_deleteStatus; }
|
||||
Bool GetLinkStatus() const { return m_linkStatus; }
|
||||
@@ -67,6 +53,7 @@ namespace MobileGL {
|
||||
Int GetActiveUniformBlocksCount() const { return m_program->getNumUniformBlocks(); }
|
||||
Int GetActiveAttributesMaxLength() const { return m_attribInNameMaxLength; }
|
||||
Int GetActiveUniformBlocksMaxNameLength() const { return m_uniformBlockNameMaxLength; }
|
||||
|
||||
private:
|
||||
void DoReflection();
|
||||
void GenerateBinary();
|
||||
|
||||
@@ -8,8 +8,7 @@ namespace MobileGL {
|
||||
m_programIndexGenerator.Generate(1, &programId);
|
||||
EnsureIndexAvail(programId, m_programObjects);
|
||||
auto programObject = MakeShared<ProgramObject>(programId);
|
||||
if (programObject == nullptr)
|
||||
return 0;
|
||||
if (programObject == nullptr) return 0;
|
||||
m_programObjects[programId] = programObject;
|
||||
return programId;
|
||||
}
|
||||
@@ -34,8 +33,7 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void ProgramState::UseProgram(Uint program) {
|
||||
if (program == 0)
|
||||
m_currentProgram.reset();
|
||||
if (program == 0) m_currentProgram.reset();
|
||||
|
||||
if (!CheckIndexAvail(program, m_programObjects)) return;
|
||||
m_currentProgram = m_programObjects[program];
|
||||
@@ -46,8 +44,7 @@ namespace MobileGL {
|
||||
m_shaderIndexGenerator.Generate(1, &shaderId);
|
||||
EnsureIndexAvail(shaderId, m_shaderObjects);
|
||||
auto shaderObject = MakeShared<ShaderObject>(stage, shaderId);
|
||||
if (shaderObject == nullptr)
|
||||
return 0;
|
||||
if (shaderObject == nullptr) return 0;
|
||||
m_shaderObjects[shaderId] = shaderObject;
|
||||
return shaderId;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ namespace MobileGL {
|
||||
void MarkShaderObjectForDeletion(Uint shader);
|
||||
Bool ValidateShaderObject(Uint shader) const;
|
||||
|
||||
SharedPtr<ProgramObject> GetCurrentProgram() const {
|
||||
return m_currentProgram;
|
||||
}
|
||||
SharedPtr<ProgramObject> GetCurrentProgram() const { return m_currentProgram; }
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static Bool CheckIndexAvail(const SizeT idx, const Vector<T>& vec) {
|
||||
|
||||
@@ -24,11 +24,9 @@ namespace MobileGL {
|
||||
// Compile for OpenGL here, so that we can do validation and link
|
||||
// like a real OpenGL driver at linking stage
|
||||
// Will compile for other backends later.
|
||||
ShaderAttrib attrib{
|
||||
.shaderType = ConvertGLShaderTypeByMGLShaderStage(m_stage),
|
||||
ShaderAttrib attrib{.shaderType = ConvertGLShaderTypeByMGLShaderStage(m_stage),
|
||||
.sourceStr = m_source,
|
||||
.flags = ShaderCompileBits::CompileForOpenGL
|
||||
};
|
||||
.flags = ShaderCompileBits::CompileForOpenGL};
|
||||
|
||||
auto result = ShaderCompiler::CompileShader(attrib);
|
||||
if (result) {
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace MobileGL {
|
||||
const UnorderedMap<String, Uint>& GetUniformLocations() const { return m_uniforms; }
|
||||
Bool GetCompileStatus() const { return m_compileStatus; }
|
||||
Bool GetDeleteStatus() const { return m_deleteStatus; }
|
||||
|
||||
private:
|
||||
// bool DoReflection();
|
||||
const Uint m_id = 0;
|
||||
|
||||
@@ -132,14 +132,8 @@ TEST_F(BufferTest, AcquireMemoryRangeWithoutExplicit) {
|
||||
bufObj->UploadData(ptr, 0);
|
||||
bufObj->ClearDirty();
|
||||
|
||||
Range1D mapRange{
|
||||
.start = sizeof(Int),
|
||||
.end = sizeof(Int) * 4
|
||||
};
|
||||
Int* mappedPtr = static_cast<Int*>(bufObj->AcquireMemoryRange(
|
||||
mapRange,
|
||||
BufferMappingAccessBit::Write
|
||||
));
|
||||
Range1D mapRange{.start = sizeof(Int), .end = sizeof(Int) * 4};
|
||||
Int* mappedPtr = static_cast<Int*>(bufObj->AcquireMemoryRange(mapRange, BufferMappingAccessBit::Write));
|
||||
mappedPtr[0] = 200;
|
||||
mappedPtr[1] = 300;
|
||||
bufObj->ReleaseMemory();
|
||||
@@ -167,14 +161,9 @@ TEST_F(BufferTest, AcquireMemoryRangeWithExplicit) {
|
||||
|
||||
bufObj->ClearDirty();
|
||||
|
||||
Range1D mapRange{
|
||||
.start = sizeof(Int),
|
||||
.end = sizeof(Int) * 4
|
||||
};
|
||||
Int* mappedPtr = static_cast<Int*>(bufObj->AcquireMemoryRange(
|
||||
mapRange,
|
||||
BufferMappingAccessBit::Write | BufferMappingAccessBit::FlushExplicit
|
||||
));
|
||||
Range1D mapRange{.start = sizeof(Int), .end = sizeof(Int) * 4};
|
||||
Int* mappedPtr = static_cast<Int*>(
|
||||
bufObj->AcquireMemoryRange(mapRange, BufferMappingAccessBit::Write | BufferMappingAccessBit::FlushExplicit));
|
||||
|
||||
mappedPtr[0] = 200;
|
||||
mappedPtr[1] = 300;
|
||||
@@ -228,16 +217,9 @@ TEST_F(BufferTest, CopyBufferSubData) {
|
||||
srcObj->ClearDirty();
|
||||
dstObj->ClearDirty();
|
||||
|
||||
dstObj->CopyDataFrom(srcObj,
|
||||
2 * sizeof(Int),
|
||||
5 * sizeof(Int),
|
||||
4 * sizeof(Int));
|
||||
dstObj->CopyDataFrom(srcObj, 2 * sizeof(Int), 5 * sizeof(Int), 4 * sizeof(Int));
|
||||
|
||||
Vector<Int> expected{
|
||||
0, 0, 0, 0, 0,
|
||||
3, 4, 5, 6,
|
||||
0, 0, 0, 0, 0, 0
|
||||
};
|
||||
Vector<Int> expected{0, 0, 0, 0, 0, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
Vector<Int> actual(15);
|
||||
void* p = dstObj->AcquireMemory(false, true, false);
|
||||
@@ -294,10 +276,7 @@ TEST_F(BufferTest, PartialUpdate) {
|
||||
bufObj->ClearDirty();
|
||||
|
||||
Vector<Int> update{999, 888};
|
||||
bufObj->UploadSubData(
|
||||
{ (void*)(update.data()), (SizeT)(update.size() * sizeof(Int)) },
|
||||
sizeof(Int)
|
||||
);
|
||||
bufObj->UploadSubData({(void*)(update.data()), (SizeT)(update.size() * sizeof(Int))}, sizeof(Int));
|
||||
|
||||
Vector<Int> expected{100, 999, 888, 400, 500};
|
||||
Vector<Int> actual(5);
|
||||
@@ -326,9 +305,7 @@ using namespace MobileGL::MG_Impl::GLImpl;
|
||||
|
||||
class GeneralBufferTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
}
|
||||
void SetUp() override { MG_State::pGLContext = new MG_State::GLState::GLContext(); }
|
||||
|
||||
GLuint CreateBoundBuffer(GLenum target, GLsizeiptr size, GLenum usage) {
|
||||
GLuint buffer;
|
||||
@@ -414,16 +391,14 @@ TEST_F(GeneralBufferTest, General_BufferMapping) {
|
||||
strcpy((char*)fullMap, " Full mapping test");
|
||||
EXPECT_TRUE(UnmapBuffer(GL_ARRAY_BUFFER));
|
||||
|
||||
void* partialMap = MapBufferRange(GL_ARRAY_BUFFER, 0, 30,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
void* partialMap = MapBufferRange(GL_ARRAY_BUFFER, 0, 30, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
ASSERT_NE(partialMap, nullptr);
|
||||
strcpy((char*)partialMap, "Partial (not valid value)");
|
||||
|
||||
FlushMappedBufferRange(GL_ARRAY_BUFFER, 0, 7);
|
||||
EXPECT_TRUE(UnmapBuffer(GL_ARRAY_BUFFER));
|
||||
|
||||
partialMap = MapBufferRange(GL_ARRAY_BUFFER, 20, 40,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
partialMap = MapBufferRange(GL_ARRAY_BUFFER, 20, 40, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
ASSERT_NE(partialMap, nullptr);
|
||||
strcpy((char*)partialMap, ": modified data (not valid value)");
|
||||
|
||||
@@ -465,8 +440,7 @@ TEST_F(GeneralBufferTest, General_MapFlags) {
|
||||
|
||||
EXPECT_TRUE(UnmapBuffer(GL_ARRAY_BUFFER));
|
||||
|
||||
void* nosyncMap = MapBufferRange(GL_ARRAY_BUFFER, 0, 100,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
void* nosyncMap = MapBufferRange(GL_ARRAY_BUFFER, 0, 100, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
ASSERT_NE(nosyncMap, nullptr);
|
||||
memset(nosyncMap, 0xAA, 100);
|
||||
EXPECT_TRUE(UnmapBuffer(GL_ARRAY_BUFFER));
|
||||
@@ -492,15 +466,13 @@ TEST_F(GeneralBufferTest, General_GeneralTest_1) {
|
||||
BufferData(GL_UNIFORM_BUFFER, sizeof(indexData), indexData, GL_STATIC_DRAW);
|
||||
|
||||
const uint16_t newIndices[] = {4, 5};
|
||||
BufferSubData(GL_UNIFORM_BUFFER, 2 * sizeof(uint16_t),
|
||||
sizeof(newIndices), newIndices);
|
||||
BufferSubData(GL_UNIFORM_BUFFER, 2 * sizeof(uint16_t), sizeof(newIndices), newIndices);
|
||||
|
||||
BindBuffer(GL_COPY_READ_BUFFER, staging);
|
||||
const char stagingData[] = "StagingBufferData";
|
||||
BufferData(GL_COPY_READ_BUFFER, sizeof(stagingData), stagingData, GL_STREAM_COPY);
|
||||
|
||||
CopyBufferSubData(GL_COPY_READ_BUFFER, GL_ARRAY_BUFFER,
|
||||
0, 40, sizeof(stagingData));
|
||||
CopyBufferSubData(GL_COPY_READ_BUFFER, GL_ARRAY_BUFFER, 0, 40, sizeof(stagingData));
|
||||
|
||||
BindBuffer(GL_UNIFORM_BUFFER, ibo);
|
||||
void* fullMap = MapBuffer(GL_UNIFORM_BUFFER, GL_READ_WRITE);
|
||||
@@ -512,9 +484,7 @@ TEST_F(GeneralBufferTest, General_GeneralTest_1) {
|
||||
EXPECT_TRUE(UnmapBuffer(GL_UNIFORM_BUFFER));
|
||||
|
||||
BindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
void* partialMap = MapBufferRange(GL_ARRAY_BUFFER, 20, 8,
|
||||
GL_MAP_WRITE_BIT |
|
||||
GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
void* partialMap = MapBufferRange(GL_ARRAY_BUFFER, 20, 8, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
|
||||
ASSERT_NE(partialMap, nullptr);
|
||||
|
||||
const char partialWriteData[] = "PARTIAL"; // 7 chars + '\0' = 8 bytes
|
||||
|
||||
@@ -8,13 +8,9 @@ using namespace MobileGL::MG_Impl::GLImpl;
|
||||
|
||||
class ProgramTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
}
|
||||
void SetUp() override { MG_State::pGLContext = new MG_State::GLState::GLContext(); }
|
||||
|
||||
void TearDown() override {
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
void TearDown() override { delete MG_State::pGLContext; }
|
||||
};
|
||||
|
||||
TEST_F(ProgramTest, Sanity) {
|
||||
@@ -94,7 +90,6 @@ void main() {
|
||||
fragColor = vec4(OutColor, float(intVal));
|
||||
})";
|
||||
|
||||
|
||||
TEST_F(ProgramTest, CompileVertex) {
|
||||
GLuint vs = CreateShader(GL_VERTEX_SHADER);
|
||||
ShaderSource(vs, 1, &vsSrc, NULL);
|
||||
@@ -217,12 +212,8 @@ TEST_F(ProgramTest, UniformMatrixFunctions) {
|
||||
ASSERT_NE(locProjMat, -1);
|
||||
|
||||
// 4x4 matrix (16 elements) - identity matrix
|
||||
GLfloat matrix4x4[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
GLfloat matrix4x4[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
// Test UniformMatrix4fv with count = 1 and transpose = GL_FALSE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_FALSE, matrix4x4);
|
||||
@@ -231,12 +222,8 @@ TEST_F(ProgramTest, UniformMatrixFunctions) {
|
||||
UniformMatrix4fv(locProjMat, 1, GL_TRUE, matrix4x4);
|
||||
|
||||
// Test with a non-identity matrix
|
||||
GLfloat nonIdentityMatrix[16] = {
|
||||
1.0f, 2.0f, 3.0f, 4.0f,
|
||||
5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f,
|
||||
13.0f, 14.0f, 15.0f, 16.0f
|
||||
};
|
||||
GLfloat nonIdentityMatrix[16] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f};
|
||||
|
||||
// Test with transpose = GL_FALSE
|
||||
UniformMatrix4fv(locProjMat, 1, GL_FALSE, nonIdentityMatrix);
|
||||
@@ -461,11 +448,7 @@ TEST_F(ProgramTest, UniformLocationGaps) {
|
||||
ASSERT_EQ(GetUniformLocation(program, "NonExistentUniform"), -1);
|
||||
|
||||
// Test uniform operations on locations with gaps
|
||||
GLfloat matrix3[9] = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f
|
||||
};
|
||||
GLfloat matrix3[9] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
// Test setting and getting uniform at location 10 (TestMat3)
|
||||
UniformMatrix3fv(10, 1, GL_FALSE, matrix3);
|
||||
@@ -476,10 +459,7 @@ TEST_F(ProgramTest, UniformLocationGaps) {
|
||||
}
|
||||
|
||||
// Test setting and getting uniform at location 20 (TestMat2)
|
||||
GLfloat matrix2[4] = {
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f
|
||||
};
|
||||
GLfloat matrix2[4] = {1.0f, 0.0f, 0.0f, 1.0f};
|
||||
UniformMatrix2fv(20, 1, GL_FALSE, matrix2);
|
||||
GLfloat result2[4];
|
||||
GetUniformfv(program, 20, result2);
|
||||
|
||||
@@ -41,10 +41,7 @@ void main(){
|
||||
|
||||
TEST_F(ProgramUtilTest, CompileSimpleVertexShader) {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib attrib {
|
||||
.shaderType = GL_VERTEX_SHADER,
|
||||
.sourceStr = vs
|
||||
};
|
||||
ShaderAttrib attrib{.shaderType = GL_VERTEX_SHADER, .sourceStr = vs};
|
||||
auto res = ShaderCompiler::CompileShader(attrib);
|
||||
if (!res) {
|
||||
ASSERT_NE(res.error().errc, 0);
|
||||
@@ -93,10 +90,7 @@ void main() {
|
||||
|
||||
TEST_F(ProgramUtilTest, CompileSimpleFragmentShader) {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib attrib {
|
||||
.shaderType = GL_FRAGMENT_SHADER,
|
||||
.sourceStr = fs
|
||||
};
|
||||
ShaderAttrib attrib{.shaderType = GL_FRAGMENT_SHADER, .sourceStr = fs};
|
||||
auto res = ShaderCompiler::CompileShader(attrib);
|
||||
if (!res) {
|
||||
ASSERT_NE(res.error().errc, 0);
|
||||
@@ -122,20 +116,15 @@ void main() {
|
||||
|
||||
TEST_F(ProgramUtilTest, CompileFragmentShaderWithDiscard) {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib attrib {
|
||||
.shaderType = GL_FRAGMENT_SHADER,
|
||||
.sourceStr = position_color_fsh
|
||||
};
|
||||
ShaderAttrib attrib{.shaderType = GL_FRAGMENT_SHADER, .sourceStr = position_color_fsh};
|
||||
auto res = ShaderCompiler::CompileShader(attrib);
|
||||
if (!res) {
|
||||
ASSERT_NE(res.error().errc, 0);
|
||||
FAIL() << "errc: " << res.error().errc << "\nlog: " << res.error().log;
|
||||
}
|
||||
|
||||
ProgramAttrib programAttrib {
|
||||
// .shaderTypes = { GL_FRAGMENT_SHADER },
|
||||
.shaders = { res.value() }
|
||||
};
|
||||
ProgramAttrib programAttrib{// .shaderTypes = { GL_FRAGMENT_SHADER },
|
||||
.shaders = {res.value()}};
|
||||
|
||||
auto program_res = ShaderCompiler::LinkProgram(programAttrib);
|
||||
if (!program_res) {
|
||||
@@ -197,10 +186,7 @@ void main(){
|
||||
TEST_F(ProgramUtilTest, CompileVertexShaderWithLocation) {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib attrib{
|
||||
.shaderType = GL_VERTEX_SHADER,
|
||||
.sourceStr = vs_location,
|
||||
.flags = ShaderCompileBits::CompileForOpenGL
|
||||
};
|
||||
.shaderType = GL_VERTEX_SHADER, .sourceStr = vs_location, .flags = ShaderCompileBits::CompileForOpenGL};
|
||||
auto res = ShaderCompiler::CompileShader(attrib);
|
||||
if (!res) {
|
||||
ASSERT_NE(res.error().errc, 0);
|
||||
@@ -224,30 +210,22 @@ TEST_F(ProgramUtilTest, CompileVertexShaderWithLocation) {
|
||||
|
||||
TEST_F(ProgramUtilTest, CompileAndLinkProgram) {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib vs_attrib {
|
||||
.shaderType = GL_VERTEX_SHADER,
|
||||
.sourceStr = vs
|
||||
};
|
||||
ShaderAttrib vs_attrib{.shaderType = GL_VERTEX_SHADER, .sourceStr = vs};
|
||||
auto vs_res = ShaderCompiler::CompileShader(vs_attrib);
|
||||
if (!vs_res) {
|
||||
ASSERT_NE(vs_res.error().errc, 0);
|
||||
FAIL() << "errc: " << vs_res.error().errc << "\nlog: " << vs_res.error().log;
|
||||
}
|
||||
|
||||
ShaderAttrib fs_attrib {
|
||||
.shaderType = GL_FRAGMENT_SHADER,
|
||||
.sourceStr = fs
|
||||
};
|
||||
ShaderAttrib fs_attrib{.shaderType = GL_FRAGMENT_SHADER, .sourceStr = fs};
|
||||
auto fs_res = ShaderCompiler::CompileShader(fs_attrib);
|
||||
if (!fs_res) {
|
||||
ASSERT_NE(fs_res.error().errc, 0);
|
||||
FAIL() << "errc: " << fs_res.error().errc << "\nlog: " << fs_res.error().log;
|
||||
}
|
||||
|
||||
ProgramAttrib programAttrib {
|
||||
// .shaderTypes = { GL_VERTEX_SHADER, GL_FRAGMENT_SHADER },
|
||||
.shaders = { vs_res.value(), fs_res.value() }
|
||||
};
|
||||
ProgramAttrib programAttrib{// .shaderTypes = { GL_VERTEX_SHADER, GL_FRAGMENT_SHADER },
|
||||
.shaders = {vs_res.value(), fs_res.value()}};
|
||||
|
||||
auto program_res = ShaderCompiler::LinkProgram(programAttrib);
|
||||
if (!program_res) {
|
||||
@@ -258,30 +236,22 @@ TEST_F(ProgramUtilTest, CompileAndLinkProgram) {
|
||||
|
||||
TEST_F(ProgramUtilTest, DecompProgram) {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib vs_attrib {
|
||||
.shaderType = GL_VERTEX_SHADER,
|
||||
.sourceStr = vs
|
||||
};
|
||||
ShaderAttrib vs_attrib{.shaderType = GL_VERTEX_SHADER, .sourceStr = vs};
|
||||
auto vs_res = ShaderCompiler::CompileShader(vs_attrib);
|
||||
if (!vs_res) {
|
||||
ASSERT_NE(vs_res.error().errc, 0);
|
||||
FAIL() << "errc: " << vs_res.error().errc << "\nlog: " << vs_res.error().log;
|
||||
}
|
||||
|
||||
ShaderAttrib fs_attrib {
|
||||
.shaderType = GL_FRAGMENT_SHADER,
|
||||
.sourceStr = fs
|
||||
};
|
||||
ShaderAttrib fs_attrib{.shaderType = GL_FRAGMENT_SHADER, .sourceStr = fs};
|
||||
auto fs_res = ShaderCompiler::CompileShader(fs_attrib);
|
||||
if (!fs_res) {
|
||||
ASSERT_NE(fs_res.error().errc, 0);
|
||||
FAIL() << "errc: " << fs_res.error().errc << "\nlog: " << fs_res.error().log;
|
||||
}
|
||||
|
||||
ProgramAttrib programAttrib {
|
||||
// .shaderTypes = { GL_VERTEX_SHADER, GL_FRAGMENT_SHADER },
|
||||
.shaders = { vs_res.value(), fs_res.value() }
|
||||
};
|
||||
ProgramAttrib programAttrib{// .shaderTypes = { GL_VERTEX_SHADER, GL_FRAGMENT_SHADER },
|
||||
.shaders = {vs_res.value(), fs_res.value()}};
|
||||
|
||||
auto program_res = ShaderCompiler::LinkProgram(programAttrib);
|
||||
if (!program_res) {
|
||||
|
||||
@@ -50,17 +50,23 @@ namespace MobileGL {
|
||||
switch (baseType) {
|
||||
case GL_BOOL:
|
||||
switch (vecSize) {
|
||||
case 4: return GL_BOOL_VEC4;
|
||||
case 3: return GL_BOOL_VEC3;
|
||||
case 2: return GL_BOOL_VEC2;
|
||||
case 4:
|
||||
return GL_BOOL_VEC4;
|
||||
case 3:
|
||||
return GL_BOOL_VEC3;
|
||||
case 2:
|
||||
return GL_BOOL_VEC2;
|
||||
}
|
||||
case GL_FLOAT:
|
||||
return GL_FLOAT_VEC2 + (vecSize - 2); // GL_FLOAT_VEC* is contiguous
|
||||
case GL_DOUBLE:
|
||||
switch (vecSize) {
|
||||
case 4: return GL_DOUBLE_VEC4;
|
||||
case 3: return GL_DOUBLE_VEC3;
|
||||
case 2: return GL_DOUBLE_VEC2;
|
||||
case 4:
|
||||
return GL_DOUBLE_VEC4;
|
||||
case 3:
|
||||
return GL_DOUBLE_VEC3;
|
||||
case 2:
|
||||
return GL_DOUBLE_VEC2;
|
||||
}
|
||||
break;
|
||||
case GL_INT:
|
||||
@@ -73,7 +79,6 @@ namespace MobileGL {
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
GLenum ConvertSpvcTypeToGLEnum(const ShaderTranspiler::SpvcType& spvcType) {
|
||||
switch (spvcType.basetype) {
|
||||
case SPVC_BASETYPE_BOOLEAN:
|
||||
@@ -120,5 +125,5 @@ namespace MobileGL {
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace MG_Util
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -69,7 +69,8 @@ namespace MobileGL {
|
||||
void Log(const char* levelTag, android_LogPriority androidLogLevel, const char* fmt, ...) {
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
|
||||
std::string header = "[" + GetCurrentTime() + "] [" + GetOSName() + " " + GetThreadName() + "/" + levelTag + "]: ";
|
||||
std::string header =
|
||||
"[" + GetCurrentTime() + "] [" + GetOSName() + " " + GetThreadName() + "/" + levelTag + "]: ";
|
||||
|
||||
char buffer[1024];
|
||||
va_list args;
|
||||
@@ -98,5 +99,5 @@ namespace MobileGL {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace MG_Util::Debug
|
||||
} // namespace MobileGL
|
||||
@@ -763,4 +763,4 @@ namespace MobileGL {
|
||||
E_GL_NV_uniform_buffer_std430_layout,
|
||||
E_GL_MESA_texture_const_bandwidth
|
||||
};
|
||||
}
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -113,5 +113,5 @@ namespace MG_Util {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace MG_Util
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -11,6 +11,6 @@ namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
SizeT GetGLTypeSize(GLenum type);
|
||||
}
|
||||
}
|
||||
} // namespace MobileGL
|
||||
|
||||
#endif // BUFFERMETRICS_H
|
||||
|
||||
@@ -139,7 +139,9 @@ namespace MobileGL {
|
||||
tshader->setEnvInput(glslang::EShSourceGlsl, lang, glslang::EShClientVulkan, 450);
|
||||
tshader->setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_3);
|
||||
tshader->setEnvTarget(glslang::EShTargetSpv,
|
||||
((attrib.flags & ShaderCompileBits::EmitDiscardAsDemote) ? glslang::EShTargetSpv_1_6 : glslang::EShTargetSpv_1_5));
|
||||
((attrib.flags & ShaderCompileBits::EmitDiscardAsDemote)
|
||||
? glslang::EShTargetSpv_1_6
|
||||
: glslang::EShTargetSpv_1_5));
|
||||
}
|
||||
tshader->setAutoMapLocations(true);
|
||||
tshader->setAutoMapBindings(true);
|
||||
@@ -192,7 +194,8 @@ namespace MobileGL {
|
||||
return program;
|
||||
}
|
||||
|
||||
Result<Vector<Vector<unsigned>>> ShaderCompiler::GetSpirvBinaryFromProgram(const ProgramBinaryAttrib &attrib) {
|
||||
Result<Vector<Vector<unsigned>>> ShaderCompiler::GetSpirvBinaryFromProgram(
|
||||
const ProgramBinaryAttrib& attrib) {
|
||||
glslang::SpvOptions spvOptions;
|
||||
spvOptions.disableOptimizer = false;
|
||||
|
||||
|
||||
@@ -93,7 +93,8 @@ namespace MobileGL {
|
||||
SPVC_CHK_RESULT(spvc_compiler_type_struct_member_offset(compiler, type, j, &memberOffset);)
|
||||
metadata.plainUniformOffsetsInUBO[memberName] = memberOffset;
|
||||
SizeT memberSize = 0;
|
||||
SPVC_CHK_RESULT(spvc_compiler_get_declared_struct_member_size(compiler, type, j, &memberSize);)
|
||||
SPVC_CHK_RESULT(
|
||||
spvc_compiler_get_declared_struct_member_size(compiler, type, j, &memberSize);)
|
||||
metadata.plainUniformMemberSizesInBytes[memberName] = memberSize;
|
||||
|
||||
auto memberTypeId = spvc_type_get_member_type(type, j);
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace MobileGL {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct SpvcMetadata {
|
||||
|
||||
@@ -9,11 +9,9 @@ namespace MG_Util {
|
||||
namespace ShaderTranspiler {
|
||||
void UniformTraverser::visitSymbol(glslang::TIntermSymbol* symbol) {
|
||||
auto parent = getParentNode();
|
||||
if (!parent)
|
||||
return;
|
||||
if (!parent) return;
|
||||
auto parentAgg = parent->getAsAggregate();
|
||||
if (!parentAgg || parentAgg->getOp() != glslang::EOpLinkerObjects)
|
||||
return;
|
||||
if (!parentAgg || parentAgg->getOp() != glslang::EOpLinkerObjects) return;
|
||||
|
||||
const auto& type = symbol->getType();
|
||||
if (symbol->getQualifier().isUniform() && type.getBasicType() != glslang::EbtSampler) {
|
||||
@@ -35,6 +33,6 @@ namespace ShaderTranspiler {
|
||||
// uniform.sampler = type.getSampler();
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace ShaderTranspiler
|
||||
} // namespace MG_Util
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -14,11 +14,12 @@ namespace ShaderTranspiler {
|
||||
public:
|
||||
void visitSymbol(glslang::TIntermSymbol* symbol) override;
|
||||
Vector<glslang::TIntermSymbol*>& GetCollectedSymbols() { return m_collectedSymbols; }
|
||||
|
||||
private:
|
||||
Vector<glslang::TIntermSymbol*> m_collectedSymbols;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace ShaderTranspiler
|
||||
} // namespace MG_Util
|
||||
} // namespace MobileGL
|
||||
|
||||
#endif // MOBILEGL_UNIFORMTRAVERSER_H
|
||||
|
||||
Reference in New Issue
Block a user