Example #1
0
void Buffer::createFromDrawable(Drawable &obj) {
   shouldDelete = true;

   if (obj.getW() > 512 || obj.getH() > 512)
      throw RubyException(rb_eRuntimeError, "Drawable too big for a buffer.");

   int width = obj.getW();
   int height = obj.getH();
   img = oslCreateImage(width, height, OSL_IN_VRAM, OSL_PF_8888);
   if (!img) {
      img = oslCreateImage(width, height, OSL_IN_RAM, OSL_PF_8888);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Buffer could not be created");
   }
   else {
      Buffer::registerInVram(img);
   }

   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();

   obj.clearMove();
   obj.setPos(0, 0);
   obj.draw();
   obj.cancelMove();

   oslSetDrawBuffer(old);
}
Example #2
0
void Buffer::resize(int w, int h) {
   if (!shouldDelete)
      throw RubyException(rb_eRuntimeError, "Not allowed to resize this Buffer");

   OSL_IMAGE *old_image = img;
   OSL_IMAGE *old_buffer = oslGetDrawBuffer();
   
   img = oslCreateImage(w, h, OSL_IN_VRAM, img->pixelFormat);
   if (!img) {
      img = oslCreateImage(w, h, OSL_IN_RAM, img->pixelFormat);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Could not recreate the buffer.");
   }
   else {
      Buffer::registerInVram(img);
   }

   setActual();
   oslDrawImageXY(old_image, 0, 0);
   oslSetDrawBuffer(old_buffer);

   if (old_image->location == OSL_IN_RAM)
      oslDeleteImage(old_image);
   else
      Buffer::removeFromVram(old_image);
}
Example #3
0
void Buffer::resize(int w, int h) {
   OSL_IMAGE *old_image = img;
   OSL_IMAGE *old_buffer = oslGetDrawBuffer();
   
   img = oslCreateImage(w, h, OSL_IN_VRAM, img->pixelFormat);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Could not recreate the buffer.");
   
   setActual();
   oslDrawImageXY(old_image, 0, 0);
   oslSetDrawBuffer(old_buffer);

   oslDeleteImage(old_image);
}
Example #4
0
Buffer::Buffer(Drawable &obj): shouldDelete(true) {
   setClass("Buffer");

   if (obj.getW() > 512 || obj.getH() > 512)
      throw RubyException(rb_eRuntimeError, "Drawable too big for a buffer.");
   
   img = oslCreateImage(obj.getW(), obj.getH(), OSL_IN_VRAM, OSL_PF_8888);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be created");
   
   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();

   obj.clearMove();
   obj.setPos(0, 0);
   obj.draw();
   obj.cancelMove();

   oslSetDrawBuffer(old);
}
Example #5
0
void Buffer::draw(Buffer &obj) {
   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();
   obj.draw();
   oslSetDrawBuffer(old);
}