Added glSissor suppor via new osg::Scissor class.

Added .osg support for osg::Scissor.
Added .ive support for osg::Viewport and osg::Scissor.
This commit is contained in:
Robert Osfield
2005-07-22 09:31:19 +00:00
parent 37b4df3f71
commit 47651d3c8d
18 changed files with 439 additions and 0 deletions

View File

@@ -408,6 +408,10 @@ SOURCE=..\..\src\osg\Referenced.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Scissor.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Sequence.cpp
# End Source File
# Begin Source File
@@ -896,6 +900,10 @@ SOURCE=..\..\Include\Osg\Referenced
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Scissor
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Sequence
# End Source File
# Begin Source File

View File

@@ -324,6 +324,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\ReaderWriterIVE.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\Scissor.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\Sequence.cpp
# End Source File
# Begin Source File
@@ -412,6 +416,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\VertexProgram.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\Viewport.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\VisibilityGroup.cpp
# End Source File
# End Group
@@ -704,6 +712,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\Program.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\Scissor.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\Shader.h
# End Source File
# Begin Source File
@@ -740,6 +752,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\VertexProgram.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\Viewport.h
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\ive\VisibilityGroup.h
# End Source File
# End Group

View File

@@ -280,6 +280,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ReaderWriterOSG.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\Scissor.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\Sequence.cpp
# End Source File
# Begin Source File
@@ -300,6 +304,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ShapeDrawable.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\Scissor.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\StateSet.cpp
# End Source File
# Begin Source File
@@ -374,6 +382,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Uniform.cpp
SOURCE=..\..\..\src\osgPlugins\osg\VertexProgram.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\Viewport.cpp
# End Source File
# End Group
# Begin Group "Header Files"

110
include/osg/Scissor Normal file
View File

@@ -0,0 +1,110 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_Scissor
#define OSG_Scissor 1
#include <osg/StateAttribute>
namespace osg {
/** Encapsulate OpenGL glScissor. */
class OSG_EXPORT Scissor : public StateAttribute
{
public :
Scissor();
Scissor(int x,int y,int width,int height):
_x(x),
_y(y),
_width(width),
_height(height) {}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Scissor(const Scissor& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(vp,copyop),
_x(vp._x),
_y(vp._y),
_width(vp._width),
_height(vp._height) {}
META_StateAttribute(osg, Scissor, SCISSOR);
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const StateAttribute& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Paramter macro's below.
COMPARE_StateAttribute_Types(Scissor,sa)
// compare each paramter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_x)
COMPARE_StateAttribute_Parameter(_y)
COMPARE_StateAttribute_Parameter(_width)
COMPARE_StateAttribute_Parameter(_height)
return 0; // passed all the above comparison macro's, must be equal.
}
virtual bool getModeUsage(ModeUsage& usage) const
{
usage.usesMode(GL_SCISSOR_TEST);
return true;
}
inline void setScissor(int x,int y,int width,int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
void getScissor(int& x,int& y,int& width,int& height) const
{
x = _x;
y = _y;
width = _width;
height = _height;
}
inline int& x() { return _x; }
inline int x() const { return _x; }
inline int& y() { return _y; }
inline int y() const { return _y; }
inline int& width() { return _width; }
inline int width() const { return _width; }
inline int& height() { return _height; }
inline int height() const { return _height; }
virtual void apply(State& state) const;
protected:
virtual ~Scissor();
int _x;
int _y;
int _width;
int _height;
};
}
#endif

View File

@@ -149,6 +149,7 @@ class OSG_EXPORT StateAttribute : public Object
COLORMASK,
DEPTH,
VIEWPORT,
SCISSOR,
BLENDCOLOR,
MULTISAMPLE,

View File

@@ -74,9 +74,16 @@ class OSG_EXPORT Viewport : public StateAttribute
height = _height;
}
inline int& x() { return _x; }
inline int x() const { return _x; }
inline int& y() { return _y; }
inline int y() const { return _y; }
inline int& width() { return _width; }
inline int width() const { return _width; }
inline int& height() { return _height; }
inline int height() const { return _height; }
inline bool valid() const { return _width!=0 && _height!=0; }

View File

@@ -80,6 +80,7 @@ CXXFILES =\
ProxyNode.cpp\
Quat.cpp\
Referenced.cpp\
Scissor.cpp\
Sequence.cpp\
ShadeModel.cpp\
Shader.cpp\

34
src/osg/Scissor.cpp Normal file
View File

@@ -0,0 +1,34 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osg/Scissor>
using namespace osg;
Scissor::Scissor()
{
_x = 0;
_y = 0;
_width = 800;
_height = 600;
}
Scissor::~Scissor()
{
}
void Scissor::apply(State&) const
{
glScissor(_x,_y,_width,_height);
}

View File

