Commit 34064756 authored by Chia-I Wu's avatar Chia-I Wu Committed by Brian Paul

mesa/es: Add support for GL_OES_draw_texture.

Signed-off-by: Chia-I Wu's avatarChia-I Wu <olvaffe@gmail.com>
parent bfa66bd6
......@@ -412,6 +412,8 @@ checkdependentparam pname GL_TEXTURE_WRAP_T params GLES1.1:GL_MIRRORED_REPEAT_OE
dependentvector params 1 pname GL_TEXTURE_MAX_ANISOTROPY_EXT
# OES_texture_3D
checkdependentparam pname GL_TEXTURE_WRAP_R_OES params GLES2.0:GL_CLAMP_TO_EDGE GLES2.0:GL_REPEAT GLES2.0:GL_MIRRORED_REPEAT
# OES_draw_texture - not in gl2ext.h
dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
category GLES1.1 GLES2.0
name TexParameteri
......@@ -457,6 +459,8 @@ checkdependentparam pname GL_TEXTURE_WRAP_T params GLES1.1:GL_MIRRORED_REPEAT_OE
dependentvector params 1 pname GL_TEXTURE_MAX_ANISOTROPY_EXT
# OES_texture_3D
checkdependentparam pname GL_TEXTURE_WRAP_R_OES params GLES2.0:GL_CLAMP_TO_EDGE GLES2.0:GL_REPEAT GLES2.0:GL_MIRRORED_REPEAT
# OES_draw_texture - not in gl2ext.h
dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
category GLES1.1 GLES2.0
name TexParameterx
......@@ -498,6 +502,8 @@ checkdependentparam pname GL_TEXTURE_MAG_FILTER params GL_NEAREST GL_LINEAR
checkdependentparam pname GL_GENERATE_MIPMAP params GL_TRUE GL_FALSE
convertalias TexParameterfv
convertparams GLfloat params
# OES_draw_texture
dependentvector params 4 pname GL_TEXTURE_CROP_RECT_OES
# OES_texture_cube_map
checkparam target GL_TEXTURE_CUBE_MAP_OES
# OES_texture_mirrored_repeat
......@@ -1352,6 +1358,8 @@ param pname GLenum
param params GLfloat *
dependentvector params 1 pname GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXTURE_MIN_FILTER GL_TEXTURE_MAG_FILTER GLES1.1:GL_GENERATE_MIPMAP
props get
# OES_draw_texture - not in gl2ext.h
dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
# OES_texture_cube_map
checkparam target GLES1.1:GL_TEXTURE_CUBE_MAP_OES
category GLES1.1 GLES2.0
......@@ -1366,6 +1374,8 @@ dependentvector params 1 pname GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXTURE_MI
props get
# OES_texture_cube_map
checkparam target GLES1.1:GL_TEXTURE_CUBE_MAP_OES
# OES_draw_texture - not in gl2ext.h
dependentvector params 4 pname GLES1.1:GL_TEXTURE_CROP_RECT_OES
# OES_texture_3D
checkparam target GLES2.0:GL_TEXTURE_3D_OES
category GLES1.1 GLES2.0
......@@ -1383,6 +1393,8 @@ dependentnovalueconvert params pname GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXT
props get
# OES_texture_cube_map
checkparam target GL_TEXTURE_CUBE_MAP_OES
# OES_draw_texture
dependentvector params 4 pname GL_TEXTURE_CROP_RECT_OES
category GLES1.1 GLES1.1:OES_fixed_point
# GLES1.1 and GLES2.0 have different capabilities
......@@ -2867,6 +2879,71 @@ vector exponent 16
props get
category GLES1.1:OES_query_matrix
# OES_draw_texture
name DrawTexf
return void
param x GLfloat
param y GLfloat
param z GLfloat
param w GLfloat
param h GLfloat
category GLES1.1:OES_draw_texture
name DrawTexi
return void
param x GLint
param y GLint
param z GLint
param w GLint
param h GLint
category GLES1.1:OES_draw_texture
name DrawTexs
return void
param x GLshort
param y GLshort
param z GLshort
param w GLshort
param h GLshort
category GLES1.1:OES_draw_texture
name DrawTexx
return void
param x GLfixed
param y GLfixed
param z GLfixed
param w GLfixed
param h GLfixed
convertalias DrawTexf
convertparams GLfloat x y z w h
category GLES1.1:OES_draw_texture
name DrawTexfv
return void
param coords const GLfloat *
vector coords 5
category GLES1.1:OES_draw_texture
name DrawTexiv
return void
param coords const GLint *
vector coords 5
category GLES1.1:OES_draw_texture
name DrawTexsv
return void
param coords const GLshort *
vector coords 5
category GLES1.1:OES_draw_texture
name DrawTexxv
return void
param coords const GLfixed *
vector coords 5
convertalias DrawTexfv
convertparams GLfloat coords
category GLES1.1:OES_draw_texture
# We don't support OES_get_program_binary yet either
#name GetProgramBinary
#return void
......
/*
* Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "drawtex.h"
#include "main/state.h"
#include "main/imports.h"
#include "glapi/dispatch.h"
#if FEATURE_OES_draw_texture
static void
draw_texture(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z,
GLfloat width, GLfloat height)
{
if (!ctx->Extensions.OES_draw_texture) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glDrawTex(unsupported)");
return;
}
if (width <= 0.0f || height <= 0.0f) {
_mesa_error(ctx, GL_INVALID_VALUE, "glDrawTex(width or height <= 0)");
return;
}
if (ctx->NewState)
_mesa_update_state(ctx);
ASSERT(ctx->Driver.DrawTex);
ctx->Driver.DrawTex(ctx, x, y, z, width, height);
}
void GLAPIENTRY
_mesa_DrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx, x, y, z, width, height);
}
void GLAPIENTRY
_mesa_DrawTexfv(const GLfloat *coords)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx, coords[0], coords[1], coords[2], coords[3], coords[4]);
}
void GLAPIENTRY
_mesa_DrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
(GLfloat) width, (GLfloat) height);
}
void GLAPIENTRY
_mesa_DrawTexiv(const GLint *coords)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
(GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
}
void GLAPIENTRY
_mesa_DrawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx, (GLfloat) x, (GLfloat) y, (GLfloat) z,
(GLfloat) width, (GLfloat) height);
}
void GLAPIENTRY
_mesa_DrawTexsv(const GLshort *coords)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx, (GLfloat) coords[0], (GLfloat) coords[1],
(GLfloat) coords[2], (GLfloat) coords[3], (GLfloat) coords[4]);
}
void GLAPIENTRY
_mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx,
(GLfloat) x / 65536.0f,
(GLfloat) y / 65536.0f,
(GLfloat) z / 65536.0f,
(GLfloat) width / 65536.0f,
(GLfloat) height / 65536.0f);
}
void GLAPIENTRY
_mesa_DrawTexxv(const GLfixed *coords)
{
GET_CURRENT_CONTEXT(ctx);
draw_texture(ctx,
(GLfloat) coords[0] / 65536.0f,
(GLfloat) coords[1] / 65536.0f,
(GLfloat) coords[2] / 65536.0f,
(GLfloat) coords[3] / 65536.0f,
(GLfloat) coords[4] / 65536.0f);
}
void
_mesa_init_drawtex_dispatch(struct _glapi_table *disp)
{
SET_DrawTexfOES(disp, _mesa_DrawTexf);
SET_DrawTexfvOES(disp, _mesa_DrawTexfv);
SET_DrawTexiOES(disp, _mesa_DrawTexi);
SET_DrawTexivOES(disp, _mesa_DrawTexiv);
SET_DrawTexsOES(disp, _mesa_DrawTexs);
SET_DrawTexsvOES(disp, _mesa_DrawTexsv);
SET_DrawTexxOES(disp, _mesa_DrawTexx);
SET_DrawTexxvOES(disp, _mesa_DrawTexxv);
}
#endif /* FEATURE_OES_draw_texture */
/*
* Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAWTEX_H
#define DRAWTEX_H
#include "main/mtypes.h"
#if FEATURE_OES_draw_texture
#define _MESA_INIT_DRAWTEX_FUNCTIONS(driver, impl) \
do { \
(driver)->DrawTex = impl ## DrawTex; \
} while (0)
extern void GLAPIENTRY
_mesa_DrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
extern void GLAPIENTRY
_mesa_DrawTexfv(const GLfloat *coords);
extern void GLAPIENTRY
_mesa_DrawTexi(GLint x, GLint y, GLint z, GLint width, GLint height);
extern void GLAPIENTRY
_mesa_DrawTexiv(const GLint *coords);
extern void GLAPIENTRY
_mesa_DrawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height);
extern void GLAPIENTRY
_mesa_DrawTexsv(const GLshort *coords);
extern void GLAPIENTRY
_mesa_DrawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height);
extern void GLAPIENTRY
_mesa_DrawTexxv(const GLfixed *coords);
extern void
_mesa_init_drawtex_dispatch(struct _glapi_table *disp);
#else /* FEATURE_OES_draw_texture */
#define _MESA_INIT_DRAWTEX_FUNCTIONS(driver, impl) do { } while (0)
static INLINE void
_mesa_init_drawtex_dispatch(struct _glapi_table *disp)
{
}
#endif /* FEATURE_OES_draw_texture */
#endif /* DRAWTEX_H */
......@@ -103,6 +103,7 @@
#define FEATURE_NV_vertex_program 0
#define FEATURE_OES_framebuffer_object 1
#define FEATURE_OES_draw_texture 1
#define FEATURE_OES_mapbuffer 1
#define FEATURE_extra_context_init 1
......
......@@ -103,6 +103,7 @@
#define FEATURE_NV_vertex_program 0
#define FEATURE_OES_framebuffer_object 1
#define FEATURE_OES_draw_texture 0
#define FEATURE_OES_mapbuffer 1
#define FEATURE_extra_context_init 1
......
......@@ -100,6 +100,11 @@ make_extension_string(const GLcontext *ctx, char *str)
/* 1.1 deprecated extensions */
len += append_extension(&str, "GL_OES_query_matrix");
#if FEATURE_OES_draw_texture
if (ctx->Extensions.OES_draw_texture)
len += append_extension(&str, "GL_OES_draw_texture");
#endif
if (ctx->Extensions.EXT_blend_equation_separate)
len += append_extension(&str, "GL_OES_blend_equation_separate");
if (ctx->Extensions.EXT_blend_func_separate)
......
......@@ -4,6 +4,7 @@ include $(MESA)/sources.mak
LOCAL_ES1_SOURCES := \
main/api_exec_es1.c \
main/drawtex.c \
main/get_es1.c \
main/specials_es1.c \
main/drawtex.c \
......@@ -14,7 +15,8 @@ LOCAL_ES1_SOURCES := \
glapi/glapi-es1/main/enums.c
LOCAL_ES1_GALLIUM_SOURCES := \
$(LOCAL_ES1_SOURCES)
$(LOCAL_ES1_SOURCES) \
state_tracker/st_cb_drawtex.c
# always use local version of GLAPI_ASM_SOURCES
LOCAL_ES1_API_ASM := $(addprefix glapi/glapi-es1/, $(GLAPI_ASM_SOURCES))
......
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
**************************************************************************/
/**
* Implementation of glDrawTex() for GL_OES_draw_tex
*/
#include "main/imports.h"
#include "main/image.h"
#include "main/bufferobj.h"
#include "main/drawtex.h"
#include "main/macros.h"
#include "main/state.h"
#include "main/texformat.h"
#include "shader/program.h"
#include "shader/prog_parameter.h"
#include "shader/prog_print.h"
#include "st_context.h"
#include "st_atom.h"
#include "st_atom_constbuf.h"
#include "st_draw.h"
#include "st_cb_drawtex.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_tile.h"
#include "util/u_draw_quad.h"
#include "util/u_simple_shaders.h"
#include "cso_cache/cso_context.h"
struct cached_shader
{
//struct pipe_shader_state shader;
void *handle;
uint num_attribs;
uint semantic_names[2 + MAX_TEXTURE_UNITS];
uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
};
#define MAX_SHADERS (2 * MAX_TEXTURE_UNITS)
/**
* Simple linear list cache.
* Most of the time there'll only be one cached shader.
*/
static struct cached_shader CachedShaders[MAX_SHADERS];
static GLuint NumCachedShaders = 0;
#if FEATURE_OES_draw_texture
static void *
lookup_shader(struct pipe_context *pipe,
uint num_attribs,
const uint *semantic_names,
const uint *semantic_indexes)
{
GLuint i, j;
/* look for existing shader with same attributes */
for (i = 0; i < NumCachedShaders; i++) {
if (CachedShaders[i].num_attribs == num_attribs) {
GLboolean match = GL_TRUE;
for (j = 0; j < num_attribs; j++) {
if (semantic_names[j] != CachedShaders[i].semantic_names[j] ||
semantic_indexes[j] != CachedShaders[i].semantic_indexes[j]) {
match = GL_FALSE;
break;
}
}
if (match)
return CachedShaders[i].handle;
}
}
/* not found - create new one now */
if (NumCachedShaders >= MAX_SHADERS) {
return NULL;
}
CachedShaders[i].num_attribs = num_attribs;
for (j = 0; j < num_attribs; j++) {
CachedShaders[i].semantic_names[j] = semantic_names[j];
CachedShaders[i].semantic_indexes[j] = semantic_indexes[j];
}
CachedShaders[i].handle =
util_make_vertex_passthrough_shader(pipe,
num_attribs,
semantic_names,
semantic_indexes);
NumCachedShaders++;
return CachedShaders[i].handle;
}
static void
st_DrawTex(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z,
GLfloat width, GLfloat height)
{
struct st_context *st = ctx->st;
struct pipe_context *pipe = st->pipe;
struct cso_context *cso = ctx->st->cso_context;
struct pipe_buffer *vbuffer;
GLuint i, numTexCoords, numAttribs;
GLboolean emitColor;
uint semantic_names[2 + MAX_TEXTURE_UNITS];
uint semantic_indexes[2 + MAX_TEXTURE_UNITS];
GLbitfield inputs = VERT_BIT_POS;
/* determine if we need vertex color */
if (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL0)
emitColor = GL_TRUE;
else
emitColor = GL_FALSE;
/* determine how many enabled sets of texcoords */
numTexCoords = 0;
for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
inputs |= VERT_BIT_TEX(i);
numTexCoords++;
}
}
/* total number of attributes per vertex */
numAttribs = 1 + emitColor + numTexCoords;
/* create the vertex buffer */
vbuffer = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
numAttribs * 4 * 4 * sizeof(GLfloat));
/* load vertex buffer */
{
#define SET_ATTRIB(VERT, ATTR, X, Y, Z, W) \
do { \
GLuint k = (((VERT) * numAttribs + (ATTR)) * 4); \
assert(k < 4 * 4 * numAttribs); \
vbuf[k + 0] = X; \
vbuf[k + 1] = Y; \
vbuf[k + 2] = Z; \
vbuf[k + 3] = W; \
} while (0)
const GLfloat x0 = x, y0 = y, x1 = x + width, y1 = y + height;
GLfloat *vbuf = (GLfloat *) pipe_buffer_map(pipe->screen, vbuffer,
PIPE_BUFFER_USAGE_CPU_WRITE);
GLuint attr;
z = CLAMP(z, 0.0f, 1.0f);
/* positions (in clip coords) */
{
const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
const GLfloat fb_width = (GLfloat)fb->Width;
const GLfloat fb_height = (GLfloat)fb->Height;
const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0);
const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0);
const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0);
const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0);
SET_ATTRIB(0, 0, clip_x0, clip_y0, z, 1.0f); /* lower left */
SET_ATTRIB(1, 0, clip_x1, clip_y0, z, 1.0f); /* lower right */
SET_ATTRIB(2, 0, clip_x1, clip_y1, z, 1.0f); /* upper right */
SET_ATTRIB(3, 0, clip_x0, clip_y1, z, 1.0f); /* upper left */
semantic_names[0] = TGSI_SEMANTIC_POSITION;
semantic_indexes[0] = 0;
}
/* colors */
if (emitColor) {
const GLfloat *c = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
SET_ATTRIB(0, 1, c[0], c[1], c[2], c[3]);
SET_ATTRIB(1, 1, c[0], c[1], c[2], c[3]);
SET_ATTRIB(2, 1, c[0], c[1], c[2], c[3]);
SET_ATTRIB(3, 1, c[0], c[1], c[2], c[3]);
semantic_names[1] = TGSI_SEMANTIC_COLOR;
semantic_indexes[1] = 0;
attr = 2;
}
else {
attr = 1;
}
/* texcoords */
for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
if (ctx->Texture.Unit[i]._ReallyEnabled & TEXTURE_2D_BIT) {
struct gl_texture_object *obj = ctx->Texture.Unit[i]._Current;
struct gl_texture_image *img = obj->Image[0][obj->BaseLevel];
const GLfloat wt = (GLfloat) img->Width;
const GLfloat ht = (GLfloat) img->Height;
const GLfloat s0 = obj->CropRect[0] / wt;
const GLfloat t0 = obj->CropRect[1] / ht;
const GLfloat s1 = (obj->CropRect[0] + obj->CropRect[2]) / wt;
const GLfloat t1 = (obj->CropRect[1] + obj->CropRect[3]) / ht;
/*printf("crop texcoords: %g, %g .. %g, %g\n", s0, t0, s1, t1);*/
SET_ATTRIB(0, attr, s0, t0, 0.0f, 1.0f); /* lower left */
SET_ATTRIB(1, attr, s1, t0, 0.0f, 1.0f); /* lower right */
SET_ATTRIB(2, attr, s1, t1, 0.0f, 1.0f); /* upper right */
SET_ATTRIB(3, attr, s0, t1, 0.0f, 1.0f); /* upper left */
semantic_names[attr] = TGSI_SEMANTIC_GENERIC;
semantic_indexes[attr] = 0;
attr++;
}
}
pipe_buffer_unmap(pipe->screen, vbuffer);
#undef SET_ATTRIB
}
cso_save_viewport(cso);
cso_save_vertex_shader(cso);
{
void *vs = lookup_shader(pipe, numAttribs,
semantic_names, semantic_indexes);
cso_set_vertex_shader_handle(cso, vs);
}
/* viewport state: viewport matching window dims */
{