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/errors.h"
25 #include "main/drawtex.h"
26 #include "main/state.h"
27 
28 #include "main/mtypes.h"
29 
30 
31 static void
draw_texture(struct gl_context * ctx,GLfloat x,GLfloat y,GLfloat z,GLfloat width,GLfloat height)32 draw_texture(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
33              GLfloat width, GLfloat height)
34 {
35    if (!ctx->Extensions.OES_draw_texture) {
36       _mesa_error(ctx, GL_INVALID_OPERATION,
37                   "glDrawTex(unsupported)");
38       return;
39    }
40    if (width <= 0.0f || height <= 0.0f) {
41       _mesa_error(ctx, GL_INVALID_VALUE, "glDrawTex(width or height <= 0)");
42       return;
43    }
44 
45    _mesa_set_vp_override(ctx, GL_TRUE);
46 
47    if (ctx->NewState)
48       _mesa_update_state(ctx);
49 
50    assert(ctx->Driver.DrawTex);
51    ctx->Driver.DrawTex(ctx, x, y, z, width, height);
52 
53    _mesa_set_vp_override(ctx, GL_FALSE);
54 }
55 
56 
57 void GLAPIENTRY
_mesa_DrawTexfOES(GLfloat x,GLfloat y,GLfloat z,GLfloat width,GLfloat height)58 _mesa_DrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
59 {
60    GET_CURRENT_CONTEXT(ctx);
61    draw_texture(ctx, x, y, z, width, height);
62 }
63 
64 
65 void GLAPIENTRY
_mesa_DrawTexfvOES(const GLfloat * coords)66 _mesa_DrawTexfvOES(const GLfloat *coords)
67 {
68    GET_CURRENT_CONTEXT(ctx);
69    draw_texture(ctx, coords[0], coords[1], coords[2], coords[3], coords[4]);
70 }
71 
72 
73 void GLAPIENTRY
_mesa_DrawTexiOES(GLint x,GLint y,GLint z,GLint width,GLint height)74 _mesa_DrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
75 {
76    GET_CURRENT_CONTEXT(ctx);
77    draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
78                 (GLfloat) width, (GLfloat) height);
79 }
80 
81 
82 void GLAPIENTRY
_mesa_DrawTexivOES(const GLint * coords)83 _mesa_DrawTexivOES(const GLint *coords)
84 {
85    GET_CURRENT_CONTEXT(ctx);
86    draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
87                 (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
88 }
89 
90 
91 void GLAPIENTRY
_mesa_DrawTexsOES(GLshort x,GLshort y,GLshort z,GLshort width,GLshort height)92 _mesa_DrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
93 {
94    GET_CURRENT_CONTEXT(ctx);
95    draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
96                 (GLfloat) width, (GLfloat) height);
97 }
98 
99 
100 void GLAPIENTRY
_mesa_DrawTexsvOES(const GLshort * coords)101 _mesa_DrawTexsvOES(const GLshort *coords)
102 {
103    GET_CURRENT_CONTEXT(ctx);
104    draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
105                 (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
106 }
107 
108 
109 void GLAPIENTRY
_mesa_DrawTexx(GLfixed x,GLfixed y,GLfixed z,GLfixed width,GLfixed height)110 _mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
111 {
112    GET_CURRENT_CONTEXT(ctx);
113    draw_texture(ctx,
114                 (GLfloat) x / 65536.0f,
115                 (GLfloat) y / 65536.0f,
116                 (GLfloat) z / 65536.0f,
117                 (GLfloat) width / 65536.0f,
118                 (GLfloat) height / 65536.0f);
119 }
120 
121 
122 void GLAPIENTRY
_mesa_DrawTexxv(const GLfixed * coords)123 _mesa_DrawTexxv(const GLfixed *coords)
124 {
125    GET_CURRENT_CONTEXT(ctx);
126    draw_texture(ctx,
127                 (GLfloat) coords[0] / 65536.0f,
128                 (GLfloat) coords[1] / 65536.0f,
129                 (GLfloat) coords[2] / 65536.0f,
130                 (GLfloat) coords[3] / 65536.0f,
131                 (GLfloat) coords[4] / 65536.0f);
132 }
133