aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/tinygl-0.4-ugfx/BeOS/GLView.cpp
blob: 778107e62dfef4325693ca2fab66c406a9658e0f (plain)
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
26
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
96
97
98
99
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "GLView.h"
#include <stdio.h>
#include <interface/Bitmap.h>

BLocker BGLView::locker;

BGLView::BGLView(BRect rect, char *name,
                 ulong resizingMode, ulong mode,
                 ulong options)
  : BView(rect, name, resizingMode, mode|B_FRAME_EVENTS|B_WILL_DRAW)
{
#ifdef __INTEL__
  color_space cs = B_RGB16_LITTLE;
#else
  color_space cs = B_RGB16_BIG;
#endif
  this->bitmaps[0] = new BBitmap(rect, cs, false, true);
  this->bitmaps[1] = new BBitmap(rect, cs, false, true);

  this->currBitmap = 0;
  int w = this->bitmaps[0]->BytesPerRow() / 2;
  int h = rect.Height() + 1;
  void *buffers[2];
  buffers[0] = this->bitmaps[0]->Bits();
  buffers[1] = this->bitmaps[1]->Bits();
  this->context = ostgl_create_context(w, h, 16, buffers, 2);
  ostgl_make_current(this->context, 0); 
}

BGLView::~BGLView()
{
  ostgl_delete_context(this->context);
  delete this->bitmaps[0];
  delete this->bitmaps[1];
}

void 
BGLView::LockGL()
{  
  BGLView::locker.Lock();
  ostgl_make_current(this->context, this->currBitmap);
}

void 
BGLView::UnlockGL()
{
  BGLView::locker.Unlock();
}

void 
BGLView::SwapBuffers()
{
  if (Window()->Lock()) {
    DrawBitmap(this->bitmaps[this->currBitmap]);
    Window()->Unlock();
    this->currBitmap ^= 1;
  }
}

/*
BView *
BGLView::EmbeddedView()
{
  return NULL;
}

status_t 
BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
{
  assert(0);
  return 0;
}

status_t 
BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
{
  assert(0);
  return 0;
}
*/

void 
BGLView::ErrorCallback(GLenum /*errorCode*/)
{
}

void 
BGLView::Draw(BRect rect)
{
  //fprintf(stderr, "GLView::Draw()");
  DrawBitmap(this->bitmaps[this->currBitmap^1], rect, rect);
}

void 
BGLView::AttachedToWindow()
{
}

void 
BGLView::AllAttached()
{
}

void 
BGLView::DetachedFromWindow()
{
}

void 
BGLView::AllDetached()
{
}

void 
BGLView::FrameResized(float w, float h)
{
  delete this->bitmaps[0];
  delete this->bitmaps[1];
#ifdef __INTEL__
  color_space cs = B_RGB16_LITTLE;
#else
  color_space cs = B_RGB16_BIG;
#endif
  this->bitmaps[0] = new BBitmap(BRect(0,0, w-1, h-1), 
                                 cs, false, true);
  this->bitmaps[1] = new BBitmap(BRect(0,0, w-1, h-1), 
                                 cs, false, true);
  int w2 = this->bitmaps[0]->BytesPerRow() / 2;
  void *buffers[2];
  buffers[0] = this->bitmaps[0]->Bits();
  buffers[1] = this->bitmaps[1]->Bits();
  ostgl_resize(this->context, w2, h, buffers);
}

/*
status_t 
BGLView::Perform(perform_code d, void *arg)
{
  
}
*/

//
// the rest are pass-through functions
//

status_t 
BGLView::Archive(BMessage *data, bool deep) const
{
  return BView::Archive(data, deep);
}

void 
BGLView::MessageReceived(BMessage *msg)
{
  BView::MessageReceived(msg);
}

void 
BGLView::SetResizingMode(uint32 mode)
{
  BView::SetResizingMode(mode);
}

void 
BGLView::Show()
{
  BView::Show();
}

void 
BGLView::Hide()
{
  BView::Hide();
}

BHandler *
BGLView::ResolveSpecifier(BMessage *msg, int32 index,
                          BMessage *specifier, int32 form,
					      const char *property)
{
  return BView::ResolveSpecifier(msg, index, specifier, form, property);
}

status_t 
BGLView::GetSupportedSuites(BMessage *data)
{
  return BView::GetSupportedSuites(data);
}

/*
void 
BGLView::DirectConnected( direct_buffer_info *info )
{
  BView::DirectConnected(info);
}
*/

/*
void 
BGLView::EnableDirectMode( bool enabled )
{
  BView::EnableDirectMode(enabled);
}
*/