20
20
* Lesser General Public License for more details.
22
22
* You should have received a copy of the GNU Lesser General Public
23
* License along with this library; if not, write to the
24
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25
* Boston, MA 02111-1307, USA.
23
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
121
130
clutter_glx_texture_pixmap, \
122
131
CLUTTER_X11_TYPE_TEXTURE_PIXMAP);
125
texture_bind (ClutterGLXTexturePixmap *tex)
134
bind_texture (ClutterGLXTexturePixmap *tex)
130
cogl_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE(tex));
138
CoglHandle cogl_tex =
139
clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (tex));
132
141
if (!cogl_texture_get_gl_texture (cogl_tex, &handle, &target))
142
g_warning ("Failed to pluck out GL handle from cogl texture to bind");
135
/* FIXME: fire off an error here? */
136
144
glBindTexture (target, handle);
148
release_tex_image (ClutterGLXTexturePixmap *texture)
150
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
153
if (!priv->glx_pixmap || !priv->bound)
156
dpy = clutter_x11_get_default_display ();
158
bind_texture (texture);
160
clutter_x11_trap_x_errors ();
162
(_gl_release_tex_image) (dpy,
168
if (clutter_x11_untrap_x_errors ())
169
CLUTTER_NOTE (TEXTURE, "Failed to release?");
171
CLUTTER_NOTE (TEXTURE, "Destroyed pxm: %li", priv->glx_pixmap);
142
177
on_glx_texture_pixmap_pre_paint (ClutterGLXTexturePixmap *texture,
143
178
gpointer user_data)
145
if (texture->priv->mipmap_generate_queued)
180
ClutterGLXTexturePixmapPrivate *priv = texture->priv;
181
gboolean tex_bound = FALSE;
182
Display *dpy = clutter_x11_get_default_display();
184
if (priv->bind_tex_image_queued)
186
CLUTTER_NOTE (TEXTURE, "Really updating via GLX");
188
bind_texture (CLUTTER_GLX_TEXTURE_PIXMAP (texture));
191
clutter_x11_trap_x_errors ();
193
(_gl_bind_tex_image) (dpy,
200
/* Note above fires X error for non name pixmaps - but
201
* things still seem to work - i.e pixmap updated
203
if (clutter_x11_untrap_x_errors ())
204
CLUTTER_NOTE (TEXTURE, "Update bind_tex_image failed");
208
if (clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
209
== CLUTTER_TEXTURE_QUALITY_HIGH)
211
priv->mipmap_generate_queued++;
214
priv->bind_tex_image_queued = FALSE;
217
if (_gl_generate_mipmap &&
219
priv->mipmap_generate_queued)
147
221
GLuint handle = 0;
148
222
GLenum target = 0;
150
224
cogl_tex = clutter_texture_get_cogl_texture
151
225
(CLUTTER_TEXTURE(texture));
153
texture_bind (texture);
227
bind_texture (texture);
155
230
cogl_texture_get_gl_texture (cogl_tex, &handle, &target);
157
232
_gl_generate_mipmap (target);
159
texture->priv->mipmap_generate_queued = 0;
234
priv->mipmap_generate_queued = FALSE;
162
236
/* Disable mipmaps if we can't support them */
163
237
if (clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
164
238
== CLUTTER_TEXTURE_QUALITY_HIGH
165
&& !texture->priv->can_mipmap)
239
&& !priv->can_mipmap)
167
241
CoglHandle material
168
242
= clutter_texture_get_cogl_material (CLUTTER_TEXTURE (texture));
198
272
clutter_x11_get_default_screen ());
200
274
/* Check for the texture from pixmap extension */
201
if (cogl_check_extension ("GLX_EXT_texture_from_pixmap", glx_extensions))
275
if (_cogl_check_extension ("GLX_EXT_texture_from_pixmap",
203
278
_gl_bind_tex_image =
204
279
(BindTexImage)cogl_get_proc_address ("glXBindTexImageEXT");
213
288
(GenerateMipmap)cogl_get_proc_address ("glGenerateMipmapEXT");
215
290
gl_extensions = (char *) glGetString (GL_EXTENSIONS);
216
_have_tex_rectangle = cogl_check_extension ("GL_ARB_texture_rectangle",
291
_have_tex_rectangle = _cogl_check_extension ("GL_ARB_texture_rectangle",
219
294
if ((rect_env = g_getenv ("CLUTTER_PIXMAP_TEXTURE_RECTANGLE")))
351
426
using_rectangle = TRUE;
353
428
glGenTextures (1, &tex);
354
glBindTexture (CGL_TEXTURE_RECTANGLE_ARB, tex);
355
glTexImage2D (CGL_TEXTURE_RECTANGLE_ARB, 0,
429
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
430
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0,
356
431
gl_format, width, height,
357
432
0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
359
handle = cogl_texture_new_from_foreign (tex, CGL_TEXTURE_RECTANGLE_ARB,
434
handle = cogl_texture_new_from_foreign (tex, GL_TEXTURE_RECTANGLE_ARB,
362
437
cogl_format | COGL_BGR_BIT |
429
503
if (!CLUTTER_ACTOR_IS_REALIZED (actor))
432
if (priv->glx_pixmap && priv->bound)
434
clutter_x11_trap_x_errors ();
436
(_gl_release_tex_image) (dpy,
440
XSync (clutter_x11_get_default_display(), FALSE);
441
clutter_x11_untrap_x_errors ();
506
release_tex_image (texture);
446
508
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
588
650
dpy = clutter_x11_get_default_display ();
590
if (priv->glx_pixmap &&
593
texture_bind (texture);
595
clutter_x11_trap_x_errors ();
597
(_gl_release_tex_image) (dpy,
601
XSync (clutter_x11_get_default_display(), FALSE);
603
if (clutter_x11_untrap_x_errors ())
604
CLUTTER_NOTE (TEXTURE, "Failed to release?");
606
CLUTTER_NOTE (TEXTURE, "Destroyed pxm: %li", priv->glx_pixmap);
652
release_tex_image (texture);
611
654
clutter_x11_trap_x_errors ();
612
655
if (priv->glx_pixmap)
738
781
pixmap_width, pixmap_height);
740
783
/* Get ready to queue initial mipmap generation */
741
if (_gl_generate_mipmap
743
&& clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
784
if (clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
744
785
== CLUTTER_TEXTURE_QUALITY_HIGH)
746
priv->mipmap_generate_queued++;
787
priv->mipmap_generate_queued = TRUE;
768
809
ClutterGLXTexturePixmap *texture_glx = CLUTTER_GLX_TEXTURE_PIXMAP (texture);
769
ClutterGLXTexturePixmapPrivate *priv = texture_glx->priv;
810
ClutterGLXTexturePixmapPrivate *priv = texture_glx->priv;
772
812
CLUTTER_NOTE (TEXTURE, "Updating texture pixmap");
774
dpy = clutter_x11_get_default_display();
776
814
if (!CLUTTER_ACTOR_IS_REALIZED (texture))
791
829
if (priv->glx_pixmap == None)
794
if (texture_bind (CLUTTER_GLX_TEXTURE_PIXMAP(texture)))
796
CLUTTER_NOTE (TEXTURE, "Really updating via GLX");
798
clutter_x11_trap_x_errors ();
800
(_gl_bind_tex_image) (dpy,
805
XSync (clutter_x11_get_default_display(), FALSE);
807
/* Note above fires X error for non name pixmaps - but
808
* things still seem to work - i.e pixmap updated
810
if (clutter_x11_untrap_x_errors ())
811
CLUTTER_NOTE (TEXTURE, "Update bind_tex_image failed");
815
if (_gl_generate_mipmap
817
&& clutter_texture_get_filter_quality (CLUTTER_TEXTURE (texture))
818
== CLUTTER_TEXTURE_QUALITY_HIGH)
820
/* FIXME: It may make more sense to set a flag here and only
821
* generate the mipmap on a pre paint.. compressing need
822
* to call generate mipmap
823
* May break clones however..
825
priv->mipmap_generate_queued++;
830
g_warning ("Failed to bind initial tex");
832
clutter_actor_queue_redraw (CLUTTER_ACTOR(texture));
832
priv->bind_tex_image_queued = TRUE;
851
851
actor_class->unrealize = clutter_glx_texture_pixmap_unrealize;
853
853
x11_texture_class->update_area = clutter_glx_texture_pixmap_update_area;
858
857
* clutter_glx_texture_pixmap_using_extension:
859
858
* @texture: A #ClutterGLXTexturePixmap
861
* Return value: A boolean indicating if the texture is using the
862
* GLX_EXT_texture_from_pixmap OpenGL extension or falling back to
863
* slower software mechanism.
860
* Checks whether @texture is using the GLX_EXT_texture_from_pixmap
861
* extension; this extension can be optionally (though it is strongly
862
* encouraged) implemented as a zero-copy between a GLX pixmap and
865
* Return value: %TRUE if the texture is using the
866
* GLX_EXT_texture_from_pixmap OpenGL extension or falling back to the
867
* slower software mechanism.
868
872
clutter_glx_texture_pixmap_using_extension (ClutterGLXTexturePixmap *texture)
882
886
* clutter_glx_texture_pixmap_new_with_pixmap:
883
887
* @pixmap: the X Pixmap to which this texture should be bound
889
* Creates a new #ClutterGLXTexturePixmap for @pixmap
885
891
* Return value: A new #ClutterGLXTexturePixmap bound to the given X Pixmap
890
896
clutter_glx_texture_pixmap_new_with_pixmap (Pixmap pixmap)
894
actor = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
898
return g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
902
904
* clutter_glx_texture_pixmap_new_with_window:
903
905
* @window: the X window to which this texture should be bound
907
* Creates a new #ClutterGLXTexturePixmap for @window
905
909
* Return value: A new #ClutterGLXTexturePixmap bound to the given X window
910
914
clutter_glx_texture_pixmap_new_with_window (Window window)
914
actor = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
916
return g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP,
922
922
* clutter_glx_texture_pixmap_new:
924
* Creates a new, empty #ClutterGLXTexturePixmap
924
926
* Return value: A new #ClutterGLXTexturePixmap
929
931
clutter_glx_texture_pixmap_new (void)
933
actor = g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP, NULL);
933
return g_object_new (CLUTTER_GLX_TYPE_TEXTURE_PIXMAP, NULL);