Tue, 09 Apr 2024 21:18:52 +0200
add texture.h
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * Copyright 2023 Mike Becker. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
28 #ifndef ASCENSION_SHADER_H
29 #define ASCENSION_SHADER_H
31 typedef struct AscShader {
32 unsigned int id;
33 } AscShader;
35 typedef struct AscShaderProgram {
36 unsigned int id;
37 int model;
38 int view;
39 int projection;
40 } AscShaderProgram;
42 typedef struct AscShaderSprite {
43 AscShaderProgram base;
44 int depth;
45 int tex;
46 } AscShaderSprite;
49 /**
50 * Compiles a shader from the given source code.
51 *
52 * The ID of the returned shader will be zero when something went wrong.
53 *
54 * @param type the shader type (use the GL enum)
55 * @param code the source code
56 * @param length the length of the source code
57 * @return the compiled shader
58 */
59 AscShader asc_shader_compile(unsigned int type, char const *code, int length);
61 /**
62 * Compiles a shader from the given source file.
63 *
64 * The ID of the returned shader will be zero when something went wrong.
65 * The file is mapped into memory for compilation and then unmapped again.
66 *
67 * @param type the shader type (use the GL enum)
68 * @param filename the path to the shader file
69 * @return the compiled shader
70 */
71 AscShader asc_shader_compilef(unsigned int type, char const *filename);
73 /**
74 * This function links shaders into a program.
75 *
76 * The ID of the returned program will be zero when something went wrong.
77 *
78 * @param vertex the vertex shader
79 * @param fragment the fragment shader
80 * @return a compiled program
81 */
82 AscShaderProgram asc_shader_link(AscShader vertex, AscShader fragment);
84 /**
85 * Destroys the shader.
86 *
87 * @param shader the shader
88 */
89 void asc_shader_destroy(AscShader shader);
91 /**
92 * Destroys the shader program.
93 *
94 * @param program the program
95 */
96 void asc_shader_program_destroy(AscShaderProgram program);
99 AscShaderProgram asc_shader_easy_compile_and_link(
100 char const *vtxName,
101 char const *fragName
102 );
104 #endif //ASCENSION_SHADER_H