Use custom callbacks if they are available in 'i->callbacks'
This commit is contained in:
parent
1397890e8e
commit
84d11c472a
@ -80,25 +80,6 @@ typedef struct glslang_program_s {
|
|||||||
(CallbackIncluder::callbacks::free_include_result)
|
(CallbackIncluder::callbacks::free_include_result)
|
||||||
*/
|
*/
|
||||||
class CallbackIncluder : public glslang::TShader::Includer {
|
class CallbackIncluder : public glslang::TShader::Includer {
|
||||||
public:
|
|
||||||
/* Wrapper of IncludeResult which stores a glsl_include_result object internally */
|
|
||||||
class CallbackIncludeResult : public glslang::TShader::Includer::IncludeResult {
|
|
||||||
public:
|
|
||||||
CallbackIncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength,
|
|
||||||
void* userData, glsl_include_result_t* includeResult)
|
|
||||||
: glslang::TShader::Includer::IncludeResult(headerName, headerData, headerLength, userData),
|
|
||||||
includeResult(includeResult)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~CallbackIncludeResult() {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CallbackIncluder;
|
|
||||||
|
|
||||||
glsl_include_result_t* includeResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CallbackIncluder(glsl_include_callbacks_t _callbacks, void* _context) : callbacks(_callbacks), context(_context) {}
|
CallbackIncluder(glsl_include_callbacks_t _callbacks, void* _context) : callbacks(_callbacks), context(_context) {}
|
||||||
|
|
||||||
@ -110,9 +91,7 @@ public:
|
|||||||
if (this->callbacks.include_system) {
|
if (this->callbacks.include_system) {
|
||||||
glsl_include_result_t* result =
|
glsl_include_result_t* result =
|
||||||
this->callbacks.include_system(this->context, headerName, includerName, inclusionDepth);
|
this->callbacks.include_system(this->context, headerName, includerName, inclusionDepth);
|
||||||
|
return makeIncludeResult(result);
|
||||||
return new CallbackIncludeResult(std::string(headerName), result->header_data, result->header_length,
|
|
||||||
nullptr, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return glslang::TShader::Includer::includeSystem(headerName, includerName, inclusionDepth);
|
return glslang::TShader::Includer::includeSystem(headerName, includerName, inclusionDepth);
|
||||||
@ -124,9 +103,7 @@ public:
|
|||||||
if (this->callbacks.include_local) {
|
if (this->callbacks.include_local) {
|
||||||
glsl_include_result_t* result =
|
glsl_include_result_t* result =
|
||||||
this->callbacks.include_local(this->context, headerName, includerName, inclusionDepth);
|
this->callbacks.include_local(this->context, headerName, includerName, inclusionDepth);
|
||||||
|
return makeIncludeResult(result);
|
||||||
return new CallbackIncludeResult(std::string(headerName), result->header_data, result->header_length,
|
|
||||||
nullptr, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return glslang::TShader::Includer::includeLocal(headerName, includerName, inclusionDepth);
|
return glslang::TShader::Includer::includeLocal(headerName, includerName, inclusionDepth);
|
||||||
@ -139,22 +116,25 @@ public:
|
|||||||
if (result == nullptr)
|
if (result == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this->callbacks.free_include_result && (result->userData == nullptr)) {
|
if (this->callbacks.free_include_result) {
|
||||||
CallbackIncludeResult* innerResult = static_cast<CallbackIncludeResult*>(result);
|
this->callbacks.free_include_result(this->context, static_cast<glsl_include_result_t*>(result->userData));
|
||||||
/* use internal free() function */
|
|
||||||
this->callbacks.free_include_result(this->context, innerResult->includeResult);
|
|
||||||
/* ignore internal fields of TShader::Includer::IncludeResult */
|
|
||||||
delete result;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] static_cast<char*>(result->userData);
|
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CallbackIncluder() {}
|
CallbackIncluder() {}
|
||||||
|
|
||||||
|
IncludeResult* makeIncludeResult(glsl_include_result_t* result) {
|
||||||
|
if (!result) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new glslang::TShader::Includer::IncludeResult(
|
||||||
|
std::string(result->header_name), result->header_data, result->header_length, result);
|
||||||
|
}
|
||||||
|
|
||||||
/* C callback pointers */
|
/* C callback pointers */
|
||||||
glsl_include_callbacks_t callbacks;
|
glsl_include_callbacks_t callbacks;
|
||||||
/* User-defined context */
|
/* User-defined context */
|
||||||
@ -394,8 +374,11 @@ GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t
|
|||||||
|
|
||||||
GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input)
|
GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input)
|
||||||
{
|
{
|
||||||
DirStackFileIncluder Includer;
|
DirStackFileIncluder dirStackFileIncluder;
|
||||||
/* TODO: use custom callbacks if they are available in 'i->callbacks' */
|
CallbackIncluder callbackIncluder(input->callbacks, input->callbacks_ctx);
|
||||||
|
glslang::TShader::Includer& Includer = (input->callbacks.include_local||input->callbacks.include_system)
|
||||||
|
? static_cast<glslang::TShader::Includer&>(callbackIncluder)
|
||||||
|
: static_cast<glslang::TShader::Includer&>(dirStackFileIncluder);
|
||||||
return shader->shader->preprocess(
|
return shader->shader->preprocess(
|
||||||
reinterpret_cast<const TBuiltInResource*>(input->resource),
|
reinterpret_cast<const TBuiltInResource*>(input->resource),
|
||||||
input->default_version,
|
input->default_version,
|
||||||
|
|||||||
@ -168,23 +168,6 @@ typedef struct glslang_resource_s {
|
|||||||
glslang_limits_t limits;
|
glslang_limits_t limits;
|
||||||
} glslang_resource_t;
|
} glslang_resource_t;
|
||||||
|
|
||||||
typedef struct glslang_input_s {
|
|
||||||
glslang_source_t language;
|
|
||||||
glslang_stage_t stage;
|
|
||||||
glslang_client_t client;
|
|
||||||
glslang_target_client_version_t client_version;
|
|
||||||
glslang_target_language_t target_language;
|
|
||||||
glslang_target_language_version_t target_language_version;
|
|
||||||
/** Shader source code */
|
|
||||||
const char* code;
|
|
||||||
int default_version;
|
|
||||||
glslang_profile_t default_profile;
|
|
||||||
int force_default_version_and_profile;
|
|
||||||
int forward_compatible;
|
|
||||||
glslang_messages_t messages;
|
|
||||||
const glslang_resource_t* resource;
|
|
||||||
} glslang_input_t;
|
|
||||||
|
|
||||||
/* Inclusion result structure allocated by C include_local/include_system callbacks */
|
/* Inclusion result structure allocated by C include_local/include_system callbacks */
|
||||||
typedef struct glsl_include_result_s {
|
typedef struct glsl_include_result_s {
|
||||||
/* Header file name or NULL if inclusion failed */
|
/* Header file name or NULL if inclusion failed */
|
||||||
@ -214,6 +197,25 @@ typedef struct glsl_include_callbacks_s {
|
|||||||
glsl_free_include_result_func free_include_result;
|
glsl_free_include_result_func free_include_result;
|
||||||
} glsl_include_callbacks_t;
|
} glsl_include_callbacks_t;
|
||||||
|
|
||||||
|
typedef struct glslang_input_s {
|
||||||
|
glslang_source_t language;
|
||||||
|
glslang_stage_t stage;
|
||||||
|
glslang_client_t client;
|
||||||
|
glslang_target_client_version_t client_version;
|
||||||
|
glslang_target_language_t target_language;
|
||||||
|
glslang_target_language_version_t target_language_version;
|
||||||
|
/** Shader source code */
|
||||||
|
const char* code;
|
||||||
|
int default_version;
|
||||||
|
glslang_profile_t default_profile;
|
||||||
|
int force_default_version_and_profile;
|
||||||
|
int forward_compatible;
|
||||||
|
glslang_messages_t messages;
|
||||||
|
const glslang_resource_t* resource;
|
||||||
|
glsl_include_callbacks_t callbacks;
|
||||||
|
void* callbacks_ctx;
|
||||||
|
} glslang_input_t;
|
||||||
|
|
||||||
/* SpvOptions counterpart */
|
/* SpvOptions counterpart */
|
||||||
typedef struct glslang_spv_options_s {
|
typedef struct glslang_spv_options_s {
|
||||||
bool generate_debug_info;
|
bool generate_debug_info;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user