OpenGL: JSON format support

This commit is contained in:
李通洲
2023-09-07 09:28:04 +08:00
parent cdaf5e9281
commit 34902db21c
2 changed files with 30 additions and 1 deletions
+29 -1
View File
@@ -44,7 +44,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
void ffInitOpenGLOptions(FFOpenGLOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, ffGenerateOpenGLJson);
ffOptionInitModuleArg(&options->moduleArgs);
#if defined(__linux__) || defined(__FreeBSD__)
@@ -115,3 +115,31 @@ void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module)
ffPrintError(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateOpenGLJson(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFOpenGLResult result;
ffStrbufInit(&result.version);
ffStrbufInit(&result.renderer);
ffStrbufInit(&result.vendor);
ffStrbufInit(&result.slv);
const char* error = ffDetectOpenGL(options, &result);
if(error != NULL)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
}
else
{
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
yyjson_mut_obj_add_strbuf(doc, obj, "renderer", &result.renderer);
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &result.vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "slv", &result.slv);
}
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.renderer);
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.slv);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitOpenGLOptions(FFOpenGLOptions* options);
bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, const char* value);
void ffDestroyOpenGLOptions(FFOpenGLOptions* options);
void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module);
void ffGenerateOpenGLJson(FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);