glcanvas.cpp 4.01 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**********************************************************************
 *                                                                    *
 * tgt - Tiny Graphics Toolbox                                        *
 *                                                                    *
 * Copyright (C) 2006-2011 Visualization and Computer Graphics Group, *
 * Department of Computer Science, University of Muenster, Germany.   *
 * <http://viscg.uni-muenster.de>                                     *
 *                                                                    *
 * This file is part of the tgt library. This library is free         *
 * software; you can redistribute it and/or modify it under the terms *
 * of the GNU Lesser General Public License version 2.1 as published  *
 * by the Free Software Foundation.                                   *
 *                                                                    *
 * This library is distributed in the hope that it will be useful,    *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU Lesser General Public License for more details.                *
 *                                                                    *
 * You should have received a copy of the GNU Lesser General Public   *
 * License in the file "LICENSE.txt" along with this library.         *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

#include "tgt/glcanvas.h"
26
#include "tgt/glcontextmanager.h"
schultezub's avatar
schultezub committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "tgt/camera.h"
#include "tgt/painter.h"

#include <cstdlib>
#include <stdio.h>

namespace tgt {

GLCanvas::GLCanvas(const std::string& title,
                   const ivec2& size,
                   const GLCanvas::Buffers buffers )
    : title_(title),
      size_(size),
      buffers_(buffers),
      rgbaSize_(0, 0, 0, 0),
      depthSize_(0),
      stencilSize_(0),
      doubleBuffered_((buffers & DOUBLE_BUFFER) != 0),
      stereoViewing_(false),
      fullscreen_(false),
      autoFlush_(true),
      initialized_(false),
      camera_(0),
      painter_(0) ,
      eventHandler_(new EventHandler())
{}

GLCanvas::~GLCanvas() {
55
    eventHandler_->clearEventListeners();
schultezub's avatar
schultezub committed
56
57
58
59
60
61
62
63
64
65
    delete eventHandler_;
}

void GLCanvas::sizeChanged(const ivec2& size) {
    size_ = size;
    if (painter_)
        painter_->sizeChanged(size);
}

void GLCanvas::paint() {
66
    GLContextScopedLock lock(this);
schultezub's avatar
schultezub committed
67
    if (painter_)
68
        painter_->repaint();
schultezub's avatar
schultezub committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    if (autoFlush_) {
        if (doubleBuffered_) {
            swap();
        } else {
            glFlush();
        }
    }
}

void GLCanvas::init() {
    if (!initialized_)
        initialized_ = true;
}

void GLCanvas::setPainter(Painter* p, bool initP) {
    painter_ = p;
    painter_->setCanvas(this);
    if (initP)
        initPainter();
}

Painter* GLCanvas::getPainter() const {
    return painter_;
}

void GLCanvas::initPainter() {
    if (painter_) {
96
        {
97
            GLContextScopedLock lock(this);
98
99
            painter_->init();
        }
schultezub's avatar
schultezub committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
        painter_->sizeChanged(size_);
    }
}

EventHandler* GLCanvas::getEventHandler() const {
    return eventHandler_;
}
void GLCanvas::setEventHandler(EventHandler* handler){
    delete eventHandler_;
    eventHandler_ = handler;
}

bool GLCanvas::getAutoFlush() {
 return autoFlush_;
}

const ivec4& GLCanvas::getRgbaSize() const {
    return rgbaSize_;
}

int GLCanvas::getDepthSize() const {
    return depthSize_;
}

int GLCanvas::getStencilSize() const {
    return stencilSize_;
}

ivec2 GLCanvas::getSize() const {
    return size_;
}

int GLCanvas::getWidth() const {
    return size_.x;
}

int GLCanvas::getHeight() const {
    return size_.y;
}

GLCanvas::Buffers GLCanvas::getBuffers() const {
    return buffers_;
}

void GLCanvas::setCamera(Camera* cam) {
    camera_ = cam;
}

Camera* GLCanvas::getCamera() const {
    return camera_;
}

} // namespace