Added new osg::DrawPixels class with encapsulates glDrawPixels as and

osg::Drawable.  Added osg::Image::readPixels to osg::Image.

Made osg::LightSource to default to cullActive set to false to that LightSource
nodes don't get culled by default.
This commit is contained in:
Robert Osfield
2002-04-10 21:51:34 +00:00
parent 80d2c718cd
commit 360247225e
11 changed files with 282 additions and 15 deletions

View File

@@ -3,6 +3,7 @@
#include <osg/Notify>
#include <osg/Transform>
#include <osg/Texture>
#include <osg/DrawPixels>
#include <osgUtil/TrackballManipulator>
#include <osgUtil/FlightManipulator>
@@ -165,6 +166,23 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
osg::Vec3 local_offset(0.0f,0.0f,0.0f);
osg::Vec3 local_delta(3.0f,0.0f,0.0f);
// // use DrawPixels drawable to draw a pixel image.
// {
//
// osg::DrawPixels* drawimage = osgNew osg::DrawPixels;
// drawimage->setPosition(local_offset);
// drawimage->setImage(image);
//
// osg::Geode* geode = osgNew osg::Geode;
// geode->addDrawable(drawimage);
//
// // add the transform node to root group node.
// top_transform->addChild(geode);
//
// local_offset += local_delta;
// }
// defaults mipmapped texturing.
{
// create the texture attribute

100
src/osg/DrawPixels.cpp Normal file
View File

@@ -0,0 +1,100 @@
#include <osg/DrawPixels>
using namespace osg;
DrawPixels::DrawPixels()
{
// turn off display lists right now, just incase we want to modify the projection matrix along the way.
setSupportsDisplayList(false);
_position.set(0.0f,0.0f,0.0f);
_useSubImage = false;
_offsetX = 0;
_offsetY = 0;
_width = 0;
_height = 0;
}
DrawPixels::DrawPixels(const DrawPixels& drawimage,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Drawable(drawimage,copyop),
_position(drawimage._position),
_image(drawimage._image),
_useSubImage(drawimage._useSubImage),
_offsetX(drawimage._offsetX),
_offsetY(drawimage._offsetY),
_width(drawimage._width),
_height(drawimage._height)
{
}
DrawPixels::~DrawPixels()
{
// image will delete itself thanks to ref_ptr :-)
}
void DrawPixels::setPosition(const osg::Vec3& position)
{
_position = position;
dirtyBound();
}
void DrawPixels::setSubImageDimensions(unsigned int offsetX,unsigned int offsetY,unsigned int width,unsigned int height)
{
_useSubImage = true;
_offsetX = offsetX;
_offsetY = offsetY;
_width = width;
_height = height;
}
void DrawPixels::getSubImageDimensions(unsigned int& offsetX,unsigned int& offsetY,unsigned int& width,unsigned int& height) const
{
offsetX = _offsetX;
offsetY = _offsetY;
width = _width;
height = _height;
}
const bool DrawPixels::computeBound() const
{
// really needs to be dependant of view poistion and projection... will implement simple version right now.
_bbox.init();
float diagonal = 0.0f;
if (_useSubImage)
{
diagonal = sqrtf(_width*_width+_height*_height);
}
else
{
diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t());
}
_bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal));
_bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal));
_bbox_computed = true;
return true;
}
void DrawPixels::drawImmediateMode(State&)
{
glRasterPos3f(_position.x(),_position.y(),_position.z());
if (_useSubImage)
{
const GLvoid* pixels = _image->data();
glDrawPixels(_width,_height,
(GLenum)_image->pixelFormat(),
(GLenum)_image->dataType(),
pixels);
}
else
{
glDrawPixels(_image->s(), _image->t(),
(GLenum)_image->pixelFormat(),
(GLenum)_image->dataType(),
_image->data() );
}
}

View File

@@ -21,6 +21,7 @@ Image::Image()
_pixelFormat = (unsigned int)0;
_dataType = (unsigned int)0;
_packing = 4;
_pixelSizeInBits = 0;
_data = (unsigned char *)0L;
@@ -35,6 +36,7 @@ Image::Image(const Image& image,const CopyOp& copyop):
_pixelFormat(image._pixelFormat),
_dataType(image._dataType),
_packing(image._packing),
_pixelSizeInBits(image._pixelSizeInBits),
_data(0L),
_modifiedTag(image._modifiedTag)
{
@@ -64,6 +66,12 @@ void Image::setFileName(const std::string& fileName)
}
void Image::computePixelSize()
{
// temporary code.. to be filled in properly ASAP. RO.
_pixelSizeInBits=32;
}
void Image::setImage(const int s,const int t,const int r,
const int internalFormat,
const unsigned int pixelFormat,
@@ -92,6 +100,8 @@ void Image::setImage(const int s,const int t,const int r,
}
else
_packing = packing;
computePixelSize();
// test scaling...
// scaleImageTo(16,16,_r);
@@ -100,10 +110,52 @@ void Image::setImage(const int s,const int t,const int r,
}
void Image::readPixels(int x,int y,int width,int height,
unsigned int pixelFormat,unsigned int dataType,
const int packing)
{
if (width!=_s || height!=_s || _t != 1 ||
_pixelFormat!=pixelFormat ||
_dataType!=dataType)
{
if (_data) ::free(_data);
_s = width;
_t = height;
_r = 1;
_pixelFormat = pixelFormat;
_dataType = dataType;
if (packing<0)
{
if (_s%4==0)
_packing = 4;
else
_packing = 1;
}
else
_packing = packing;
computePixelSize();
// need to sort out what size to really use...
_data = (unsigned char *)malloc(2 * (_s+1)*(_t+1)*4);
}
glPixelStorei(GL_PACK_ALIGNMENT,_packing);
glReadPixels(x,y,width,height,pixelFormat,dataType,_data);
}
void Image::scaleImage(const int s,const int t,const int /*r*/)
{
if (_data==NULL) return;
// need to sort out what size to really use...
unsigned char* newData = (unsigned char *)malloc(2 * (s+1)*(t+1)*4);
glPixelStorei(GL_PACK_ALIGNMENT,_packing);

View File

@@ -4,7 +4,8 @@ using namespace osg;
LightSource::LightSource()
{
_bsphere_computed = false;
// switch off culling of light source nodes by default.
setCullingActive(false);
}

View File

@@ -16,6 +16,7 @@ CXXFILES =\
Depth.cpp\
DisplaySettings.cpp\
Drawable.cpp\
DrawPixels.cpp\
EarthSky.cpp\
Fog.cpp\
FrameStamp.cpp\

View File

@@ -236,13 +236,6 @@ void SceneView::cullStage(osg::Camera* camera, osgUtil::CullVisitor* cullVisitor
osg::Matrix* projection = osgNew osg::Matrix(camera->getProjectionMatrix());
osg::Matrix* modelview = osgNew osg::Matrix(camera->getModelViewMatrix());
// take a copy of camera, and init it home
osg::Camera* local_camera = osgNew Camera(*camera);
local_camera->home();
local_camera->attachTransform(osg::Camera::NO_ATTACHED_TRANSFORM);
cullVisitor->setLODBias(_lodBias);
cullVisitor->setEarthSky(NULL); // reset earth sky on each frame.
@@ -347,7 +340,6 @@ void SceneView::cullStage(osg::Camera* camera, osgUtil::CullVisitor* cullVisitor
_far_plane = 1000.0f;
}
local_camera->setNearFar(_near_plane,_far_plane);
camera->setNearFar(_near_plane,_far_plane);
}