X-Git-Url: https://git.cworth.org/git?p=glaze;a=blobdiff_plain;f=glaze.h;fp=glaze.h;h=9a9115a3a516e33189f737f82f5f2fe1998cd62f;hp=0000000000000000000000000000000000000000;hb=cec0694a7f219bd3590e6a04beba34ca45539540;hpb=0b190cc8fbca0f970eadd8c0f1d5792c41f71cf6 diff --git a/glaze.h b/glaze.h new file mode 100644 index 0000000..9a9115a --- /dev/null +++ b/glaze.h @@ -0,0 +1,58 @@ +/* Copyright © 2013, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GLAZE_H +#define GLAZE_H + +/* Perform dynamic lookup of 'function' within the library specified + * by the GLAZE_LIBGL environment variable. + */ +void * +glaze_lookup (char *function); + +/* A helper macro for glaze-using wrappers to defer an operation to + * the "real" underlying OpenGL function. + * + * The underlying function to be called will be obtained by calling + * glaze_lookup. This lookup will be cached in a local variable + * (defined by this macro) named real_. + * + * NOTE: This macro can only be used a single time within any + * function, (due to the locally-defined variable). If this is + * inadequate, callers can instead call glaze_lookup manually. + */ +#define GLAZE_DEFER(function,...) do { \ + static typeof(&function) real_ ## function; \ + if (! real_ ## function) \ + real_ ## function = glaze_lookup (#function); \ + real_ ## function(__VA_ARGS__); \ +} while (0); + +/* As GLAZE_DEFER, but also set 'ret' to the value returned by the + * underlying "real" function. */ +#define GLAZE_DEFER_WITH_RETURN(ret, function,...) do { \ + static typeof(&function) real_ ## function; \ + if (! real_ ## function) \ + real_ ## function = glaze_lookup (#function); \ + (ret) = real_ ## function(__VA_ARGS__); \ +} while (0); + +#endif /* GLAZE_H */