Skip to content

Commit 1f7053c

Browse files
committed
[Feat] (MG_State/Program): GetProgramInfoLog, GetShaderInfoLog
1 parent 323df93 commit 1f7053c

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ namespace MobileGL {
5656
return programObject;
5757
}
5858

59+
void CopyStr(GLsizei bufSize, GLsizei *length, GLchar *dst, const char* src, GLsizei srcLength) {
60+
auto sz = std::min(bufSize - 1, srcLength);
61+
if (length)
62+
*length = sz;
63+
memcpy(dst, src, sz);
64+
dst[sz] = '\0';
65+
}
66+
5967
void AttachShader_State(GLuint program, GLuint shader) {
6068
auto programObject = TryToGetProgramObject(program);
6169
if (!programObject)
@@ -168,15 +176,25 @@ namespace MobileGL {
168176
}
169177

170178
void GetProgramInfoLog_State(GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
171-
THROW_UNIMPL_EXCEPTION;
179+
auto programObject = TryToGetProgramObject(program);
180+
if (!programObject)
181+
return;
182+
183+
const auto& log = programObject->GetInfoLog();
184+
CopyStr(bufSize, length, infoLog, log.c_str(), log.length());
172185
}
173186

174187
void GetShaderiv_State(GLuint shader, GLenum pname, GLint* params) {
175188
THROW_UNIMPL_EXCEPTION;
176189
}
177190

178191
void GetShaderInfoLog_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
179-
THROW_UNIMPL_EXCEPTION;
192+
auto shaderObject = TryToGetShaderObject(shader);
193+
if (!shaderObject)
194+
return;
195+
196+
const auto& log = shaderObject->GetInfoLog();
197+
CopyStr(bufSize, length, infoLog, log.c_str(), log.length());
180198
}
181199

182200
void GetShaderSource_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* source) {
@@ -192,13 +210,11 @@ namespace MobileGL {
192210
return;
193211

194212
auto& src = shaderObject->GetShaderSource();
195-
auto sz = std::min(bufSize - 1, (GLsizei)src.length());
196-
if (length)
197-
*length = sz;
198-
memcpy(source, src.c_str(), sz);
199-
source[sz] = '\0';
213+
CopyStr(bufSize, length, source, src.c_str(), src.length());
200214
}
201215

216+
217+
202218
GLint GetUniformLocation_State(GLuint program, const GLchar* name) {
203219
THROW_UNIMPL_EXCEPTION;
204220
}

MobileGL/MG_State/GLState/ProgramState/ProgramObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace MobileGL {
1414
void Link();
1515
void MarkAsDeleted();
1616
Vector<SharedPtr<ShaderObject>>& GetAttachedShaders();
17+
const String& GetInfoLog() const { return m_infoLog; }
1718
private:
1819
const Uint m_id = 0;
1920
Vector<SharedPtr<ShaderObject>> m_shaders;

MobileGL/MG_State/GLState/ProgramState/ShaderObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
namespace MobileGL {
55
namespace MG_State {
66
namespace GLState {
7-
void ShaderObject::SetShaderSource(const std::string& source) {
7+
void ShaderObject::SetShaderSource(const String& source) {
88
m_source = source;
99
}
1010

11-
void ShaderObject::SetShaderSource(std::string &&source) {
11+
void ShaderObject::SetShaderSource(String &&source) {
1212
m_source = Move(source);
1313
}
1414

MobileGL/MG_State/GLState/ProgramState/ShaderObject.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,22 @@ namespace MobileGL {
5757
class ShaderObject {
5858
public:
5959
ShaderObject(const ShaderStage stage, const Uint id) : m_stage(stage), m_id(id) {}
60-
void SetShaderSource(const std::string& source);
61-
void SetShaderSource(std::string&& source);
60+
void SetShaderSource(const String& source);
61+
void SetShaderSource(String&& source);
6262
void Compile();
6363
void MarkAsDeleted();
6464

6565
Uint GetId() const { return m_id; }
6666
ShaderStage GetShaderStage() const { return m_stage; }
67-
const std::string& GetShaderSource() const { return m_source; }
67+
const String& GetShaderSource() const { return m_source; }
6868
SharedPtr<glslang::TShader> GetCompiledShader() const { return m_shader; }
69+
const String& GetInfoLog() const { return m_infoLog; }
6970
private:
7071
const Uint m_id = 0;
7172
const ShaderStage m_stage;
72-
std::string m_source;
73+
String m_source;
7374
SharedPtr<glslang::TShader> m_shader;
74-
std::string m_infoLog;
75+
String m_infoLog;
7576

7677
Bool m_deleteStatus = false;
7778
Bool m_compileStatus = false;

0 commit comments

Comments
 (0)