Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* |
2 | * Mesa 3-D graphics library |
||
3 | * |
||
4 | * Copyright (C) 2010 LunarG Inc. |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the "Software"), |
||
8 | * to deal in the Software without restriction, including without limitation |
||
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
10 | * and/or sell copies of the Software, and to permit persons to whom the |
||
11 | * Software is furnished to do so, subject to the following conditions: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice shall be included |
||
14 | * in all copies or substantial portions of the Software. |
||
15 | * |
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
22 | * DEALINGS IN THE SOFTWARE. |
||
23 | * |
||
24 | * Authors: |
||
25 | * Chia-I Wu |
||
26 | */ |
||
27 | |||
28 | #include "main/texobj.h" |
||
29 | #include "main/teximage.h" |
||
30 | #include "util/u_inlines.h" |
||
31 | #include "util/u_format.h" |
||
32 | #include "st_cb_eglimage.h" |
||
33 | #include "st_cb_fbo.h" |
||
34 | #include "st_context.h" |
||
35 | #include "st_texture.h" |
||
36 | #include "st_format.h" |
||
37 | #include "st_manager.h" |
||
38 | |||
39 | /** |
||
40 | * Return the base format just like _mesa_base_fbo_format does. |
||
41 | */ |
||
42 | static GLenum |
||
43 | st_pipe_format_to_base_format(enum pipe_format format) |
||
44 | { |
||
45 | GLenum base_format; |
||
46 | |||
47 | if (util_format_is_depth_or_stencil(format)) { |
||
48 | if (util_format_is_depth_and_stencil(format)) { |
||
49 | base_format = GL_DEPTH_STENCIL; |
||
50 | } |
||
51 | else { |
||
52 | if (format == PIPE_FORMAT_S8_UINT) |
||
53 | base_format = GL_STENCIL_INDEX; |
||
54 | else |
||
55 | base_format = GL_DEPTH_COMPONENT; |
||
56 | } |
||
57 | } |
||
58 | else { |
||
59 | /* is this enough? */ |
||
60 | if (util_format_has_alpha(format)) |
||
61 | base_format = GL_RGBA; |
||
62 | else |
||
63 | base_format = GL_RGB; |
||
64 | } |
||
65 | |||
66 | return base_format; |
||
67 | } |
||
68 | |||
69 | static void |
||
70 | st_egl_image_target_renderbuffer_storage(struct gl_context *ctx, |
||
71 | struct gl_renderbuffer *rb, |
||
72 | GLeglImageOES image_handle) |
||
73 | { |
||
74 | struct st_context *st = st_context(ctx); |
||
75 | struct st_renderbuffer *strb = st_renderbuffer(rb); |
||
76 | struct pipe_surface *ps; |
||
77 | |||
78 | ps = st_manager_get_egl_image_surface(st, (void *) image_handle); |
||
79 | if (ps) { |
||
80 | strb->Base.Width = ps->width; |
||
81 | strb->Base.Height = ps->height; |
||
82 | strb->Base.Format = st_pipe_format_to_mesa_format(ps->format); |
||
83 | strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format); |
||
84 | strb->Base.InternalFormat = strb->Base._BaseFormat; |
||
85 | |||
86 | pipe_surface_reference(&strb->surface, ps); |
||
87 | pipe_resource_reference(&strb->texture, ps->texture); |
||
88 | |||
89 | pipe_surface_reference(&ps, NULL); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | static void |
||
94 | st_bind_surface(struct gl_context *ctx, GLenum target, |
||
95 | struct gl_texture_object *texObj, |
||
96 | struct gl_texture_image *texImage, |
||
97 | struct pipe_surface *ps) |
||
98 | { |
||
99 | struct st_texture_object *stObj; |
||
100 | struct st_texture_image *stImage; |
||
101 | GLenum internalFormat; |
||
102 | gl_format texFormat; |
||
103 | |||
104 | /* map pipe format to base format */ |
||
105 | if (util_format_get_component_bits(ps->format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0) |
||
106 | internalFormat = GL_RGBA; |
||
107 | else |
||
108 | internalFormat = GL_RGB; |
||
109 | |||
110 | stObj = st_texture_object(texObj); |
||
111 | stImage = st_texture_image(texImage); |
||
112 | |||
113 | /* switch to surface based */ |
||
114 | if (!stObj->surface_based) { |
||
115 | _mesa_clear_texture_object(ctx, texObj); |
||
116 | stObj->surface_based = GL_TRUE; |
||
117 | } |
||
118 | |||
119 | texFormat = st_pipe_format_to_mesa_format(ps->format); |
||
120 | |||
121 | _mesa_init_teximage_fields(ctx, texImage, |
||
122 | ps->width, ps->height, 1, 0, internalFormat, |
||
123 | texFormat); |
||
124 | |||
125 | /* FIXME create a non-default sampler view from the pipe_surface? */ |
||
126 | pipe_resource_reference(&stObj->pt, ps->texture); |
||
127 | pipe_sampler_view_reference(&stObj->sampler_view, NULL); |
||
128 | pipe_resource_reference(&stImage->pt, stObj->pt); |
||
129 | |||
130 | stObj->width0 = ps->width; |
||
131 | stObj->height0 = ps->height; |
||
132 | stObj->depth0 = 1; |
||
133 | stObj->surface_format = ps->format; |
||
134 | |||
135 | _mesa_dirty_texobj(ctx, texObj, GL_TRUE); |
||
136 | } |
||
137 | |||
138 | static void |
||
139 | st_egl_image_target_texture_2d(struct gl_context *ctx, GLenum target, |
||
140 | struct gl_texture_object *texObj, |
||
141 | struct gl_texture_image *texImage, |
||
142 | GLeglImageOES image_handle) |
||
143 | { |
||
144 | struct st_context *st = st_context(ctx); |
||
145 | struct pipe_surface *ps; |
||
146 | |||
147 | ps = st_manager_get_egl_image_surface(st, (void *) image_handle); |
||
148 | if (ps) { |
||
149 | st_bind_surface(ctx, target, texObj, texImage, ps); |
||
150 | pipe_surface_reference(&ps, NULL); |
||
151 | } |
||
152 | } |
||
153 | |||
154 | void |
||
155 | st_init_eglimage_functions(struct dd_function_table *functions) |
||
156 | { |
||
157 | functions->EGLImageTargetTexture2D = st_egl_image_target_texture_2d; |
||
158 | functions->EGLImageTargetRenderbufferStorage = st_egl_image_target_renderbuffer_storage; |
||
159 | } |