source: trunk/sys/TinyGL/BeOS/GLView.cpp @ 424

Last change on this file since 424 was 1, checked in by alain, 8 years ago

First import

File size: 3.4 KB
Line 
1#include "GLView.h"
2#include <stdio.h>
3#include <interface/Bitmap.h>
4
5BLocker BGLView::locker;
6
7BGLView::BGLView(BRect rect, char *name,
8                 ulong resizingMode, ulong mode,
9                 ulong options)
10  : BView(rect, name, resizingMode, mode|B_FRAME_EVENTS|B_WILL_DRAW)
11{
12#ifdef __INTEL__
13  color_space cs = B_RGB16_LITTLE;
14#else
15  color_space cs = B_RGB16_BIG;
16#endif
17  this->bitmaps[0] = new BBitmap(rect, cs, false, true);
18  this->bitmaps[1] = new BBitmap(rect, cs, false, true);
19
20  this->currBitmap = 0;
21  int w = this->bitmaps[0]->BytesPerRow() / 2;
22  int h = rect.Height() + 1;
23  void *buffers[2];
24  buffers[0] = this->bitmaps[0]->Bits();
25  buffers[1] = this->bitmaps[1]->Bits();
26  this->context = ostgl_create_context(w, h, 16, buffers, 2);
27  ostgl_make_current(this->context, 0); 
28}
29
30BGLView::~BGLView()
31{
32  ostgl_delete_context(this->context);
33  delete this->bitmaps[0];
34  delete this->bitmaps[1];
35}
36
37void 
38BGLView::LockGL()
39{ 
40  BGLView::locker.Lock();
41  ostgl_make_current(this->context, this->currBitmap);
42}
43
44void 
45BGLView::UnlockGL()
46{
47  BGLView::locker.Unlock();
48}
49
50void 
51BGLView::SwapBuffers()
52{
53  if (Window()->Lock()) {
54    DrawBitmap(this->bitmaps[this->currBitmap]);
55    Window()->Unlock();
56    this->currBitmap ^= 1;
57  }
58}
59
60/*
61BView *
62BGLView::EmbeddedView()
63{
64  return NULL;
65}
66
67status_t
68BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
69{
70  assert(0);
71  return 0;
72}
73
74status_t
75BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
76{
77  assert(0);
78  return 0;
79}
80*/
81
82void 
83BGLView::ErrorCallback(GLenum /*errorCode*/)
84{
85}
86
87void 
88BGLView::Draw(BRect rect)
89{
90  //fprintf(stderr, "GLView::Draw()");
91  DrawBitmap(this->bitmaps[this->currBitmap^1], rect, rect);
92}
93
94void 
95BGLView::AttachedToWindow()
96{
97}
98
99void 
100BGLView::AllAttached()
101{
102}
103
104void 
105BGLView::DetachedFromWindow()
106{
107}
108
109void 
110BGLView::AllDetached()
111{
112}
113
114void 
115BGLView::FrameResized(float w, float h)
116{
117  delete this->bitmaps[0];
118  delete this->bitmaps[1];
119#ifdef __INTEL__
120  color_space cs = B_RGB16_LITTLE;
121#else
122  color_space cs = B_RGB16_BIG;
123#endif
124  this->bitmaps[0] = new BBitmap(BRect(0,0, w-1, h-1), 
125                                 cs, false, true);
126  this->bitmaps[1] = new BBitmap(BRect(0,0, w-1, h-1), 
127                                 cs, false, true);
128  int w2 = this->bitmaps[0]->BytesPerRow() / 2;
129  void *buffers[2];
130  buffers[0] = this->bitmaps[0]->Bits();
131  buffers[1] = this->bitmaps[1]->Bits();
132  ostgl_resize(this->context, w2, h, buffers);
133}
134
135/*
136status_t
137BGLView::Perform(perform_code d, void *arg)
138{
139 
140}
141*/
142
143//
144// the rest are pass-through functions
145//
146
147status_t
148BGLView::Archive(BMessage *data, bool deep) const
149{
150  return BView::Archive(data, deep);
151}
152
153void 
154BGLView::MessageReceived(BMessage *msg)
155{
156  BView::MessageReceived(msg);
157}
158
159void 
160BGLView::SetResizingMode(uint32 mode)
161{
162  BView::SetResizingMode(mode);
163}
164
165void 
166BGLView::Show()
167{
168  BView::Show();
169}
170
171void 
172BGLView::Hide()
173{
174  BView::Hide();
175}
176
177BHandler *
178BGLView::ResolveSpecifier(BMessage *msg, int32 index,
179                          BMessage *specifier, int32 form,
180                                              const char *property)
181{
182  return BView::ResolveSpecifier(msg, index, specifier, form, property);
183}
184
185status_t
186BGLView::GetSupportedSuites(BMessage *data)
187{
188  return BView::GetSupportedSuites(data);
189}
190
191/*
192void
193BGLView::DirectConnected( direct_buffer_info *info )
194{
195  BView::DirectConnected(info);
196}
197*/
198
199/*
200void
201BGLView::EnableDirectMode( bool enabled )
202{
203  BView::EnableDirectMode(enabled);
204}
205*/
Note: See TracBrowser for help on using the repository browser.