/usr/include/obs/graphics/shader-parser.h is in libobs-dev 21.0.2+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | /******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include "../util/cf-parser.h"
#include "graphics.h"
#ifdef __cplusplus
extern "C" {
#endif
EXPORT enum gs_shader_param_type get_shader_param_type(const char *type);
EXPORT enum gs_sample_filter get_sample_filter(const char *filter);
EXPORT enum gs_address_mode get_address_mode(const char *address_mode);
/*
* Shader Parser
*
* Parses a shader and extracts data such as shader constants, samplers,
* and vertex input information. Also allows the reformatting of shaders for
* different libraries. This is usually used only by graphics libraries,
*/
enum shader_var_type {
SHADER_VAR_NONE,
SHADER_VAR_UNIFORM,
SHADER_VAR_CONST
};
struct shader_var {
char *type;
char *name;
char *mapping;
enum shader_var_type var_type;
int array_count;
size_t gl_sampler_id; /* optional: used/parsed by GL */
DARRAY(uint8_t) default_val;
};
static inline void shader_var_init(struct shader_var *sv)
{
memset(sv, 0, sizeof(struct shader_var));
}
static inline void shader_var_init_param(struct shader_var *sv,
char *type, char *name, bool is_uniform,
bool is_const)
{
if (is_uniform)
sv->var_type = SHADER_VAR_UNIFORM;
else if (is_const)
sv->var_type = SHADER_VAR_CONST;
else
sv->var_type = SHADER_VAR_NONE;
sv->type = type;
sv->name = name;
sv->mapping = NULL;
sv->array_count = 0;
da_init(sv->default_val);
}
static inline void shader_var_free(struct shader_var *sv)
{
bfree(sv->type);
bfree(sv->name);
bfree(sv->mapping);
da_free(sv->default_val);
}
/* ------------------------------------------------------------------------- */
struct shader_sampler {
char *name;
DARRAY(char*) states;
DARRAY(char*) values;
};
static inline void shader_sampler_init(struct shader_sampler *ss)
{
memset(ss, 0, sizeof(struct shader_sampler));
}
static inline void shader_sampler_free(struct shader_sampler *ss)
{
size_t i;
for (i = 0; i < ss->states.num; i++)
bfree(ss->states.array[i]);
for (i = 0; i < ss->values.num; i++)
bfree(ss->values.array[i]);
bfree(ss->name);
da_free(ss->states);
da_free(ss->values);
}
EXPORT void shader_sampler_convert(struct shader_sampler *ss,
struct gs_sampler_info *info);
/* ------------------------------------------------------------------------- */
struct shader_struct {
char *name;
DARRAY(struct shader_var) vars;
};
static inline void shader_struct_init(struct shader_struct *ss)
{
memset(ss, 0, sizeof(struct shader_struct));
}
static inline void shader_struct_free(struct shader_struct *ss)
{
size_t i;
for (i = 0; i < ss->vars.num; i++)
shader_var_free(ss->vars.array+i);
bfree(ss->name);
da_free(ss->vars);
}
/* ------------------------------------------------------------------------- */
struct shader_func {
char *name;
char *return_type;
char *mapping;
DARRAY(struct shader_var) params;
struct cf_token *start, *end;
};
static inline void shader_func_init(struct shader_func *sf,
char *return_type, char *name)
{
da_init(sf->params);
sf->return_type = return_type;
sf->mapping = NULL;
sf->name = name;
sf->start = NULL;
sf->end = NULL;
}
static inline void shader_func_free(struct shader_func *sf)
{
size_t i;
for (i = 0; i < sf->params.num; i++)
shader_var_free(sf->params.array+i);
bfree(sf->name);
bfree(sf->return_type);
bfree(sf->mapping);
da_free(sf->params);
}
/* ------------------------------------------------------------------------- */
struct shader_parser {
struct cf_parser cfp;
DARRAY(struct shader_var) params;
DARRAY(struct shader_struct) structs;
DARRAY(struct shader_sampler) samplers;
DARRAY(struct shader_func) funcs;
};
static inline void shader_parser_init(struct shader_parser *sp)
{
cf_parser_init(&sp->cfp);
da_init(sp->params);
da_init(sp->structs);
da_init(sp->samplers);
da_init(sp->funcs);
}
static inline void shader_parser_free(struct shader_parser *sp)
{
size_t i;
for (i = 0; i < sp->params.num; i++)
shader_var_free(sp->params.array+i);
for (i = 0; i < sp->structs.num; i++)
shader_struct_free(sp->structs.array+i);
for (i = 0; i < sp->samplers.num; i++)
shader_sampler_free(sp->samplers.array+i);
for (i = 0; i < sp->funcs.num; i++)
shader_func_free(sp->funcs.array+i);
cf_parser_free(&sp->cfp);
da_free(sp->params);
da_free(sp->structs);
da_free(sp->samplers);
da_free(sp->funcs);
}
EXPORT bool shader_parse(struct shader_parser *sp, const char *shader,
const char *file);
static inline char *shader_parser_geterrors(struct shader_parser *sp)
{
return error_data_buildstring(&sp->cfp.error_list);
}
static inline struct shader_var *shader_parser_getparam(
struct shader_parser *sp, const char *param_name)
{
size_t i;
for (i = 0; i < sp->params.num; i++) {
struct shader_var *param = sp->params.array+i;
if (strcmp(param->name, param_name) == 0)
return param;
}
return NULL;
}
static inline struct shader_struct *shader_parser_getstruct(
struct shader_parser *sp, const char *struct_name)
{
size_t i;
for (i = 0; i < sp->structs.num; i++) {
struct shader_struct *st = sp->structs.array+i;
if (strcmp(st->name, struct_name) == 0)
return st;
}
return NULL;
}
static inline struct shader_sampler *shader_parser_getsampler(
struct shader_parser *sp, const char *sampler_name)
{
size_t i;
for (i = 0; i < sp->samplers.num; i++) {
struct shader_sampler *sampler = sp->samplers.array+i;
if (strcmp(sampler->name, sampler_name) == 0)
return sampler;
}
return NULL;
}
static inline struct shader_func *shader_parser_getfunc(
struct shader_parser *sp, const char *func_name)
{
size_t i;
for (i = 0; i < sp->funcs.num; i++) {
struct shader_func *func = sp->funcs.array+i;
if (strcmp(func->name, func_name) == 0)
return func;
}
return NULL;
}
#ifdef __cplusplus
}
#endif
|