| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/DrawPixels> |
|---|
| 14 | |
|---|
| 15 | using namespace osg; |
|---|
| 16 | |
|---|
| 17 | DrawPixels::DrawPixels() |
|---|
| 18 | { |
|---|
| 19 | |
|---|
| 20 | setSupportsDisplayList(false); |
|---|
| 21 | |
|---|
| 22 | _position.set(0.0f,0.0f,0.0f); |
|---|
| 23 | |
|---|
| 24 | _useSubImage = false; |
|---|
| 25 | _offsetX = 0; |
|---|
| 26 | _offsetY = 0; |
|---|
| 27 | _width = 0; |
|---|
| 28 | _height = 0; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | DrawPixels::DrawPixels(const DrawPixels& drawimage,const CopyOp& copyop): |
|---|
| 32 | Drawable(drawimage,copyop), |
|---|
| 33 | _position(drawimage._position), |
|---|
| 34 | _image(drawimage._image), |
|---|
| 35 | _useSubImage(drawimage._useSubImage), |
|---|
| 36 | _offsetX(drawimage._offsetX), |
|---|
| 37 | _offsetY(drawimage._offsetY), |
|---|
| 38 | _width(drawimage._width), |
|---|
| 39 | _height(drawimage._height) |
|---|
| 40 | { |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | DrawPixels::~DrawPixels() |
|---|
| 44 | { |
|---|
| 45 | |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void DrawPixels::setPosition(const osg::Vec3& position) |
|---|
| 49 | { |
|---|
| 50 | _position = position; |
|---|
| 51 | dirtyBound(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void DrawPixels::setSubImageDimensions(unsigned int offsetX,unsigned int offsetY,unsigned int width,unsigned int height) |
|---|
| 55 | { |
|---|
| 56 | _useSubImage = true; |
|---|
| 57 | _offsetX = offsetX; |
|---|
| 58 | _offsetY = offsetY; |
|---|
| 59 | _width = width; |
|---|
| 60 | _height = height; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | void DrawPixels::getSubImageDimensions(unsigned int& offsetX,unsigned int& offsetY,unsigned int& width,unsigned int& height) const |
|---|
| 64 | { |
|---|
| 65 | offsetX = _offsetX; |
|---|
| 66 | offsetY = _offsetY; |
|---|
| 67 | width = _width; |
|---|
| 68 | height = _height; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | BoundingBox DrawPixels::computeBound() const |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | BoundingBox bbox; |
|---|
| 76 | float diagonal = 0.0f; |
|---|
| 77 | if (_useSubImage) |
|---|
| 78 | { |
|---|
| 79 | diagonal = sqrtf(_width*_width+_height*_height); |
|---|
| 80 | } |
|---|
| 81 | else |
|---|
| 82 | { |
|---|
| 83 | diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t()); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal)); |
|---|
| 87 | bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal)); |
|---|
| 88 | return bbox; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void DrawPixels::drawImplementation(RenderInfo&) const |
|---|
| 92 | { |
|---|
| 93 | #ifdef OSG_GL1_AVAILABLE |
|---|
| 94 | glRasterPos3f(_position.x(),_position.y(),_position.z()); |
|---|
| 95 | |
|---|
| 96 | if (_useSubImage) |
|---|
| 97 | { |
|---|
| 98 | const GLvoid* pixels = _image->data(_offsetX,_offsetY); |
|---|
| 99 | glPixelStorei(GL_UNPACK_ALIGNMENT,_image->getPacking()); |
|---|
| 100 | glPixelStorei(GL_UNPACK_ROW_LENGTH,_image->s()); |
|---|
| 101 | glDrawPixels(_width,_height, |
|---|
| 102 | (GLenum)_image->getPixelFormat(), |
|---|
| 103 | (GLenum)_image->getDataType(), |
|---|
| 104 | pixels); |
|---|
| 105 | glPixelStorei(GL_UNPACK_ROW_LENGTH,0); |
|---|
| 106 | } |
|---|
| 107 | else |
|---|
| 108 | { |
|---|
| 109 | glPixelStorei(GL_UNPACK_ALIGNMENT,_image->getPacking()); |
|---|
| 110 | glPixelStorei(GL_UNPACK_ROW_LENGTH,0); |
|---|
| 111 | glDrawPixels(_image->s(), _image->t(), |
|---|
| 112 | (GLenum)_image->getPixelFormat(), |
|---|
| 113 | (GLenum)_image->getDataType(), |
|---|
| 114 | _image->data() ); |
|---|
| 115 | } |
|---|
| 116 | #else |
|---|
| 117 | OSG_NOTICE<<"Warning: DrawPixels::drawImplementation(RenderInfo&) - not supported."<<std::endl; |
|---|
| 118 | #endif |
|---|
| 119 | } |
|---|