Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "GLView.h"
  2. #include <stdio.h>
  3. #include <interface/Bitmap.h>
  4.  
  5. BLocker BGLView::locker;
  6.  
  7. BGLView::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.  
  30. BGLView::~BGLView()
  31. {
  32.   ostgl_delete_context(this->context);
  33.   delete this->bitmaps[0];
  34.   delete this->bitmaps[1];
  35. }
  36.  
  37. void
  38. BGLView::LockGL()
  39. {  
  40.   BGLView::locker.Lock();
  41.   ostgl_make_current(this->context, this->currBitmap);
  42. }
  43.  
  44. void
  45. BGLView::UnlockGL()
  46. {
  47.   BGLView::locker.Unlock();
  48. }
  49.  
  50. void
  51. BGLView::SwapBuffers()
  52. {
  53.   if (Window()->Lock()) {
  54.     DrawBitmap(this->bitmaps[this->currBitmap]);
  55.     Window()->Unlock();
  56.     this->currBitmap ^= 1;
  57.   }
  58. }
  59.  
  60. /*
  61. BView *
  62. BGLView::EmbeddedView()
  63. {
  64.   return NULL;
  65. }
  66.  
  67. status_t
  68. BGLView::CopyPixelsOut(BPoint source, BBitmap *dest)
  69. {
  70.   assert(0);
  71.   return 0;
  72. }
  73.  
  74. status_t
  75. BGLView::CopyPixelsIn(BBitmap *source, BPoint dest)
  76. {
  77.   assert(0);
  78.   return 0;
  79. }
  80. */
  81.  
  82. void
  83. BGLView::ErrorCallback(GLenum /*errorCode*/)
  84. {
  85. }
  86.  
  87. void
  88. BGLView::Draw(BRect rect)
  89. {
  90.   //fprintf(stderr, "GLView::Draw()");
  91.   DrawBitmap(this->bitmaps[this->currBitmap^1], rect, rect);
  92. }
  93.  
  94. void
  95. BGLView::AttachedToWindow()
  96. {
  97. }
  98.  
  99. void
  100. BGLView::AllAttached()
  101. {
  102. }
  103.  
  104. void
  105. BGLView::DetachedFromWindow()
  106. {
  107. }
  108.  
  109. void
  110. BGLView::AllDetached()
  111. {
  112. }
  113.  
  114. void
  115. BGLView::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. /*
  136. status_t
  137. BGLView::Perform(perform_code d, void *arg)
  138. {
  139.  
  140. }
  141. */
  142.  
  143. //
  144. // the rest are pass-through functions
  145. //
  146.  
  147. status_t
  148. BGLView::Archive(BMessage *data, bool deep) const
  149. {
  150.   return BView::Archive(data, deep);
  151. }
  152.  
  153. void
  154. BGLView::MessageReceived(BMessage *msg)
  155. {
  156.   BView::MessageReceived(msg);
  157. }
  158.  
  159. void
  160. BGLView::SetResizingMode(uint32 mode)
  161. {
  162.   BView::SetResizingMode(mode);
  163. }
  164.  
  165. void
  166. BGLView::Show()
  167. {
  168.   BView::Show();
  169. }
  170.  
  171. void
  172. BGLView::Hide()
  173. {
  174.   BView::Hide();
  175. }
  176.  
  177. BHandler *
  178. BGLView::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.  
  185. status_t
  186. BGLView::GetSupportedSuites(BMessage *data)
  187. {
  188.   return BView::GetSupportedSuites(data);
  189. }
  190.  
  191. /*
  192. void
  193. BGLView::DirectConnected( direct_buffer_info *info )
  194. {
  195.   BView::DirectConnected(info);
  196. }
  197. */
  198.  
  199. /*
  200. void
  201. BGLView::EnableDirectMode( bool enabled )
  202. {
  203.   BView::EnableDirectMode(enabled);
  204. }
  205. */
  206.