draw: corrections to allow for different cliptest cases
[mesa.git] / src / mesa / main / drawtex.c
1 /*
2 * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "main/drawtex.h"
25 #include "main/state.h"
26 #include "main/imports.h"
27
28
29 #if FEATURE_OES_draw_texture
30
31
32 static void
33 draw_texture(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z,
34 GLfloat width, GLfloat height)
35 {
36 if (!ctx->Extensions.OES_draw_texture) {
37 _mesa_error(ctx, GL_INVALID_OPERATION,
38 "glDrawTex(unsupported)");
39 return;
40 }
41 if (width <= 0.0f || height <= 0.0f) {
42 _mesa_error(ctx, GL_INVALID_VALUE, "glDrawTex(width or height <= 0)");
43 return;
44 }
45
46 if (ctx->NewState)
47 _mesa_update_state(ctx);
48
49 ASSERT(ctx->Driver.DrawTex);
50 ctx->Driver.DrawTex(ctx, x, y, z, width, height);
51 }
52
53
54 void GLAPIENTRY
55 _mesa_DrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
56 {
57 GET_CURRENT_CONTEXT(ctx);
58 draw_texture(ctx, x, y, z, width, height);
59 }
60
61
62 void GLAPIENTRY
63 _mesa_DrawTexfv(const GLfloat *coords)
64 {
65 GET_CURRENT_CONTEXT(ctx);
66 draw_texture(ctx, coords[0], coords[1], coords[2], coords[3], coords[4]);
67 }
68
69
70 void GLAPIENTRY
71 _mesa_DrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
72 {
73 GET_CURRENT_CONTEXT(ctx);
74 draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
75 (GLfloat) width, (GLfloat) height);
76 }
77
78
79 void GLAPIENTRY
80 _mesa_DrawTexiv(const GLint *coords)
81 {
82 GET_CURRENT_CONTEXT(ctx);
83 draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
84 (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
85 }
86
87
88 void GLAPIENTRY
89 _mesa_DrawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
90 {
91 GET_CURRENT_CONTEXT(ctx);
92 draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
93 (GLfloat) width, (GLfloat) height);
94 }
95
96
97 void GLAPIENTRY
98 _mesa_DrawTexsv(const GLshort *coords)
99 {
100 GET_CURRENT_CONTEXT(ctx);
101 draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
102 (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
103 }
104
105
106 void GLAPIENTRY
107 _mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
108 {
109 GET_CURRENT_CONTEXT(ctx);
110 draw_texture(ctx,
111 (GLfloat) x / 65536.0f,
112 (GLfloat) y / 65536.0f,
113 (GLfloat) z / 65536.0f,
114 (GLfloat) width / 65536.0f,
115 (GLfloat) height / 65536.0f);
116 }
117
118
119 void GLAPIENTRY
120 _mesa_DrawTexxv(const GLfixed *coords)
121 {
122 GET_CURRENT_CONTEXT(ctx);
123 draw_texture(ctx,
124 (GLfloat) coords[0] / 65536.0f,
125 (GLfloat) coords[1] / 65536.0f,
126 (GLfloat) coords[2] / 65536.0f,
127 (GLfloat) coords[3] / 65536.0f,
128 (GLfloat) coords[4] / 65536.0f);
129 }
130
131 #endif /* FEATURE_OES_draw_texture */