CInterface: reformatted according to .clang-format rules
[platform/upstream/glslang.git] / glslang / Include / glslang_c_interface.h
1 /**
2 BSD 2-Clause License
3
4 Copyright (c) 2019, Viktor Latypov
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 1. Redistributions of source code must retain the above copyright notice, this
11    list of conditions and the following disclaimer.
12
13 2. Redistributions in binary form must reproduce the above copyright notice,
14    this list of conditions and the following disclaimer in the documentation
15    and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 **/
28
29 #ifndef GLSLANG_C_IFACE_H_INCLUDED
30 #define GLSLANG_C_IFACE_H_INCLUDED
31
32 #include <stdlib.h>
33
34 #include "c_shader_types.h"
35
36 typedef struct glslang_shader_s glslang_shader_t;
37 typedef struct glslang_program_s glslang_program_t;
38
39 typedef struct glslang_input_s {
40     glslang_source_t language;
41     glslang_stage_t stage;
42     glslang_client_t client;
43     glslang_target_client_version_t client_version;
44     glslang_target_language_t target_language;
45     glslang_target_language_version_t target_language_version;
46     /** Shader source code */
47     const char* code;
48     int default_version;
49     glslang_profile_t default_profile;
50     int force_default_version_and_profile;
51     int forward_compatible;
52     glslang_messages_t messages;
53 } glslang_input_t;
54
55 /* Inclusion result structure allocated by C include_local/include_system callbacks */
56 typedef struct glsl_include_result_s {
57     /* Header file name or NULL if inclusion failed */
58     const char* header_name;
59
60     /* Header contents or NULL */
61     const char* header_data;
62     size_t header_length;
63
64 } glsl_include_result_t;
65
66 /* Callback for local file inclusion */
67 typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
68                                                           size_t include_depth);
69
70 /* Callback for system file inclusion */
71 typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
72                                                            const char* includer_name, size_t include_depth);
73
74 /* Callback for include result destruction */
75 typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
76
77 /* Collection of callbacks for GLSL preprocessor */
78 typedef struct glsl_include_callbacks_s {
79     glsl_include_system_func include_system;
80     glsl_include_local_func include_local;
81     glsl_free_include_result_func free_include_result;
82 } glsl_include_callbacks_t;
83
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87
88 int glslang_initialize_process();
89 void glslang_finalize_process();
90
91 glslang_shader_t* glslang_shader_create(glslang_input_t* input);
92 void glslang_shader_delete(glslang_shader_t* shader);
93 int glslang_shader_preprocess(glslang_shader_t* shader, glslang_input_t* input);
94 int glslang_shader_parse(glslang_shader_t* shader, glslang_input_t* input);
95 const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
96 const char* glslang_shader_get_info_log(glslang_shader_t* shader);
97 const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
98
99 glslang_program_t* glslang_program_create();
100 void glslang_program_delete(glslang_program_t* program);
101 void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
102 int glslang_program_link(glslang_program_t* program, int messages);
103 void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
104 size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
105 void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
106 const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
107 const char* glslang_program_get_info_log(glslang_program_t* program);
108 const char* glslang_program_get_info_debug_log(glslang_program_t* program);
109
110 #ifdef __cplusplus
111 }
112 #endif
113
114 #endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */