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 "glheader.h" 36#include "samplerobj.h" 37 38 39#ifdef __cplusplus 40extern "C" { 41#endif 42 43 44/** 45 * \name Internal functions 46 */ 47/*@{*/ 48 49extern struct gl_texture_object * 50_mesa_lookup_texture(struct gl_context *ctx, GLuint id); 51 52extern struct gl_texture_object * 53_mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func); 54 55extern struct gl_texture_object * 56_mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id); 57 58extern struct gl_texture_object * 59_mesa_get_current_tex_object(struct gl_context *ctx, GLenum target); 60 61extern struct gl_texture_object * 62_mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target ); 63 64extern void 65_mesa_initialize_texture_object( struct gl_context *ctx, 66 struct gl_texture_object *obj, 67 GLuint name, GLenum target ); 68 69extern int 70_mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target); 71 72extern void 73_mesa_delete_texture_object( struct gl_context *ctx, 74 struct gl_texture_object *obj ); 75 76extern void 77_mesa_copy_texture_object( struct gl_texture_object *dest, 78 const struct gl_texture_object *src ); 79 80extern void 81_mesa_clear_texture_object(struct gl_context *ctx, 82 struct gl_texture_object *obj, 83 struct gl_texture_image *retainTexImage); 84 85extern void 86_mesa_reference_texobj_(struct gl_texture_object **ptr, 87 struct gl_texture_object *tex); 88 89static inline void 90_mesa_reference_texobj(struct gl_texture_object **ptr, 91 struct gl_texture_object *tex) 92{ 93 if (*ptr != tex) 94 _mesa_reference_texobj_(ptr, tex); 95} 96 97/** 98 * Lock a texture for updating. See also _mesa_lock_context_textures(). 99 */ 100static inline void 101_mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj) 102{ 103 mtx_lock(&ctx->Shared->TexMutex); 104 ctx->Shared->TextureStateStamp++; 105 (void) texObj; 106} 107 108static inline void 109_mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj) 110{ 111 (void) texObj; 112 mtx_unlock(&ctx->Shared->TexMutex); 113} 114 115 116/** Is the texture "complete" with respect to the given sampler state? */ 117static inline GLboolean 118_mesa_is_texture_complete(const struct gl_texture_object *texObj, 119 const struct gl_sampler_object *sampler) 120{ 121 /* 122 * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would 123 * be forbidden, however it is allowed per GL 4.5 rules, allow it 124 * even without GL 4.5 since it was a spec mistake. 125 */ 126 if ((texObj->_IsIntegerFormat || 127 (texObj->StencilSampling && 128 texObj->Image[0][texObj->BaseLevel]->_BaseFormat == GL_DEPTH_STENCIL)) && 129 (sampler->MagFilter != GL_NEAREST || 130 (sampler->MinFilter != GL_NEAREST && 131 sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) { 132 /* If the format is integer, only nearest filtering is allowed */ 133 return GL_FALSE; 134 } 135 136 if (_mesa_is_mipmap_filter(sampler)) 137 return texObj->_MipmapComplete; 138 else 139 return texObj->_BaseComplete; 140} 141 142 143extern void 144_mesa_test_texobj_completeness( const struct gl_context *ctx, 145 struct gl_texture_object *obj ); 146 147extern GLboolean 148_mesa_cube_level_complete(const struct gl_texture_object *texObj, 149 const GLint level); 150 151extern GLboolean 152_mesa_cube_complete(const struct gl_texture_object *texObj); 153 154extern void 155_mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj); 156 157extern struct gl_texture_object * 158_mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex); 159 160extern GLuint 161_mesa_total_texture_memory(struct gl_context *ctx); 162 163extern GLenum 164_mesa_texture_base_format(const struct gl_texture_object *texObj); 165 166extern void 167_mesa_unlock_context_textures( struct gl_context *ctx ); 168 169extern void 170_mesa_lock_context_textures( struct gl_context *ctx ); 171 172extern void 173_mesa_delete_nameless_texture(struct gl_context *ctx, 174 struct gl_texture_object *texObj); 175 176extern void 177_mesa_bind_texture(struct gl_context *ctx, GLenum target, 178 struct gl_texture_object *tex_obj); 179/*@}*/ 180 181/** 182 * \name API functions 183 */ 184/*@{*/ 185 186void GLAPIENTRY 187_mesa_GenTextures_no_error(GLsizei n, GLuint *textures); 188 189extern void GLAPIENTRY 190_mesa_GenTextures(GLsizei n, GLuint *textures); 191 192void GLAPIENTRY 193_mesa_CreateTextures_no_error(GLenum target, GLsizei n, GLuint *textures); 194 195extern void GLAPIENTRY 196_mesa_CreateTextures(GLenum target, GLsizei n, GLuint *textures); 197 198void GLAPIENTRY 199_mesa_DeleteTextures_no_error(GLsizei n, const GLuint *textures); 200 201extern void GLAPIENTRY 202_mesa_DeleteTextures( GLsizei n, const GLuint *textures ); 203 204 205void GLAPIENTRY 206_mesa_BindTexture_no_error(GLenum target, GLuint texture); 207 208extern void GLAPIENTRY 209_mesa_BindTexture( GLenum target, GLuint texture ); 210 211void GLAPIENTRY 212_mesa_BindTextureUnit_no_error(GLuint unit, GLuint texture); 213 214extern void GLAPIENTRY 215_mesa_BindTextureUnit(GLuint unit, GLuint texture); 216 217void GLAPIENTRY 218_mesa_BindTextures_no_error(GLuint first, GLsizei count, 219 const GLuint *textures); 220 221extern void GLAPIENTRY 222_mesa_BindTextures( GLuint first, GLsizei count, const GLuint *textures ); 223 224 225extern void GLAPIENTRY 226_mesa_PrioritizeTextures( GLsizei n, const GLuint *textures, 227 const GLclampf *priorities ); 228 229 230extern GLboolean GLAPIENTRY 231_mesa_AreTexturesResident( GLsizei n, const GLuint *textures, 232 GLboolean *residences ); 233 234extern GLboolean GLAPIENTRY 235_mesa_IsTexture( GLuint texture ); 236 237void GLAPIENTRY 238_mesa_InvalidateTexSubImage_no_error(GLuint texture, GLint level, GLint xoffset, 239 GLint yoffset, GLint zoffset, 240 GLsizei width, GLsizei height, 241 GLsizei depth); 242 243extern void GLAPIENTRY 244_mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset, 245 GLint yoffset, GLint zoffset, GLsizei width, 246 GLsizei height, GLsizei depth); 247void GLAPIENTRY 248_mesa_InvalidateTexImage_no_error(GLuint texture, GLint level); 249 250extern void GLAPIENTRY 251_mesa_InvalidateTexImage(GLuint texture, GLint level); 252 253/*@}*/ 254 255 256#ifdef __cplusplus 257} 258#endif 259 260 261#endif 262