1848b8605Smrg/**
2848b8605Smrg * \file texobj.h
3848b8605Smrg * Texture object management.
4848b8605Smrg */
5848b8605Smrg
6848b8605Smrg/*
7848b8605Smrg * Mesa 3-D graphics library
8848b8605Smrg *
9848b8605Smrg * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
10848b8605Smrg *
11848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
12848b8605Smrg * copy of this software and associated documentation files (the "Software"),
13848b8605Smrg * to deal in the Software without restriction, including without limitation
14848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
16848b8605Smrg * Software is furnished to do so, subject to the following conditions:
17848b8605Smrg *
18848b8605Smrg * The above copyright notice and this permission notice shall be included
19848b8605Smrg * in all copies or substantial portions of the Software.
20848b8605Smrg *
21848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE.
28848b8605Smrg */
29848b8605Smrg
30848b8605Smrg
31848b8605Smrg#ifndef TEXTOBJ_H
32848b8605Smrg#define TEXTOBJ_H
33848b8605Smrg
34848b8605Smrg
35848b8605Smrg#include "glheader.h"
36848b8605Smrg#include "samplerobj.h"
37848b8605Smrg
38848b8605Smrg
39b8e80941Smrg#ifdef __cplusplus
40b8e80941Smrgextern "C" {
41b8e80941Smrg#endif
42b8e80941Smrg
43b8e80941Smrg
44848b8605Smrg/**
45848b8605Smrg * \name Internal functions
46848b8605Smrg */
47848b8605Smrg/*@{*/
48848b8605Smrg
49848b8605Smrgextern struct gl_texture_object *
50848b8605Smrg_mesa_lookup_texture(struct gl_context *ctx, GLuint id);
51848b8605Smrg
52b8e80941Smrgextern struct gl_texture_object *
53b8e80941Smrg_mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func);
54848b8605Smrg
55848b8605Smrgextern struct gl_texture_object *
56848b8605Smrg_mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id);
57848b8605Smrg
58b8e80941Smrgextern struct gl_texture_object *
59b8e80941Smrg_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target);
60b8e80941Smrg
61848b8605Smrgextern struct gl_texture_object *
62848b8605Smrg_mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
63848b8605Smrg
64848b8605Smrgextern void
65848b8605Smrg_mesa_initialize_texture_object( struct gl_context *ctx,
66848b8605Smrg                                 struct gl_texture_object *obj,
67848b8605Smrg                                 GLuint name, GLenum target );
68848b8605Smrg
69848b8605Smrgextern int
70848b8605Smrg_mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
71848b8605Smrg
72848b8605Smrgextern void
73848b8605Smrg_mesa_delete_texture_object( struct gl_context *ctx,
74848b8605Smrg                             struct gl_texture_object *obj );
75848b8605Smrg
76848b8605Smrgextern void
77848b8605Smrg_mesa_copy_texture_object( struct gl_texture_object *dest,
78848b8605Smrg                           const struct gl_texture_object *src );
79848b8605Smrg
80848b8605Smrgextern void
81848b8605Smrg_mesa_clear_texture_object(struct gl_context *ctx,
82b8e80941Smrg                           struct gl_texture_object *obj,
83b8e80941Smrg                           struct gl_texture_image *retainTexImage);
84848b8605Smrg
85848b8605Smrgextern void
86848b8605Smrg_mesa_reference_texobj_(struct gl_texture_object **ptr,
87848b8605Smrg                        struct gl_texture_object *tex);
88848b8605Smrg
89848b8605Smrgstatic inline void
90848b8605Smrg_mesa_reference_texobj(struct gl_texture_object **ptr,
91848b8605Smrg                       struct gl_texture_object *tex)
92848b8605Smrg{
93848b8605Smrg   if (*ptr != tex)
94848b8605Smrg      _mesa_reference_texobj_(ptr, tex);
95848b8605Smrg}
96848b8605Smrg
97848b8605Smrg/**
98b8e80941Smrg * Lock a texture for updating.  See also _mesa_lock_context_textures().
99848b8605Smrg */
100b8e80941Smrgstatic inline void
101b8e80941Smrg_mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
102848b8605Smrg{
103b8e80941Smrg   mtx_lock(&ctx->Shared->TexMutex);
104b8e80941Smrg   ctx->Shared->TextureStateStamp++;
105b8e80941Smrg   (void) texObj;
106b8e80941Smrg}
107b8e80941Smrg
108b8e80941Smrgstatic inline void
109b8e80941Smrg_mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
110b8e80941Smrg{
111b8e80941Smrg   (void) texObj;
112b8e80941Smrg   mtx_unlock(&ctx->Shared->TexMutex);
113848b8605Smrg}
114848b8605Smrg
115848b8605Smrg
116848b8605Smrg/** Is the texture "complete" with respect to the given sampler state? */
117848b8605Smrgstatic inline GLboolean
118848b8605Smrg_mesa_is_texture_complete(const struct gl_texture_object *texObj,
119848b8605Smrg                          const struct gl_sampler_object *sampler)
120848b8605Smrg{
121b8e80941Smrg   /*
122b8e80941Smrg    * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
123b8e80941Smrg    * be forbidden, however it is allowed per GL 4.5 rules, allow it
124b8e80941Smrg    * even without GL 4.5 since it was a spec mistake.
125b8e80941Smrg    */
126b8e80941Smrg   if ((texObj->_IsIntegerFormat ||
127b8e80941Smrg        (texObj->StencilSampling &&
128b8e80941Smrg         texObj->Image[0][texObj->BaseLevel]->_BaseFormat == GL_DEPTH_STENCIL)) &&
129848b8605Smrg       (sampler->MagFilter != GL_NEAREST ||
130848b8605Smrg        (sampler->MinFilter != GL_NEAREST &&
131848b8605Smrg         sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
132848b8605Smrg      /* If the format is integer, only nearest filtering is allowed */
133848b8605Smrg      return GL_FALSE;
134848b8605Smrg   }
135848b8605Smrg
136848b8605Smrg   if (_mesa_is_mipmap_filter(sampler))
137848b8605Smrg      return texObj->_MipmapComplete;
138848b8605Smrg   else
139848b8605Smrg      return texObj->_BaseComplete;
140848b8605Smrg}
141848b8605Smrg
142848b8605Smrg
143848b8605Smrgextern void
144848b8605Smrg_mesa_test_texobj_completeness( const struct gl_context *ctx,
145848b8605Smrg                                struct gl_texture_object *obj );
146848b8605Smrg
147b8e80941Smrgextern GLboolean
148b8e80941Smrg_mesa_cube_level_complete(const struct gl_texture_object *texObj,
149b8e80941Smrg                          const GLint level);
150b8e80941Smrg
151848b8605Smrgextern GLboolean
152848b8605Smrg_mesa_cube_complete(const struct gl_texture_object *texObj);
153848b8605Smrg
154848b8605Smrgextern void
155848b8605Smrg_mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
156848b8605Smrg
157848b8605Smrgextern struct gl_texture_object *
158848b8605Smrg_mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
159848b8605Smrg
160848b8605Smrgextern GLuint
161848b8605Smrg_mesa_total_texture_memory(struct gl_context *ctx);
162848b8605Smrg
163b8e80941Smrgextern GLenum
164b8e80941Smrg_mesa_texture_base_format(const struct gl_texture_object *texObj);
165b8e80941Smrg
166848b8605Smrgextern void
167848b8605Smrg_mesa_unlock_context_textures( struct gl_context *ctx );
168848b8605Smrg
169848b8605Smrgextern void
170848b8605Smrg_mesa_lock_context_textures( struct gl_context *ctx );
171848b8605Smrg
172b8e80941Smrgextern void
173b8e80941Smrg_mesa_delete_nameless_texture(struct gl_context *ctx,
174b8e80941Smrg                              struct gl_texture_object *texObj);
175b8e80941Smrg
176b8e80941Smrgextern void
177b8e80941Smrg_mesa_bind_texture(struct gl_context *ctx, GLenum target,
178b8e80941Smrg                   struct gl_texture_object *tex_obj);
179848b8605Smrg/*@}*/
180848b8605Smrg
181848b8605Smrg/**
182848b8605Smrg * \name API functions
183848b8605Smrg */
184848b8605Smrg/*@{*/
185848b8605Smrg
186b8e80941Smrgvoid GLAPIENTRY
187b8e80941Smrg_mesa_GenTextures_no_error(GLsizei n, GLuint *textures);
188b8e80941Smrg
189b8e80941Smrgextern void GLAPIENTRY
190b8e80941Smrg_mesa_GenTextures(GLsizei n, GLuint *textures);
191b8e80941Smrg
192b8e80941Smrgvoid GLAPIENTRY
193b8e80941Smrg_mesa_CreateTextures_no_error(GLenum target, GLsizei n, GLuint *textures);
194b8e80941Smrg
195848b8605Smrgextern void GLAPIENTRY
196b8e80941Smrg_mesa_CreateTextures(GLenum target, GLsizei n, GLuint *textures);
197848b8605Smrg
198b8e80941Smrgvoid GLAPIENTRY
199b8e80941Smrg_mesa_DeleteTextures_no_error(GLsizei n, const GLuint *textures);
200848b8605Smrg
201848b8605Smrgextern void GLAPIENTRY
202848b8605Smrg_mesa_DeleteTextures( GLsizei n, const GLuint *textures );
203848b8605Smrg
204848b8605Smrg
205b8e80941Smrgvoid GLAPIENTRY
206b8e80941Smrg_mesa_BindTexture_no_error(GLenum target, GLuint texture);
207b8e80941Smrg
208848b8605Smrgextern void GLAPIENTRY
209848b8605Smrg_mesa_BindTexture( GLenum target, GLuint texture );
210848b8605Smrg
211b8e80941Smrgvoid GLAPIENTRY
212b8e80941Smrg_mesa_BindTextureUnit_no_error(GLuint unit, GLuint texture);
213b8e80941Smrg
214b8e80941Smrgextern void GLAPIENTRY
215b8e80941Smrg_mesa_BindTextureUnit(GLuint unit, GLuint texture);
216b8e80941Smrg
217b8e80941Smrgvoid GLAPIENTRY
218b8e80941Smrg_mesa_BindTextures_no_error(GLuint first, GLsizei count,
219b8e80941Smrg                            const GLuint *textures);
220848b8605Smrg
221848b8605Smrgextern void GLAPIENTRY
222848b8605Smrg_mesa_BindTextures( GLuint first, GLsizei count, const GLuint *textures );
223848b8605Smrg
224848b8605Smrg
225848b8605Smrgextern void GLAPIENTRY
226848b8605Smrg_mesa_PrioritizeTextures( GLsizei n, const GLuint *textures,
227848b8605Smrg                          const GLclampf *priorities );
228848b8605Smrg
229848b8605Smrg
230848b8605Smrgextern GLboolean GLAPIENTRY
231848b8605Smrg_mesa_AreTexturesResident( GLsizei n, const GLuint *textures,
232848b8605Smrg                           GLboolean *residences );
233848b8605Smrg
234848b8605Smrgextern GLboolean GLAPIENTRY
235848b8605Smrg_mesa_IsTexture( GLuint texture );
236848b8605Smrg
237b8e80941Smrgvoid GLAPIENTRY
238b8e80941Smrg_mesa_InvalidateTexSubImage_no_error(GLuint texture, GLint level, GLint xoffset,
239b8e80941Smrg                                     GLint yoffset, GLint zoffset,
240b8e80941Smrg                                     GLsizei width, GLsizei height,
241b8e80941Smrg                                     GLsizei depth);
242b8e80941Smrg
243848b8605Smrgextern void GLAPIENTRY
244848b8605Smrg_mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset,
245848b8605Smrg                            GLint yoffset, GLint zoffset, GLsizei width,
246848b8605Smrg                            GLsizei height, GLsizei depth);
247b8e80941Smrgvoid GLAPIENTRY
248b8e80941Smrg_mesa_InvalidateTexImage_no_error(GLuint texture, GLint level);
249848b8605Smrg
250848b8605Smrgextern void GLAPIENTRY
251848b8605Smrg_mesa_InvalidateTexImage(GLuint texture, GLint level);
252848b8605Smrg
253848b8605Smrg/*@}*/
254848b8605Smrg
255848b8605Smrg
256b8e80941Smrg#ifdef __cplusplus
257b8e80941Smrg}
258b8e80941Smrg#endif
259b8e80941Smrg
260b8e80941Smrg
261848b8605Smrg#endif
262