1 /*
2 Copyright (C) 1996-2001 Id Software, Inc.
3 Copyright (C) 2002-2009 John Fitzgibbons and others
4 Copyright (C) 2010-2014 QuakeSpasm developers
5 Copyright (C) 2016 Axel Gneiting
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22 
23 #ifndef _GL_TEXMAN_H
24 #define _GL_TEXMAN_H
25 
26 //gl_texmgr.h -- fitzquake's texture manager. manages opengl texture images
27 
28 #define TEXPREF_NONE			0x0000
29 #define TEXPREF_MIPMAP			0x0001	// generate mipmaps
30 // TEXPREF_NEAREST and TEXPREF_LINEAR aren't supposed to be ORed with TEX_MIPMAP
31 #define TEXPREF_LINEAR			0x0002	// force linear
32 #define TEXPREF_NEAREST			0x0004	// force nearest
33 #define TEXPREF_ALPHA			0x0008	// allow alpha
34 #define TEXPREF_PAD			0x0010	// allow padding
35 #define TEXPREF_PERSIST			0x0020	// never free
36 #define TEXPREF_OVERWRITE		0x0040	// overwrite existing same-name texture
37 #define TEXPREF_NOPICMIP		0x0080	// always load full-sized
38 #define TEXPREF_FULLBRIGHT		0x0100	// use fullbright mask palette
39 #define TEXPREF_NOBRIGHT		0x0200	// use nobright mask palette
40 #define TEXPREF_CONCHARS		0x0400	// use conchars palette
41 #define TEXPREF_WARPIMAGE		0x0800	// resize this texture when warpimagesize changes
42 #define TEXPREF_PREMULTIPLY		0x1000	// rgb = rgb*a; a=a;
43 
44 enum srcformat {SRC_INDEXED, SRC_LIGHTMAP, SRC_RGBA};
45 
46 typedef uintptr_t src_offset_t;
47 struct glheap_s;
48 struct glheapnode_s;
49 
50 typedef struct gltexture_s {
51 //managed by texture manager
52 	struct gltexture_s	*next;
53 	qmodel_t		*owner;
54 //managed by image loading
55 	char			name[64];
56 	unsigned int		width; //size of image as it exists in opengl
57 	unsigned int		height; //size of image as it exists in opengl
58 	unsigned int		flags;
59 	char			source_file[MAX_QPATH]; //relative filepath to data source, or "" if source is in memory
60 	src_offset_t		source_offset; //byte offset into file, or memory address
61 	enum srcformat		source_format; //format of pixel data (indexed, lightmap, or rgba)
62 	unsigned int		source_width; //size of image in source data
63 	unsigned int		source_height; //size of image in source data
64 	unsigned short		source_crc; //generated by source data before modifications
65 	signed char			shirt; //0-13 shirt color, or -1 if never colormapped
66 	signed char			pants; //0-13 pants color, or -1 if never colormapped
67 //used for rendering
68 	VkImage				image;
69 	VkImageView			image_view;
70 	VkImageView			target_image_view;
71 	struct glheap_s *	heap;
72 	struct glheapnode_s *	heap_node;
73 	VkDescriptorSet		descriptor_set;
74 	VkFramebuffer		frame_buffer;
75 	VkDescriptorSet		warp_write_descriptor_set;
76 } gltexture_t;
77 
78 extern gltexture_t *notexture;
79 extern gltexture_t *nulltexture;
80 extern gltexture_t *whitetexture;
81 extern gltexture_t *greytexture;
82 
83 extern unsigned int d_8to24table[256];
84 extern unsigned int d_8to24table_fbright[256];
85 extern unsigned int d_8to24table_nobright[256];
86 extern unsigned int d_8to24table_conchars[256];
87 extern unsigned int d_8to24table_shirt[256];
88 extern unsigned int d_8to24table_pants[256];
89 
90 // TEXTURE MANAGER
91 
92 gltexture_t *TexMgr_FindTexture (qmodel_t *owner, const char *name);
93 gltexture_t *TexMgr_NewTexture (void);
94 void TexMgr_FreeTexture (gltexture_t *kill);
95 void TexMgr_FreeTextures (unsigned int flags, unsigned int mask);
96 void TexMgr_FreeTexturesForOwner (qmodel_t *owner);
97 void TexMgr_NewGame (void);
98 void TexMgr_Init (void);
99 void TexMgr_DeleteTextureObjects (void);
100 void TexMgr_CollectGarbage (void);
101 
102 // IMAGE LOADING
103 gltexture_t *TexMgr_LoadImage (qmodel_t *owner, const char *name, int width, int height, enum srcformat format,
104 			       byte *data, const char *source_file, src_offset_t source_offset, unsigned flags);
105 void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants);
106 void TexMgr_ReloadNobrightImages (void);
107 
108 void TexMgr_UpdateTextureDescriptorSets(void);
109 
110 
111 #endif	/* _GL_TEXMAN_H */
112 
113