src/ascension/texture.h

changeset 50
d8d2e4817db1
equal deleted inserted replaced
49:77493525eac2 50:d8d2e4817db1
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * Copyright 2024 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 */
27
28 #ifndef ASCENSION_TEXTURE_H
29 #define ASCENSION_TEXTURE_H
30
31 #include <SDL2/SDL_surface.h>
32
33 typedef struct AscTexture AscTexture;
34
35 struct AscTexture {
36 unsigned target;
37 unsigned tex_id;
38 };
39
40 #define asc_texture_uninitialized(tex) ((tex)->tex_id == 0)
41
42 enum asc_texture_target {
43 ASC_TEXTURE_RECTANGLE
44 };
45
46 enum asc_texture_min_filter {
47 ASC_TEXTURE_MIN_FILTER_NEAREST,
48 ASC_TEXTURE_MIN_FILTER_LINEAR,
49 ASC_TEXTURE_MIN_FILTER_NEAREST_MIPMAP_NEAREST,
50 ASC_TEXTURE_MIN_FILTER_LINEAR_MIPMAP_NEAREST,
51 ASC_TEXTURE_MIN_FILTER_NEAREST_MIPMAP_LINEAR,
52 ASC_TEXTURE_MIN_FILTER_LINEAR_MIPMAP_LINEAR
53 };
54
55 enum asc_texture_mag_filter {
56 ASC_TEXTURE_MAG_FILTER_NEAREST,
57 ASC_TEXTURE_MAG_FILTER_LINEAR
58 };
59
60 __attribute__((__nonnull__))
61 void asc_texture_init(
62 AscTexture *tex,
63 enum asc_texture_target target,
64 enum asc_texture_min_filter min_filter,
65 enum asc_texture_mag_filter mag_filter
66 );
67
68 __attribute__((__nonnull__))
69 void asc_texture_destroy(AscTexture *tex);
70
71 #define asc_texture_init_rectangle(tex) \
72 asc_texture_init(tex, ASC_TEXTURE_RECTANGLE, \
73 ASC_TEXTURE_MIN_FILTER_LINEAR, ASC_TEXTURE_MAG_FILTER_LINEAR)
74
75 __attribute__((__nonnull__))
76 void asc_texture_bind(AscTexture const *tex, int uniform_location, int unit);
77
78 __attribute__((__nonnull__))
79 void asc_texture_from_surface(AscTexture *tex, SDL_Surface const *surface);
80
81 #endif //ASCENSION_TEXTURE_H

mercurial