eb5bdb2d08f133b1ea255e6f32a6e9e452105071
[mesa.git] / src / mesa / state_tracker / st_texobj.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Brian Paul
31 */
32
33 #include "imports.h"
34 #include "texformat.h"
35
36 #include "st_context.h"
37 #include "st_texobj.h"
38 #include "pipe/p_defines.h"
39
40
41 /**
42 * Create a pipe_texture_object from a Mesa texture object.
43 * Eventually, gl_texture_object may be derived from this...
44 */
45 struct pipe_texture_object *
46 create_texture_object(struct gl_texture_object *texObj)
47 {
48 struct pipe_texture_object *pto;
49 const struct gl_texture_image *texImage;
50
51 pto = calloc(1, sizeof(*pto));
52 if (!pto)
53 return NULL;
54
55 /* XXX: Member not defined. Comment-out to get it compile. */
56 /*assert(texObj->Complete);*/
57
58 switch (texObj->Target) {
59 case GL_TEXTURE_1D:
60 pto->type = PIPE_TEXTURE_1D;
61 break;
62 case GL_TEXTURE_2D:
63 pto->type = PIPE_TEXTURE_2D;
64 break;
65 case GL_TEXTURE_3D:
66 pto->type = PIPE_TEXTURE_3D;
67 break;
68 case GL_TEXTURE_CUBE_MAP:
69 pto->type = PIPE_TEXTURE_CUBE;
70 break;
71 default:
72 assert(0);
73 return NULL;
74 }
75
76 texImage = texObj->Image[0][texObj->BaseLevel];
77 assert(texImage);
78
79 switch (texImage->TexFormat->MesaFormat) {
80 case MESA_FORMAT_RGBA8888:
81 pto->format = PIPE_FORMAT_U_R8_G8_B8_A8;
82 break;
83 case MESA_FORMAT_RGB565:
84 pto->format = PIPE_FORMAT_U_R5_G6_B5;
85 break;
86
87 /* XXX fill in more formats */
88
89 default:
90 assert(0);
91 return NULL;
92 }
93
94 pto->width = texImage->Width;
95 pto->height = texImage->Height;
96 pto->depth = texImage->Depth;
97
98 /* XXX verify this */
99 pto->mipmapped = texObj->Image[0][texObj->BaseLevel + 1] != NULL;
100
101 return pto;
102 }