1848b8605Smrg/*
2848b8605Smrg * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
3848b8605Smrg *
4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5848b8605Smrg * copy of this software and associated documentation files (the "Software"),
6848b8605Smrg * to deal in the Software without restriction, including without limitation
7848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
9848b8605Smrg * Software is furnished to do so, subject to the following conditions:
10848b8605Smrg *
11848b8605Smrg * The above copyright notice and this permission notice (including the next
12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
13848b8605Smrg * Software.
14848b8605Smrg *
15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21848b8605Smrg * DEALINGS IN THE SOFTWARE.
22848b8605Smrg */
23848b8605Smrg
24b8e80941Smrg#include "main/errors.h"
25848b8605Smrg#include "main/drawtex.h"
26848b8605Smrg#include "main/state.h"
27848b8605Smrg#include "main/imports.h"
28848b8605Smrg#include "main/mtypes.h"
29848b8605Smrg
30848b8605Smrg
31848b8605Smrgstatic void
32848b8605Smrgdraw_texture(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
33848b8605Smrg             GLfloat width, GLfloat height)
34848b8605Smrg{
35848b8605Smrg   if (!ctx->Extensions.OES_draw_texture) {
36848b8605Smrg      _mesa_error(ctx, GL_INVALID_OPERATION,
37848b8605Smrg                  "glDrawTex(unsupported)");
38848b8605Smrg      return;
39848b8605Smrg   }
40848b8605Smrg   if (width <= 0.0f || height <= 0.0f) {
41848b8605Smrg      _mesa_error(ctx, GL_INVALID_VALUE, "glDrawTex(width or height <= 0)");
42848b8605Smrg      return;
43848b8605Smrg   }
44848b8605Smrg
45848b8605Smrg   _mesa_set_vp_override(ctx, GL_TRUE);
46848b8605Smrg
47848b8605Smrg   if (ctx->NewState)
48848b8605Smrg      _mesa_update_state(ctx);
49848b8605Smrg
50b8e80941Smrg   assert(ctx->Driver.DrawTex);
51848b8605Smrg   ctx->Driver.DrawTex(ctx, x, y, z, width, height);
52848b8605Smrg
53848b8605Smrg   _mesa_set_vp_override(ctx, GL_FALSE);
54848b8605Smrg}
55848b8605Smrg
56848b8605Smrg
57848b8605Smrgvoid GLAPIENTRY
58848b8605Smrg_mesa_DrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
59848b8605Smrg{
60848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
61848b8605Smrg   draw_texture(ctx, x, y, z, width, height);
62848b8605Smrg}
63848b8605Smrg
64848b8605Smrg
65848b8605Smrgvoid GLAPIENTRY
66848b8605Smrg_mesa_DrawTexfvOES(const GLfloat *coords)
67848b8605Smrg{
68848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
69848b8605Smrg   draw_texture(ctx, coords[0], coords[1], coords[2], coords[3], coords[4]);
70848b8605Smrg}
71848b8605Smrg
72848b8605Smrg
73848b8605Smrgvoid GLAPIENTRY
74848b8605Smrg_mesa_DrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
75848b8605Smrg{
76848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
77848b8605Smrg   draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
78848b8605Smrg                (GLfloat) width, (GLfloat) height);
79848b8605Smrg}
80848b8605Smrg
81848b8605Smrg
82848b8605Smrgvoid GLAPIENTRY
83848b8605Smrg_mesa_DrawTexivOES(const GLint *coords)
84848b8605Smrg{
85848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
86848b8605Smrg   draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
87848b8605Smrg                (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
88848b8605Smrg}
89848b8605Smrg
90848b8605Smrg
91848b8605Smrgvoid GLAPIENTRY
92848b8605Smrg_mesa_DrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
93848b8605Smrg{
94848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
95848b8605Smrg   draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
96848b8605Smrg                (GLfloat) width, (GLfloat) height);
97848b8605Smrg}
98848b8605Smrg
99848b8605Smrg
100848b8605Smrgvoid GLAPIENTRY
101848b8605Smrg_mesa_DrawTexsvOES(const GLshort *coords)
102848b8605Smrg{
103848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
104848b8605Smrg   draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
105848b8605Smrg                (GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
106848b8605Smrg}
107848b8605Smrg
108848b8605Smrg
109848b8605Smrgvoid GLAPIENTRY
110848b8605Smrg_mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
111848b8605Smrg{
112848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
113848b8605Smrg   draw_texture(ctx,
114848b8605Smrg                (GLfloat) x / 65536.0f,
115848b8605Smrg                (GLfloat) y / 65536.0f,
116848b8605Smrg                (GLfloat) z / 65536.0f,
117848b8605Smrg                (GLfloat) width / 65536.0f,
118848b8605Smrg                (GLfloat) height / 65536.0f);
119848b8605Smrg}
120848b8605Smrg
121848b8605Smrg
122848b8605Smrgvoid GLAPIENTRY
123848b8605Smrg_mesa_DrawTexxv(const GLfixed *coords)
124848b8605Smrg{
125848b8605Smrg   GET_CURRENT_CONTEXT(ctx);
126848b8605Smrg   draw_texture(ctx,
127848b8605Smrg                (GLfloat) coords[0] / 65536.0f,
128848b8605Smrg                (GLfloat) coords[1] / 65536.0f,
129848b8605Smrg                (GLfloat) coords[2] / 65536.0f,
130848b8605Smrg                (GLfloat) coords[3] / 65536.0f,
131848b8605Smrg                (GLfloat) coords[4] / 65536.0f);
132848b8605Smrg}
133