~ubuntu-branches/ubuntu/quantal/libcm/quantal

« back to all changes in this revision

Viewing changes to src/pixtexture.c

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier, Josselin Mouette, Loic Minier
  • Date: 2008-05-26 14:43:19 UTC
  • mfrom: (3.1.4 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080526144319-ddwovigo7i925ewr
Tags: 0.1.1-4
[ Josselin Mouette ]
* Allow libgl-dev and libglu-dev as alternative dependencies for
  libcm-dev. Closes: #478887.

[ Loic Minier ]
* Don't copy config.guess/.sub after unpatch in clean; should avoid having
  them in the .diff.gz -- not needed as we always update them after patching
  anyway -- and should fix conversion to source format 3.0; closes: #482728.
* Stop shipping *.la files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libcm - A library with a xlib wrapper and a gl based scene graph
 
2
 * Copyright (C) 2005, 2006  Red Hat, Inc.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
19
 * Author: Soren Sandmann (sandmann@redhat.com)
 
20
 */
 
21
#include "node.h"
 
22
#include "state.h"
 
23
#include "pixtexture.h"
 
24
#include "wsint.h"
 
25
#include <math.h>
 
26
 
 
27
static void cm_pix_texture_render (CmNode *node,
 
28
                                   CmState *state);
 
29
 
 
30
G_DEFINE_TYPE (CmPixTexture, cm_pix_texture, CM_TYPE_NODE);
 
31
 
 
32
static void
 
33
cm_pix_texture_finalize (GObject *object)
 
34
{
 
35
    CmPixTexture *pix_texture = CM_PIX_TEXTURE (object);
 
36
 
 
37
    cm_pix_texture_set_pixmap (pix_texture, NULL);
 
38
    
 
39
    cm_node_disown_child (CM_NODE (pix_texture), &pix_texture->child);
 
40
        
 
41
    G_OBJECT_CLASS (cm_pix_texture_parent_class)->finalize (object);
 
42
}
 
43
 
 
44
static void
 
45
pix_texture_vertex (gdouble *x,
 
46
                    gdouble *y,
 
47
                    gdouble *z,
 
48
                    gdouble  u,
 
49
                    gdouble  v,
 
50
                    gpointer data)
 
51
{
 
52
    CmPixTexture *node = data;
 
53
 
 
54
    u = round (u * (node->geometry.width));
 
55
    v = round (v * (node->geometry.height));
 
56
 
 
57
#if 0
 
58
    g_print ("coords: %d %d\n", (int)u, (int)v);
 
59
#endif
 
60
    
 
61
    glTexCoord2i ((int)u, (int)v);
 
62
}
 
63
 
 
64
static void
 
65
cm_pix_texture_render (CmNode *node,
 
66
                       CmState *state)
 
67
{
 
68
    CmPixTexture *pix_texture = CM_PIX_TEXTURE (node);
 
69
    GLuint texture;
 
70
 
 
71
    if (!pix_texture->pixmap)
 
72
        return;
 
73
 
 
74
    glPushMatrix ();
 
75
    
 
76
#if 0
 
77
    cm_state_set_screen_coords (state);
 
78
#endif
 
79
    
 
80
    texture = ws_pixmap_get_texture (pix_texture->pixmap);
 
81
    
 
82
    glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
 
83
    glEnable (GL_TEXTURE_RECTANGLE_ARB);
 
84
 
 
85
    cm_state_push_vertex_func (state, pix_texture_vertex, pix_texture);
 
86
 
 
87
    if (cm_pix_texture_has_alpha (node))
 
88
    {
 
89
        glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
90
        glEnable (GL_BLEND);
 
91
    }
 
92
    
 
93
#if 0
 
94
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
95
    glColor4f (1.0, 1.0, 0.98, 1.0);
 
96
#endif
 
97
 
 
98
    cm_node_render (pix_texture->child, state);
 
99
 
 
100
    cm_state_pop_vertex_func (state);
 
101
 
 
102
    glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
 
103
 
 
104
    glPopMatrix ();
 
105
}
 
106
 
 
107
static void
 
108
cm_pix_texture_class_init (CmPixTextureClass *class)
 
109
{
 
110
    GObjectClass *object_class = G_OBJECT_CLASS (class);
 
111
    CmNodeClass *node_class = CM_NODE_CLASS (class);
 
112
    
 
113
    object_class->finalize = cm_pix_texture_finalize;
 
114
    node_class->render = cm_pix_texture_render;
 
115
}
 
116
 
 
117
static void
 
118
cm_pix_texture_init (CmPixTexture *pix_texture)
 
119
{
 
120
    pix_texture->updates = TRUE;
 
121
}
 
122
 
 
123
void
 
124
cm_pix_texture_set_pixmap (CmPixTexture *pix_texture,
 
125
                           WsPixmap *pixmap)
 
126
{
 
127
    if (pix_texture->pixmap)
 
128
        g_object_unref (pix_texture->pixmap);
 
129
    
 
130
    if (pixmap)
 
131
    {
 
132
        WsDisplay *display = WS_RESOURCE (pixmap)->display;
 
133
 
 
134
        g_object_ref (pixmap);
 
135
 
 
136
        ws_display_begin_error_trap (display);
 
137
        
 
138
        ws_drawable_query_geometry (pixmap,
 
139
                                    &pix_texture->geometry);
 
140
        
 
141
        ws_display_end_error_trap (display);
 
142
    }
 
143
 
 
144
    pix_texture->pixmap = pixmap;
 
145
 
 
146
    cm_node_queue_repaint (CM_NODE (pix_texture));
 
147
}
 
148
 
 
149
CmPixTexture *
 
150
cm_pix_texture_new (WsPixmap *pixmap,
 
151
                    CmNode   *child)
 
152
{
 
153
    CmPixTexture *pix_texture = g_object_new (CM_TYPE_PIX_TEXTURE, NULL);
 
154
 
 
155
    cm_pix_texture_set_pixmap (pix_texture, pixmap);
 
156
 
 
157
    cm_node_own_child (CM_NODE (pix_texture), &pix_texture->child, child);
 
158
    
 
159
    return pix_texture;
 
160
}
 
161
 
 
162
void
 
163
cm_pix_texture_set_child (CmPixTexture *pix_texture,
 
164
                          CmNode       *child)
 
165
{
 
166
    if (pix_texture->child == child)
 
167
        return;
 
168
 
 
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);
 
171
}
 
172
 
 
173
void
 
174
cm_pix_texture_set_updates (CmPixTexture *pix_texture,
 
175
                            gboolean      updates)
 
176
{
 
177
    pix_texture->updates = !!updates;
 
178
 
 
179
    if (pix_texture->pixmap)
 
180
        ws_pixmap_set_updates (pix_texture->pixmap, pix_texture->updates);
 
181
}
 
182
 
 
183
gboolean
 
184
cm_pix_textures_get_updates (CmPixTexture *pix_texture)
 
185
{
 
186
    return pix_texture->updates;
 
187
}
 
188
 
 
189
gboolean
 
190
cm_pix_texture_has_alpha (CmPixTexture *pix_texture)
 
191
{
 
192
    return (pix_texture->pixmap) &&
 
193
        ws_format_has_alpha (ws_drawable_get_format (WS_DRAWABLE (pix_texture->pixmap)));
 
194
}
 
195