2
* Mesa 3-D graphics library
5
* Copyright (C) 2010 LunarG Inc.
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
* and/or sell copies of the Software, and to permit persons to whom the
12
* Software is furnished to do so, subject to the following conditions:
14
* The above copyright notice and this permission notice shall be included
15
* in all copies or substantial portions of the Software.
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
* DEALINGS IN THE SOFTWARE.
26
* Chia-I Wu <olv@lunarg.com>
29
#include "main/texobj.h"
30
#include "main/texfetch.h"
31
#include "main/teximage.h"
32
#include "util/u_inlines.h"
33
#include "util/u_format.h"
34
#include "st_cb_eglimage.h"
35
#include "st_cb_fbo.h"
36
#include "st_context.h"
37
#include "st_texture.h"
38
#include "st_format.h"
39
#include "st_manager.h"
41
#if FEATURE_OES_EGL_image
44
* Return the base format just like _mesa_base_fbo_format does.
47
st_pipe_format_to_base_format(enum pipe_format format)
51
if (util_format_is_depth_or_stencil(format)) {
52
if (util_format_is_depth_and_stencil(format)) {
53
base_format = GL_DEPTH_STENCIL;
56
if (format == PIPE_FORMAT_S8_USCALED)
57
base_format = GL_STENCIL_INDEX;
59
base_format = GL_DEPTH_COMPONENT;
64
if (util_format_has_alpha(format))
65
base_format = GL_RGBA;
74
st_egl_image_target_renderbuffer_storage(GLcontext *ctx,
75
struct gl_renderbuffer *rb,
76
GLeglImageOES image_handle)
78
struct st_context *st = st_context(ctx);
79
struct st_renderbuffer *strb = st_renderbuffer(rb);
80
struct pipe_surface *ps;
83
usage = PIPE_BIND_RENDER_TARGET;
84
ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage);
86
strb->Base.Width = ps->width;
87
strb->Base.Height = ps->height;
88
strb->Base.Format = st_pipe_format_to_mesa_format(ps->format);
89
strb->Base.DataType = st_format_datatype(ps->format);
90
strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format);
91
strb->Base.InternalFormat = strb->Base._BaseFormat;
93
pipe_surface_reference(&strb->surface, ps);
94
pipe_resource_reference(&strb->texture, ps->texture);
96
pipe_surface_reference(&ps, NULL);
101
st_bind_surface(GLcontext *ctx, GLenum target,
102
struct gl_texture_object *texObj,
103
struct gl_texture_image *texImage,
104
struct pipe_surface *ps)
106
struct st_texture_object *stObj;
107
struct st_texture_image *stImage;
108
GLenum internalFormat;
110
/* map pipe format to base format */
111
if (util_format_get_component_bits(ps->format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
112
internalFormat = GL_RGBA;
114
internalFormat = GL_RGB;
116
stObj = st_texture_object(texObj);
117
stImage = st_texture_image(texImage);
119
/* switch to surface based */
120
if (!stObj->surface_based) {
121
_mesa_clear_texture_object(ctx, texObj);
122
stObj->surface_based = GL_TRUE;
125
_mesa_init_teximage_fields(ctx, target, texImage,
126
ps->width, ps->height, 1, 0, internalFormat);
127
texImage->TexFormat = st_pipe_format_to_mesa_format(ps->format);
128
_mesa_set_fetch_functions(texImage, 2);
130
/* FIXME create a non-default sampler view from the pipe_surface? */
131
pipe_resource_reference(&stObj->pt, ps->texture);
132
pipe_resource_reference(&stImage->pt, stObj->pt);
134
stObj->width0 = ps->width;
135
stObj->height0 = ps->height;
138
_mesa_dirty_texobj(ctx, texObj, GL_TRUE);
142
st_egl_image_target_texture_2d(GLcontext *ctx, GLenum target,
143
struct gl_texture_object *texObj,
144
struct gl_texture_image *texImage,
145
GLeglImageOES image_handle)
147
struct st_context *st = st_context(ctx);
148
struct pipe_surface *ps;
151
usage = PIPE_BIND_SAMPLER_VIEW;
152
ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage);
154
st_bind_surface(ctx, target, texObj, texImage, ps);
155
pipe_surface_reference(&ps, NULL);
160
st_init_eglimage_functions(struct dd_function_table *functions)
162
functions->EGLImageTargetTexture2D = st_egl_image_target_texture_2d;
163
functions->EGLImageTargetRenderbufferStorage = st_egl_image_target_renderbuffer_storage;
166
#endif /* FEATURE_OES_EGL_image */