@@ -41,6 +41,8 @@
#include "ProxyNode.h"
#include "FrontFace.h"
#include "Program.h"
#include "Viewport.h"
#include "Scissor.h"
#include "Group.h"
#include "MatrixTransform.h"
@@ -814,6 +816,14 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
attribute = new osg::BlendFunc();
((ive::BlendFunc*)(attribute))->read(this);
}
else if(attributeID == IVEVIEWPORT){
attribute = new osg::Viewport();
((ive::Viewport*)(attribute))->read(this);
}
else if(attributeID == IVESCISSOR){
attribute = new osg::Scissor();
((ive::Scissor*)(attribute))->read(this);
}
else if(attributeID == IVEMATERIAL){
attribute = new osg::Material();
((ive::Material*)(attribute))->read(this);

View File

@@ -44,6 +44,8 @@
#include "Program.h"
#include "Uniform.h"
#include "Shader.h"
#include "Viewport.h"
#include "Scissor.h"
#include "Group.h"
#include "MatrixTransform.h"
@@ -638,6 +640,12 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
else if(dynamic_cast<const osg::BlendFunc*>(attribute)){
((ive::BlendFunc*)(attribute))->write(this);
}
else if(dynamic_cast<const osg::Viewport*>(attribute)){
((ive::Viewport*)(attribute))->write(this);
}
else if(dynamic_cast<const osg::Scissor*>(attribute)){
((ive::Scissor*)(attribute))->write(this);
}
// This is a Material
else if(dynamic_cast<const osg::Material*>(attribute)){
((ive::Material*)(attribute))->write(this);

View File

@@ -61,6 +61,7 @@ CXXFILES =\
ProxyNode.cpp\
ReaderWriterIVE.cpp\
Sequence.cpp\
Scissor.cpp\
ShadeModel.cpp\
Shader.cpp\
Shape.cpp\
@@ -81,6 +82,7 @@ CXXFILES =\
Transform.cpp\
Uniform.cpp\
VertexProgram.cpp\
Viewport.cpp\
VisibilityGroup.cpp\
LIBS += -losgFX -losgSim -losgText $(OSG_LIBS) $(OTHER_LIBS)

View File

@@ -67,6 +67,8 @@ namespace ive {
#define IVEPROGRAM 0x00001124
#define IVESHADER 0x00001125
#define IVEUNIFORM 0x00001126
#define IVEVIEWPORT 0x00001127
#define IVESCISSOR 0x00001128
// Drawables
#define IVEDRAWABLE 0x00001000

View File

@@ -0,0 +1,63 @@
/**********************************************************************
*
* FILE: Scissor.cpp
*
* DESCRIPTION: Read/Write osg::Scissor in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Scissor.h"
#include "Object.h"
using namespace ive;
void Scissor::write(DataOutputStream* out){
// Write Scissor's identification.
out->writeInt(IVESCISSOR);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Scissor::write(): Could not cast this osg::Scissor to an osg::Object.");
// Write Scissor's properties.
out->writeInt(x());
out->writeInt(y());
out->writeInt(width());
out->writeInt(height());
}
void Scissor::read(DataInputStream* in){
// Peek on Scissor's identification.
int id = in->peekInt();
if(id == IVESCISSOR){
// Read Scissor's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Scissor::read(): Could not cast this osg::Scissor to an osg::Object.");
// Read Scissor's properties
x() = (GLenum)in->readInt();
y() = (GLenum)in->readInt();
width() = (GLenum)in->readInt();
height() = (GLenum)in->readInt();
}
else{
throw Exception("Scissor::read(): Expected Scissor identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_SCISSOR
#define IVE_SCISSOR 1
#include <osg/Scissor>
#include "ReadWrite.h"
namespace ive{
class Scissor : public osg::Scissor, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,63 @@
/**********************************************************************
*
* FILE: Viewport.cpp
*
* DESCRIPTION: Read/Write osg::Viewport in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerated
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 21.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Viewport.h"
#include "Object.h"
using namespace ive;
void Viewport::write(DataOutputStream* out){
// Write Viewport's identification.
out->writeInt(IVEVIEWPORT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Viewport::write(): Could not cast this osg::Viewport to an osg::Object.");
// Write Viewport's properties.
out->writeInt(x());
out->writeInt(y());
out->writeInt(width());
out->writeInt(height());
}
void Viewport::read(DataInputStream* in){
// Peek on Viewport's identification.
int id = in->peekInt();
if(id == IVEVIEWPORT){
// Read Viewport's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object.");
// Read Viewport's properties
x() = (GLenum)in->readInt();
y() = (GLenum)in->readInt();
width() = (GLenum)in->readInt();
height() = (GLenum)in->readInt();
}
else{
throw Exception("Viewport::read(): Expected Viewport identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_VIEWPORT
#define IVE_VIEWPORT 1
#include <osg/Viewport>
#include "ReadWrite.h"
namespace ive{
class Viewport : public osg::Viewport, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -47,6 +47,7 @@ CXXFILES =\
Projection.cpp\
ProxyNode.cpp\
ReaderWriterOSG.cpp\
Scissor.cpp\
Sequence.cpp\
ShadeModel.cpp\
Shader.cpp\

View File

@@ -0,0 +1,71 @@
#include "osg/Scissor"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool Scissor_readLocalData(Object& obj, Input& fr);
bool Scissor_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_ScissorProxy
(
new osg::Scissor,
"Scissor",
"Object StateAttribute Scissor",
&Scissor_readLocalData,
&Scissor_writeLocalData
);
bool Scissor_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
int x = 0, y = 0, width = 0, height = 0;
if (fr[0].matchWord("x") && fr[1].getInt(x))
{
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("y") && fr[1].getInt(y))
{
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("width") && fr[1].getInt(width))
{
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("height") && fr[1].getInt(height))
{
fr+=2;
iteratorAdvanced = true;
}
Scissor& scissor = static_cast<Scissor&>(obj);
scissor.setScissor( x, y, width, height );
return iteratorAdvanced;
}
bool Scissor_writeLocalData(const Object& obj, Output& fw)
{
const Scissor& scissor = static_cast<const Scissor&>(obj);
fw.indent() << "x " << scissor.x() << std::endl;
fw.indent() << "y " << scissor.y() << std::endl;
fw.indent() << "width " << scissor.width() << std::endl;
fw.indent() << "height " << scissor.height() << std::endl;
return true;
}