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