texobj.h revision 848b8605
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 "compiler.h" 36848b8605Smrg#include "glheader.h" 37848b8605Smrg#include "mtypes.h" 38848b8605Smrg#include "samplerobj.h" 39848b8605Smrg 40848b8605Smrg 41848b8605Smrg/** 42848b8605Smrg * \name Internal functions 43848b8605Smrg */ 44848b8605Smrg/*@{*/ 45848b8605Smrg 46848b8605Smrgextern struct gl_texture_object * 47848b8605Smrg_mesa_lookup_texture(struct gl_context *ctx, GLuint id); 48848b8605Smrg 49848b8605Smrgextern void 50848b8605Smrg_mesa_begin_texture_lookups(struct gl_context *ctx); 51848b8605Smrg 52848b8605Smrgextern void 53848b8605Smrg_mesa_end_texture_lookups(struct gl_context *ctx); 54848b8605Smrg 55848b8605Smrgextern struct gl_texture_object * 56848b8605Smrg_mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id); 57848b8605Smrg 58848b8605Smrgextern struct gl_texture_object * 59848b8605Smrg_mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target ); 60848b8605Smrg 61848b8605Smrgextern void 62848b8605Smrg_mesa_initialize_texture_object( struct gl_context *ctx, 63848b8605Smrg struct gl_texture_object *obj, 64848b8605Smrg GLuint name, GLenum target ); 65848b8605Smrg 66848b8605Smrgextern int 67848b8605Smrg_mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target); 68848b8605Smrg 69848b8605Smrgextern void 70848b8605Smrg_mesa_delete_texture_object( struct gl_context *ctx, 71848b8605Smrg struct gl_texture_object *obj ); 72848b8605Smrg 73848b8605Smrgextern void 74848b8605Smrg_mesa_copy_texture_object( struct gl_texture_object *dest, 75848b8605Smrg const struct gl_texture_object *src ); 76848b8605Smrg 77848b8605Smrgextern void 78848b8605Smrg_mesa_clear_texture_object(struct gl_context *ctx, 79848b8605Smrg struct gl_texture_object *obj); 80848b8605Smrg 81848b8605Smrgextern void 82848b8605Smrg_mesa_reference_texobj_(struct gl_texture_object **ptr, 83848b8605Smrg struct gl_texture_object *tex); 84848b8605Smrg 85848b8605Smrgstatic inline void 86848b8605Smrg_mesa_reference_texobj(struct gl_texture_object **ptr, 87848b8605Smrg struct gl_texture_object *tex) 88848b8605Smrg{ 89848b8605Smrg if (*ptr != tex) 90848b8605Smrg _mesa_reference_texobj_(ptr, tex); 91848b8605Smrg} 92848b8605Smrg 93848b8605Smrg 94848b8605Smrg/** 95848b8605Smrg * Return number of faces for a texture target. This will be 6 for 96848b8605Smrg * cube maps (and cube map arrays) and 1 otherwise. 97848b8605Smrg * NOTE: this function is not used for cube map arrays which operate 98848b8605Smrg * more like 2D arrays than cube maps. 99848b8605Smrg */ 100848b8605Smrgstatic inline GLuint 101848b8605Smrg_mesa_num_tex_faces(GLenum target) 102848b8605Smrg{ 103848b8605Smrg switch (target) { 104848b8605Smrg case GL_TEXTURE_CUBE_MAP: 105848b8605Smrg case GL_PROXY_TEXTURE_CUBE_MAP: 106848b8605Smrg return 6; 107848b8605Smrg default: 108848b8605Smrg return 1; 109848b8605Smrg } 110848b8605Smrg} 111848b8605Smrg 112848b8605Smrg 113848b8605Smrg/** Is the texture "complete" with respect to the given sampler state? */ 114848b8605Smrgstatic inline GLboolean 115848b8605Smrg_mesa_is_texture_complete(const struct gl_texture_object *texObj, 116848b8605Smrg const struct gl_sampler_object *sampler) 117848b8605Smrg{ 118848b8605Smrg if (texObj->_IsIntegerFormat && 119848b8605Smrg (sampler->MagFilter != GL_NEAREST || 120848b8605Smrg (sampler->MinFilter != GL_NEAREST && 121848b8605Smrg sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) { 122848b8605Smrg /* If the format is integer, only nearest filtering is allowed */ 123848b8605Smrg return GL_FALSE; 124848b8605Smrg } 125848b8605Smrg 126848b8605Smrg /* From the ARB_stencil_texturing specification: 127848b8605Smrg * "Add a new bullet point for the conditions that cause the texture 128848b8605Smrg * to not be complete: 129848b8605Smrg * 130848b8605Smrg * * The internal format of the texture is DEPTH_STENCIL, the 131848b8605Smrg * DEPTH_STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX and either 132848b8605Smrg * the magnification filter or the minification filter is not NEAREST." 133848b8605Smrg */ 134848b8605Smrg if (texObj->StencilSampling && 135848b8605Smrg texObj->Image[0][texObj->BaseLevel]->_BaseFormat == GL_DEPTH_STENCIL && 136848b8605Smrg (sampler->MagFilter != GL_NEAREST || sampler->MinFilter != GL_NEAREST)) { 137848b8605Smrg return GL_FALSE; 138848b8605Smrg } 139848b8605Smrg 140848b8605Smrg if (_mesa_is_mipmap_filter(sampler)) 141848b8605Smrg return texObj->_MipmapComplete; 142848b8605Smrg else 143848b8605Smrg return texObj->_BaseComplete; 144848b8605Smrg} 145848b8605Smrg 146848b8605Smrg 147848b8605Smrgextern void 148848b8605Smrg_mesa_test_texobj_completeness( const struct gl_context *ctx, 149848b8605Smrg struct gl_texture_object *obj ); 150848b8605Smrg 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 163848b8605Smrgextern void 164848b8605Smrg_mesa_unlock_context_textures( struct gl_context *ctx ); 165848b8605Smrg 166848b8605Smrgextern void 167848b8605Smrg_mesa_lock_context_textures( struct gl_context *ctx ); 168848b8605Smrg 169848b8605Smrg/*@}*/ 170848b8605Smrg 171848b8605Smrg/** 172848b8605Smrg * \name API functions 173848b8605Smrg */ 174848b8605Smrg/*@{*/ 175848b8605Smrg 176848b8605Smrgextern void GLAPIENTRY 177848b8605Smrg_mesa_GenTextures( GLsizei n, GLuint *textures ); 178848b8605Smrg 179848b8605Smrg 180848b8605Smrgextern void GLAPIENTRY 181848b8605Smrg_mesa_DeleteTextures( GLsizei n, const GLuint *textures ); 182848b8605Smrg 183848b8605Smrg 184848b8605Smrgextern void GLAPIENTRY 185848b8605Smrg_mesa_BindTexture( GLenum target, GLuint texture ); 186848b8605Smrg 187848b8605Smrg 188848b8605Smrgextern void GLAPIENTRY 189848b8605Smrg_mesa_BindTextures( GLuint first, GLsizei count, const GLuint *textures ); 190848b8605Smrg 191848b8605Smrg 192848b8605Smrgextern void GLAPIENTRY 193848b8605Smrg_mesa_PrioritizeTextures( GLsizei n, const GLuint *textures, 194848b8605Smrg const GLclampf *priorities ); 195848b8605Smrg 196848b8605Smrg 197848b8605Smrgextern GLboolean GLAPIENTRY 198848b8605Smrg_mesa_AreTexturesResident( GLsizei n, const GLuint *textures, 199848b8605Smrg GLboolean *residences ); 200848b8605Smrg 201848b8605Smrgextern GLboolean GLAPIENTRY 202848b8605Smrg_mesa_IsTexture( GLuint texture ); 203848b8605Smrg 204848b8605Smrgextern void GLAPIENTRY 205848b8605Smrg_mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset, 206848b8605Smrg GLint yoffset, GLint zoffset, GLsizei width, 207848b8605Smrg GLsizei height, GLsizei depth); 208848b8605Smrg 209848b8605Smrgextern void GLAPIENTRY 210848b8605Smrg_mesa_InvalidateTexImage(GLuint texture, GLint level); 211848b8605Smrg 212848b8605Smrg/*@}*/ 213848b8605Smrg 214848b8605Smrg 215848b8605Smrg#endif 216