1
/* libcm - A library with a xlib wrapper and a gl based scene graph
2
* Copyright (C) 2005, 2006 Red Hat, Inc.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
19
* Author: Soren Sandmann (sandmann@redhat.com)
23
#include "pixtexture.h"
27
static void cm_pix_texture_render (CmNode *node,
30
G_DEFINE_TYPE (CmPixTexture, cm_pix_texture, CM_TYPE_NODE);
33
cm_pix_texture_finalize (GObject *object)
35
CmPixTexture *pix_texture = CM_PIX_TEXTURE (object);
37
cm_pix_texture_set_pixmap (pix_texture, NULL);
39
cm_node_disown_child (CM_NODE (pix_texture), &pix_texture->child);
41
G_OBJECT_CLASS (cm_pix_texture_parent_class)->finalize (object);
45
pix_texture_vertex (gdouble *x,
52
CmPixTexture *node = data;
54
u = round (u * (node->geometry.width));
55
v = round (v * (node->geometry.height));
58
g_print ("coords: %d %d\n", (int)u, (int)v);
61
glTexCoord2i ((int)u, (int)v);
65
cm_pix_texture_render (CmNode *node,
68
CmPixTexture *pix_texture = CM_PIX_TEXTURE (node);
71
if (!pix_texture->pixmap)
77
cm_state_set_screen_coords (state);
80
texture = ws_pixmap_get_texture (pix_texture->pixmap);
82
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
83
glEnable (GL_TEXTURE_RECTANGLE_ARB);
85
cm_state_push_vertex_func (state, pix_texture_vertex, pix_texture);
87
if (cm_pix_texture_has_alpha (node))
89
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
94
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
95
glColor4f (1.0, 1.0, 0.98, 1.0);
98
cm_node_render (pix_texture->child, state);
100
cm_state_pop_vertex_func (state);
102
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
108
cm_pix_texture_class_init (CmPixTextureClass *class)
110
GObjectClass *object_class = G_OBJECT_CLASS (class);
111
CmNodeClass *node_class = CM_NODE_CLASS (class);
113
object_class->finalize = cm_pix_texture_finalize;
114
node_class->render = cm_pix_texture_render;
118
cm_pix_texture_init (CmPixTexture *pix_texture)
120
pix_texture->updates = TRUE;
124
cm_pix_texture_set_pixmap (CmPixTexture *pix_texture,
127
if (pix_texture->pixmap)
128
g_object_unref (pix_texture->pixmap);
132
WsDisplay *display = WS_RESOURCE (pixmap)->display;
134
g_object_ref (pixmap);
136
ws_display_begin_error_trap (display);
138
ws_drawable_query_geometry (pixmap,
139
&pix_texture->geometry);
141
ws_display_end_error_trap (display);
144
pix_texture->pixmap = pixmap;
146
cm_node_queue_repaint (CM_NODE (pix_texture));
150
cm_pix_texture_new (WsPixmap *pixmap,
153
CmPixTexture *pix_texture = g_object_new (CM_TYPE_PIX_TEXTURE, NULL);
155
cm_pix_texture_set_pixmap (pix_texture, pixmap);
157
cm_node_own_child (CM_NODE (pix_texture), &pix_texture->child, child);
163
cm_pix_texture_set_child (CmPixTexture *pix_texture,
166
if (pix_texture->child == child)
169
cm_node_disown_child (CM_NODE (pix_texture), &pix_texture->child);
170
cm_node_own_child (CM_NODE (pix_texture), &pix_texture->child, child);
174
cm_pix_texture_set_updates (CmPixTexture *pix_texture,
177
pix_texture->updates = !!updates;
179
if (pix_texture->pixmap)
180
ws_pixmap_set_updates (pix_texture->pixmap, pix_texture->updates);
184
cm_pix_textures_get_updates (CmPixTexture *pix_texture)
186
return pix_texture->updates;
190
cm_pix_texture_has_alpha (CmPixTexture *pix_texture)
192
return (pix_texture->pixmap) &&
193
ws_format_has_alpha (ws_drawable_get_format (WS_DRAWABLE (pix_texture->pixmap)));