a4573b399e3744207fc1e0aebb715f6d63c835c8
[mesa.git] / src / mesa / main / texobj.h
1 /**
2 * \file texobj.h
3 * Texture object management.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 *
9 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30
31 #ifndef TEXTOBJ_H
32 #define TEXTOBJ_H
33
34
35 #include "compiler.h"
36 #include "glheader.h"
37 #include "mtypes.h"
38 #include "samplerobj.h"
39
40
41 /**
42 * \name Internal functions
43 */
44 /*@{*/
45
46 extern struct gl_texture_object *
47 _mesa_lookup_texture(struct gl_context *ctx, GLuint id);
48
49 extern struct gl_texture_object *
50 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
51
52 extern void
53 _mesa_initialize_texture_object( struct gl_context *ctx,
54 struct gl_texture_object *obj,
55 GLuint name, GLenum target );
56
57 extern int
58 _mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
59
60 extern void
61 _mesa_delete_texture_object( struct gl_context *ctx,
62 struct gl_texture_object *obj );
63
64 extern void
65 _mesa_copy_texture_object( struct gl_texture_object *dest,
66 const struct gl_texture_object *src );
67
68 extern void
69 _mesa_clear_texture_object(struct gl_context *ctx,
70 struct gl_texture_object *obj);
71
72 extern void
73 _mesa_reference_texobj_(struct gl_texture_object **ptr,
74 struct gl_texture_object *tex);
75
76 static inline void
77 _mesa_reference_texobj(struct gl_texture_object **ptr,
78 struct gl_texture_object *tex)
79 {
80 if (*ptr != tex)
81 _mesa_reference_texobj_(ptr, tex);
82 }
83
84
85 /**
86 * Return number of faces for a texture target. This will be 6 for
87 * cube maps (and cube map arrays) and 1 otherwise.
88 * NOTE: this function is not used for cube map arrays which operate
89 * more like 2D arrays than cube maps.
90 */
91 static inline GLuint
92 _mesa_num_tex_faces(GLenum target)
93 {
94 switch (target) {
95 case GL_TEXTURE_CUBE_MAP:
96 case GL_PROXY_TEXTURE_CUBE_MAP:
97 return 6;
98 default:
99 return 1;
100 }
101 }
102
103
104 /** Is the texture "complete" with respect to the given sampler state? */
105 static inline GLboolean
106 _mesa_is_texture_complete(const struct gl_texture_object *texObj,
107 const struct gl_sampler_object *sampler)
108 {
109 if (texObj->_IsIntegerFormat &&
110 (sampler->MagFilter != GL_NEAREST ||
111 (sampler->MinFilter != GL_NEAREST &&
112 sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
113 /* If the format is integer, only nearest filtering is allowed */
114 return GL_FALSE;
115 }
116
117 if (_mesa_is_mipmap_filter(sampler))
118 return texObj->_MipmapComplete;
119 else
120 return texObj->_BaseComplete;
121 }
122
123
124 extern void
125 _mesa_test_texobj_completeness( const struct gl_context *ctx,
126 struct gl_texture_object *obj );
127
128 extern GLboolean
129 _mesa_cube_complete(const struct gl_texture_object *texObj);
130
131 extern void
132 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
133
134 extern struct gl_texture_object *
135 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
136
137 extern GLuint
138 _mesa_total_texture_memory(struct gl_context *ctx);
139
140 extern void
141 _mesa_unlock_context_textures( struct gl_context *ctx );
142
143 extern void
144 _mesa_lock_context_textures( struct gl_context *ctx );
145
146 /*@}*/
147
148 /**
149 * \name API functions
150 */
151 /*@{*/
152
153 extern void GLAPIENTRY
154 _mesa_GenTextures( GLsizei n, GLuint *textures );
155
156
157 extern void GLAPIENTRY
158 _mesa_DeleteTextures( GLsizei n, const GLuint *textures );
159
160
161 extern void GLAPIENTRY
162 _mesa_BindTexture( GLenum target, GLuint texture );
163
164
165 extern void GLAPIENTRY
166 _mesa_PrioritizeTextures( GLsizei n, const GLuint *textures,
167 const GLclampf *priorities );
168
169
170 extern GLboolean GLAPIENTRY
171 _mesa_AreTexturesResident( GLsizei n, const GLuint *textures,
172 GLboolean *residences );
173
174 extern GLboolean GLAPIENTRY
175 _mesa_IsTexture( GLuint texture );
176
177 extern void GLAPIENTRY
178 _mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset,
179 GLint yoffset, GLint zoffset, GLsizei width,
180 GLsizei height, GLsizei depth);
181
182 extern void GLAPIENTRY
183 _mesa_InvalidateTexImage(GLuint texture, GLint level);
184
185 /*@}*/
186
187
188 #endif