mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Feat] (MG_State/Program): GetProgramInfoLog, GetShaderInfoLog
This commit is contained in:
@@ -56,6 +56,14 @@ namespace MobileGL {
|
||||
return programObject;
|
||||
}
|
||||
|
||||
void CopyStr(GLsizei bufSize, GLsizei *length, GLchar *dst, const char* src, GLsizei srcLength) {
|
||||
auto sz = std::min(bufSize - 1, srcLength);
|
||||
if (length)
|
||||
*length = sz;
|
||||
memcpy(dst, src, sz);
|
||||
dst[sz] = '\0';
|
||||
}
|
||||
|
||||
void AttachShader_State(GLuint program, GLuint shader) {
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
@@ -168,7 +176,12 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void GetProgramInfoLog_State(GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
|
||||
THROW_UNIMPL_EXCEPTION;
|
||||
auto programObject = TryToGetProgramObject(program);
|
||||
if (!programObject)
|
||||
return;
|
||||
|
||||
const auto& log = programObject->GetInfoLog();
|
||||
CopyStr(bufSize, length, infoLog, log.c_str(), log.length());
|
||||
}
|
||||
|
||||
void GetShaderiv_State(GLuint shader, GLenum pname, GLint* params) {
|
||||
@@ -176,7 +189,12 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void GetShaderInfoLog_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
|
||||
THROW_UNIMPL_EXCEPTION;
|
||||
auto shaderObject = TryToGetShaderObject(shader);
|
||||
if (!shaderObject)
|
||||
return;
|
||||
|
||||
const auto& log = shaderObject->GetInfoLog();
|
||||
CopyStr(bufSize, length, infoLog, log.c_str(), log.length());
|
||||
}
|
||||
|
||||
void GetShaderSource_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* source) {
|
||||
@@ -192,13 +210,11 @@ namespace MobileGL {
|
||||
return;
|
||||
|
||||
auto& src = shaderObject->GetShaderSource();
|
||||
auto sz = std::min(bufSize - 1, (GLsizei)src.length());
|
||||
if (length)
|
||||
*length = sz;
|
||||
memcpy(source, src.c_str(), sz);
|
||||
source[sz] = '\0';
|
||||
CopyStr(bufSize, length, source, src.c_str(), src.length());
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLint GetUniformLocation_State(GLuint program, const GLchar* name) {
|
||||
THROW_UNIMPL_EXCEPTION;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace MobileGL {
|
||||
void Link();
|
||||
void MarkAsDeleted();
|
||||
Vector<SharedPtr<ShaderObject>>& GetAttachedShaders();
|
||||
const String& GetInfoLog() const { return m_infoLog; }
|
||||
private:
|
||||
const Uint m_id = 0;
|
||||
Vector<SharedPtr<ShaderObject>> m_shaders;
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
void ShaderObject::SetShaderSource(const std::string& source) {
|
||||
void ShaderObject::SetShaderSource(const String& source) {
|
||||
m_source = source;
|
||||
}
|
||||
|
||||
void ShaderObject::SetShaderSource(std::string &&source) {
|
||||
void ShaderObject::SetShaderSource(String &&source) {
|
||||
m_source = Move(source);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,21 +57,22 @@ namespace MobileGL {
|
||||
class ShaderObject {
|
||||
public:
|
||||
ShaderObject(const ShaderStage stage, const Uint id) : m_stage(stage), m_id(id) {}
|
||||
void SetShaderSource(const std::string& source);
|
||||
void SetShaderSource(std::string&& source);
|
||||
void SetShaderSource(const String& source);
|
||||
void SetShaderSource(String&& source);
|
||||
void Compile();
|
||||
void MarkAsDeleted();
|
||||
|
||||
Uint GetId() const { return m_id; }
|
||||
ShaderStage GetShaderStage() const { return m_stage; }
|
||||
const std::string& GetShaderSource() const { return m_source; }
|
||||
const String& GetShaderSource() const { return m_source; }
|
||||
SharedPtr<glslang::TShader> GetCompiledShader() const { return m_shader; }
|
||||
const String& GetInfoLog() const { return m_infoLog; }
|
||||
private:
|
||||
const Uint m_id = 0;
|
||||
const ShaderStage m_stage;
|
||||
std::string m_source;
|
||||
String m_source;
|
||||
SharedPtr<glslang::TShader> m_shader;
|
||||
std::string m_infoLog;
|
||||
String m_infoLog;
|
||||
|
||||
Bool m_deleteStatus = false;
|
||||
Bool m_compileStatus = false;
|
||||
|
||||
Reference in New Issue
Block a user