Merge branch 'master' into shader_pipeline

This commit is contained in:
Robert Osfield 2018-03-06 10:24:26 +00:00
commit 98a7772fa7
5 changed files with 66 additions and 29 deletions

View File

@ -25,7 +25,7 @@ namespace osg {
// forward declare // forward declare
class CallbackObject; class CallbackObject;
class NodeCallback; class NodeCallback;
class StateAtteributeCallback; class StateAttributeCallback;
class UniformCallback; class UniformCallback;
class DrawableUpdateCallback; class DrawableUpdateCallback;
class DrawableEventCallback; class DrawableEventCallback;

View File

@ -25,6 +25,7 @@ class State;
typedef std::vector<osg::ShaderComponent*> ShaderComponents; typedef std::vector<osg::ShaderComponent*> ShaderComponents;
/// deprecated
class OSG_EXPORT ShaderComposer : public osg::Object class OSG_EXPORT ShaderComposer : public osg::Object
{ {
public: public:

View File

@ -159,19 +159,19 @@ class OSG_EXPORT State : public Referenced
_extensionMap[id] = ptr; _extensionMap[id] = ptr;
} }
/* Set whether shader composition is enabled.*/ /* deprecated.*/
void setShaderCompositionEnabled(bool flag) { _shaderCompositionEnabled = flag; } void setShaderCompositionEnabled(bool flag) { _shaderCompositionEnabled = flag; }
/* Get whether shader composition is enabled.*/ /* deprecated.*/
bool getShaderCompositionEnabled() const { return _shaderCompositionEnabled; } bool getShaderCompositionEnabled() const { return _shaderCompositionEnabled; }
/** Set the ShaderComposor object that implements shader composition.*/ /** deprecated.*/
void setShaderComposer(ShaderComposer* sc) { _shaderComposer = sc; } void setShaderComposer(ShaderComposer* sc) { _shaderComposer = sc; }
/** Get the ShaderComposor object.*/ /** deprecated.*/
ShaderComposer* getShaderComposer() { return _shaderComposer.get(); } ShaderComposer* getShaderComposer() { return _shaderComposer.get(); }
/** Get the const ShaderComposor object.*/ /** deprecated.*/
const ShaderComposer* getShaderComposer() const { return _shaderComposer.get(); } const ShaderComposer* getShaderComposer() const { return _shaderComposer.get(); }
/** Get the unform list in which to inject any uniforms that StateAttribute::apply(State&) methods provide.*/ /** Get the unform list in which to inject any uniforms that StateAttribute::apply(State&) methods provide.*/
@ -326,6 +326,14 @@ class OSG_EXPORT State : public Referenced
/** Apply any shader composed state.*/ /** Apply any shader composed state.*/
void applyShaderComposition(); void applyShaderComposition();
void glDrawBuffer(GLenum buffer);
GLenum getDrawBuffer() const { return _drawBuffer; }
void glReadBuffer(GLenum buffer);
GLenum getReadBuffer() const { return _readBuffer; }
/** Set whether a particular OpenGL mode is valid in the current graphics context. /** Set whether a particular OpenGL mode is valid in the current graphics context.
* Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/ * Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/
inline void setModeValidity(StateAttribute::GLMode mode,bool valid) inline void setModeValidity(StateAttribute::GLMode mode,bool valid)
@ -1139,6 +1147,9 @@ class OSG_EXPORT State : public Referenced
ref_ptr<FrameStamp> _frameStamp; ref_ptr<FrameStamp> _frameStamp;
GLenum _drawBuffer;
GLenum _readBuffer;
ref_ptr<const RefMatrix> _identity; ref_ptr<const RefMatrix> _identity;
ref_ptr<const RefMatrix> _initialViewMatrix; ref_ptr<const RefMatrix> _initialViewMatrix;
ref_ptr<const RefMatrix> _projection; ref_ptr<const RefMatrix> _projection;

View File

@ -68,6 +68,9 @@ State::State():
_shaderComposer = new ShaderComposer; _shaderComposer = new ShaderComposer;
_currentShaderCompositionProgram = 0L; _currentShaderCompositionProgram = 0L;
_drawBuffer = GL_NONE;
_readBuffer = GL_NONE;
_identity = new osg::RefMatrix(); // default RefMatrix constructs to identity. _identity = new osg::RefMatrix(); // default RefMatrix constructs to identity.
_initialViewMatrix = _identity; _initialViewMatrix = _identity;
_projection = _identity; _projection = _identity;
@ -584,6 +587,28 @@ void State::reset()
} }
void State::glDrawBuffer(GLenum buffer)
{
if (_drawBuffer!=buffer)
{
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)
glDrawBuffer(buffer);
#endif
_drawBuffer=buffer;
}
}
void State::glReadBuffer(GLenum buffer)
{
if (_readBuffer!=buffer)
{
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)
glReadBuffer(buffer);
#endif
_readBuffer=buffer;
}
}
void State::setInitialViewMatrix(const osg::RefMatrix* matrix) void State::setInitialViewMatrix(const osg::RefMatrix* matrix)
{ {
if (matrix) _initialViewMatrix = matrix; if (matrix) _initialViewMatrix = matrix;

View File

@ -256,7 +256,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
int internalFormat = GL_LUMINANCE; int internalFormat = GL_LUMINANCE;
unsigned int pixelFormat = GL_LUMINANCE; unsigned int pixelFormat = GL_LUMINANCE;
unsigned int dataType = 0; unsigned int dataType = 0;
unsigned int numBytesPerPixel = 0; unsigned int numBytesPerComponent = 0;
GDALDataType targetGDALType = GDT_Byte; GDALDataType targetGDALType = GDT_Byte;
@ -327,14 +327,14 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
targetGDALType = band->GetRasterDataType(); targetGDALType = band->GetRasterDataType();
switch(band->GetRasterDataType()) switch(band->GetRasterDataType())
{ {
case(GDT_Byte): dataType = GL_UNSIGNED_BYTE; numBytesPerPixel = 1; break; case(GDT_Byte): dataType = GL_UNSIGNED_BYTE; numBytesPerComponent = 1; break;
case(GDT_UInt16): dataType = GL_UNSIGNED_SHORT; numBytesPerPixel = 2; break; case(GDT_UInt16): dataType = GL_UNSIGNED_SHORT; numBytesPerComponent = 2; break;
case(GDT_Int16): dataType = GL_SHORT; numBytesPerPixel = 2; break; case(GDT_Int16): dataType = GL_SHORT; numBytesPerComponent = 2; break;
case(GDT_UInt32): dataType = GL_UNSIGNED_INT; numBytesPerPixel = 4; break; case(GDT_UInt32): dataType = GL_UNSIGNED_INT; numBytesPerComponent = 4; break;
case(GDT_Int32): dataType = GL_INT; numBytesPerPixel = 4; break; case(GDT_Int32): dataType = GL_INT; numBytesPerComponent = 4; break;
case(GDT_Float32): dataType = GL_FLOAT; numBytesPerPixel = 4; break; case(GDT_Float32): dataType = GL_FLOAT; numBytesPerComponent = 4; break;
case(GDT_Float64): dataType = GL_DOUBLE; numBytesPerPixel = 8; break; // not handled case(GDT_Float64): dataType = GL_DOUBLE; numBytesPerComponent = 8; break; // not handled
default: dataType = 0; numBytesPerPixel = 0; break; // not handled default: dataType = 0; numBytesPerComponent = 0; break; // not handled
} }
} }
} }
@ -348,7 +348,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
if (dataType==0) if (dataType==0)
{ {
dataType = GL_UNSIGNED_BYTE; dataType = GL_UNSIGNED_BYTE;
numBytesPerPixel = 1; numBytesPerComponent = 1;
targetGDALType = GDT_Byte; targetGDALType = GDT_Byte;
} }
@ -360,7 +360,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
{ {
// RGBA // RGBA
int pixelSpace=4*numBytesPerPixel; int pixelSpace=4*numBytesPerComponent;
int lineSpace=destWidth * pixelSpace; int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace]; imageData = new unsigned char[destWidth * destHeight * pixelSpace];
@ -370,16 +370,16 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
OSG_INFO << "reading RGBA"<<std::endl; OSG_INFO << "reading RGBA"<<std::endl;
bandRed->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandRed->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+3),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+3*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
} }
else else
{ {
// RGB // RGB
int pixelSpace=3*numBytesPerPixel; int pixelSpace=3*numBytesPerComponent;
int lineSpace=destWidth * pixelSpace; int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace]; imageData = new unsigned char[destWidth * destHeight * pixelSpace];
@ -389,8 +389,8 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
OSG_INFO << "reading RGB"<<std::endl; OSG_INFO << "reading RGB"<<std::endl;
bandRed->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandRed->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandBlue->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+2*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
} }
} }
@ -399,7 +399,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
if (bandAlpha) if (bandAlpha)
{ {
// Luminance alpha // Luminance alpha
int pixelSpace=2*numBytesPerPixel; int pixelSpace=2*numBytesPerComponent;
int lineSpace=destWidth * pixelSpace; int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace]; imageData = new unsigned char[destWidth * destHeight * pixelSpace];
@ -409,12 +409,12 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
OSG_INFO << "reading grey + alpha"<<std::endl; OSG_INFO << "reading grey + alpha"<<std::endl;
bandGray->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandGray->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1*numBytesPerComponent),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);
} }
else else
{ {
// Luminance map // Luminance map
int pixelSpace=1*numBytesPerPixel; int pixelSpace=1*numBytesPerComponent;
int lineSpace=destWidth * pixelSpace; int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace]; imageData = new unsigned char[destWidth * destHeight * pixelSpace];
@ -429,7 +429,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
else if (bandAlpha) else if (bandAlpha)
{ {
// alpha map // alpha map
int pixelSpace=1*numBytesPerPixel; int pixelSpace=1*numBytesPerComponent;
int lineSpace=destWidth * pixelSpace; int lineSpace=destWidth * pixelSpace;
imageData = new unsigned char[destWidth * destHeight * pixelSpace]; imageData = new unsigned char[destWidth * destHeight * pixelSpace];
@ -444,7 +444,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
else if (bandPalette) else if (bandPalette)
{ {
// Paletted map // Paletted map
int pixelSpace=1*numBytesPerPixel; int pixelSpace=1*numBytesPerComponent;
int lineSpace=destWidth * pixelSpace; int lineSpace=destWidth * pixelSpace;
unsigned char *rawImageData; unsigned char *rawImageData;
@ -454,7 +454,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
internalFormat = GL_RGBA; internalFormat = GL_RGBA;
OSG_INFO << "reading palette"<<std::endl; OSG_INFO << "reading palette"<<std::endl;
OSG_INFO << "numBytesPerPixel: " << numBytesPerPixel << std::endl; OSG_INFO << "numBytesPerComponent: " << numBytesPerComponent << std::endl;
bandPalette->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(rawImageData),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandPalette->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(rawImageData),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace);