1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 * Copyright 2008 VMware, Inc. All rights reserved.
6 * Copyright 2009 Marek Olšák <[email protected]>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30 /**
31 * @file
32 * Texture mapping utility functions.
33 *
34 * @author Brian Paul
35 * Marek Olšák
36 */
37
38 #include "pipe/p_defines.h"
39
40 #include "util/u_debug.h"
41 #include "util/u_texture.h"
42
util_map_texcoords2d_onto_cubemap(unsigned face,const float * in_st,unsigned in_stride,float * out_str,unsigned out_stride)43 void util_map_texcoords2d_onto_cubemap(unsigned face,
44 const float *in_st, unsigned in_stride,
45 float *out_str, unsigned out_stride)
46 {
47 int i;
48 float rx, ry, rz;
49
50 /* loop over quad verts */
51 for (i = 0; i < 4; i++) {
52 const float sc = 2 * in_st[0] - 1;
53 const float tc = 2 * in_st[1] - 1;
54
55 switch (face) {
56 case PIPE_TEX_FACE_POS_X:
57 rx = 1;
58 ry = -tc;
59 rz = -sc;
60 break;
61 case PIPE_TEX_FACE_NEG_X:
62 rx = -1;
63 ry = -tc;
64 rz = sc;
65 break;
66 case PIPE_TEX_FACE_POS_Y:
67 rx = sc;
68 ry = 1;
69 rz = tc;
70 break;
71 case PIPE_TEX_FACE_NEG_Y:
72 rx = sc;
73 ry = -1;
74 rz = -tc;
75 break;
76 case PIPE_TEX_FACE_POS_Z:
77 rx = sc;
78 ry = -tc;
79 rz = 1;
80 break;
81 case PIPE_TEX_FACE_NEG_Z:
82 rx = -sc;
83 ry = -tc;
84 rz = -1;
85 break;
86 default:
87 rx = ry = rz = 0;
88 assert(0);
89 }
90
91 out_str[0] = rx; /*s*/
92 out_str[1] = ry; /*t*/
93 out_str[2] = rz; /*r*/
94
95 in_st += in_stride;
96 out_str += out_stride;
97 }
98 }
99