📄 sis_tex.c
字号:
/**************************************************************************Copyright 2003 Eric AnholtAll Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationon the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whomthe Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice (including the nextparagraph) shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALLERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* $XFree86$ *//* * Authors: * Eric Anholt <anholt@FreeBSD.org> */#include "sis_context.h"#include "sis_alloc.h"#include "sis_tex.h"#include "swrast/swrast.h"#include "imports.h"#include "texformat.h"#include "texstore.h"#include "teximage.h"#include "texobj.h"#include "xmlpool.h"#define ALIGN(value, align) (GLubyte *)((long)(value + align - 1) & ~(align - 1))#define TEXTURE_HW_ALIGNMENT 4#define TEXTURE_HW_PLUS (4 + 4)static sisTexObjPtrsisAllocTexObj( struct gl_texture_object *texObj ){ sisTexObjPtr t; t = (sisTexObjPtr) CALLOC_STRUCT( sis_tex_obj ); texObj->DriverData = t; return t;}static voidsisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level, const struct gl_texture_image *image ){ char *addr; int size, texel_size; if (t->format == 0) { t->format = image->_BaseFormat; switch (image->TexFormat->MesaFormat) { case MESA_FORMAT_ARGB8888: t->hwformat = TEXEL_ARGB_8888_32; break; case MESA_FORMAT_ARGB4444: t->hwformat = TEXEL_ARGB_4444_16; break; case MESA_FORMAT_ARGB1555: t->hwformat = TEXEL_ARGB_1555_16; break; case MESA_FORMAT_RGB565: t->hwformat = TEXEL_RGB_565_16; break; case MESA_FORMAT_RGB332: t->hwformat = TEXEL_RGB_332_8; break; case MESA_FORMAT_I8: t->hwformat = TEXEL_I8; break; case MESA_FORMAT_A8: t->hwformat = TEXEL_A8; break; case MESA_FORMAT_L8: t->hwformat = TEXEL_L8; break; case MESA_FORMAT_AL88: t->hwformat = TEXEL_AL88; break; case MESA_FORMAT_YCBCR: t->hwformat = TEXEL_YUV422; break; case MESA_FORMAT_YCBCR_REV: t->hwformat = TEXEL_VUY422; break; default: sis_fatal_error("Bad texture format 0x%x.\n", image->TexFormat->MesaFormat); } } assert(t->format == image->_BaseFormat); texel_size = image->TexFormat->TexelBytes; size = image->Width * image->Height * texel_size + TEXTURE_HW_PLUS; addr = sisAllocFB( smesa, size, &t->image[level].handle ); if (addr == NULL) { addr = sisAllocAGP( smesa, size, &t->image[level].handle ); if (addr == NULL) sis_fatal_error("Failure to allocate texture memory.\n"); t->image[level].memType = AGP_TYPE; } else t->image[level].memType = VIDEO_TYPE; t->image[level].Data = ALIGN(addr, TEXTURE_HW_ALIGNMENT); t->image[level].pitch = image->Width * texel_size; t->image[level].size = image->Width * image->Height * texel_size; t->numImages++;}static voidsisFreeTexImage( sisContextPtr smesa, sisTexObjPtr t, int level ){ assert(level >= 0); assert(level < SIS_MAX_TEXTURE_LEVELS); if (t->image[level].Data == NULL) return; switch (t->image[level].memType) { case VIDEO_TYPE: sisFreeFB( smesa, t->image[level].handle ); break; case AGP_TYPE: sisFreeAGP( smesa, t->image[level].handle ); break; } t->image[level].Data = NULL; t->image[level].handle = NULL; /* If there are no textures loaded any more, reset the hw format so the * object can be reused for new formats */ t->numImages--; if (t->numImages == 0) { t->format = 0; t->hwformat = 0; }}static void sisTexEnv( GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param ){ sisContextPtr smesa = SIS_CONTEXT(ctx); smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV;}static voidsisTexParameter( GLcontext *ctx, GLenum target, struct gl_texture_object *texObj, GLenum pname, const GLfloat *params ){ sisContextPtr smesa = SIS_CONTEXT(ctx); smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING;}static voidsisBindTexture( GLcontext *ctx, GLenum target, struct gl_texture_object *texObj ){ sisContextPtr smesa = SIS_CONTEXT(ctx); sisTexObjPtr t; if ( target == GL_TEXTURE_2D || target == GL_TEXTURE_1D ) { if ( texObj->DriverData == NULL ) { sisAllocTexObj( texObj ); } } t = texObj->DriverData; if (!t) return; if (smesa->PrevTexFormat[ctx->Texture.CurrentUnit] != t->format) { smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURE_ENV; smesa->PrevTexFormat[ctx->Texture.CurrentUnit] = t->format; } smesa->TexStates[ctx->Texture.CurrentUnit] |= NEW_TEXTURING;}static voidsisDeleteTexture( GLcontext * ctx, struct gl_texture_object *texObj ){ sisContextPtr smesa = SIS_CONTEXT(ctx); sisTexObjPtr t; int i; smesa->clearTexCache = GL_TRUE; t = texObj->DriverData; if (t == NULL) { /* * this shows the texture is default object and never be a * argument of sisTexImage* */ return; } for (i = 0; i < SIS_MAX_TEXTURE_LEVELS; i++) { sisFreeTexImage( smesa, t, i ); } FREE(t); texObj->DriverData = NULL; /* Free mipmap images and the texture object itself */ _mesa_delete_texture_object(ctx, texObj);}static GLboolean sisIsTextureResident( GLcontext * ctx, struct gl_texture_object *texObj ){ return (texObj->DriverData != NULL);}static const struct gl_texture_format *sisChooseTextureFormat( GLcontext *ctx, GLint internalFormat, GLenum format, GLenum type ){ sisContextPtr smesa = SIS_CONTEXT(ctx); const GLboolean do32bpt = (smesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32); const GLboolean force16bpt = (smesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16); switch ( internalFormat ) { case 4: case GL_RGBA: case GL_COMPRESSED_RGBA: switch ( type ) { case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: return &_mesa_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: return &_mesa_texformat_argb1555; default: return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; } case 3: case GL_RGB: case GL_COMPRESSED_RGB: switch ( type ) { case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: return &_mesa_texformat_argb4444; case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: return &_mesa_texformat_argb1555; case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: return &_mesa_texformat_rgb565; default: return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565; } case GL_RGBA8: case GL_RGBA12: case GL_RGBA16: return !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; case GL_RGB10_A2: return !force16bpt ?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -