OLD | NEW |
| (Empty) |
1 // Copyright 2010 The Ginsu Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can | |
3 // be found in the LICENSE file. | |
4 | |
5 #include "c_salt/opengl_view.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "c_salt/instance.h" | |
10 #include "c_salt/opengl_context.h" | |
11 | |
12 namespace c_salt { | |
13 | |
14 OpenGLView::OpenGLView() : width_(1), height_(1), needs_redraw_(true) { | |
15 } | |
16 | |
17 OpenGLView::~OpenGLView() { | |
18 } | |
19 | |
20 SharedOpenGLContext OpenGLView::GetOpenGLContext() const { | |
21 return context_; | |
22 } | |
23 | |
24 void OpenGLView::SetOpenGLContext(SharedOpenGLContext context) { | |
25 context_ = context; // Might cause ReleaseOpenGL() to be called. | |
26 SharedOpenGLView shared_view(this); | |
27 context_->set_opengl_view(shared_view); | |
28 } | |
29 | |
30 void OpenGLView::SetNeedsRedraw(bool flag) { | |
31 needs_redraw_ = flag; | |
32 if (needs_redraw_) { | |
33 // Signal the associated context to issue a repaint request. | |
34 context_->RenderOpenGL(); | |
35 } | |
36 } | |
37 | |
38 void OpenGLView::AddToInstance(const Instance& instance) { | |
39 if (context_.get() && context_->is_valid()) { | |
40 // This view already belongs to a context, do nothing. | |
41 return; | |
42 } | |
43 SharedOpenGLContext shared_context(new OpenGLContext(instance)); | |
44 shared_context->InitializeOpenGL(); | |
45 SetOpenGLContext(shared_context); | |
46 } | |
47 | |
48 void OpenGLView::SetSize(int32_t width, int32_t height) { | |
49 width_ = std::max(static_cast<int32_t>(1), width); | |
50 height_ = std::max(static_cast<int32_t>(1), height); | |
51 assert(context_.get()); | |
52 if (context_.get() && context_->is_valid()) | |
53 context_->MakeContextCurrent(); | |
54 ResizeViewport(); | |
55 } | |
56 | |
57 } // namespace c_salt | |
OLD | NEW |