Loading...
Searching...
No Matches
renderTarget.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_VIEW_RENDERING_RENDERTARGET_H
#define BALL_VIEW_RENDERING_RENDERTARGET_H
#include <BALL/COMMON/global.h>
#include <BALL/COMMON/exception.h>
#include <assert.h>
#include <vector>
#include <boost/smart_ptr.hpp>
#include <boost/shared_array.hpp>
#include <BALL/VIEW/RENDERING/pixelFormat.h>
namespace BALL
{
namespace VIEW
{
struct Resolution
{
Size width;
Size height;
Resolution()
: width(0),
height(0)
{ }
Resolution(Size width, Size height)
: width(width),
height(height)
{ }
};
class FrameBufferFormat
{
public:
FrameBufferFormat()
: width(0),
height(0),
pitch(0),
pixelFormat(PixelFormat::RGB_32)
{ }
FrameBufferFormat(Size width, Size height, const PixelFormat &pixelFormat)
: width(width),
height(height),
pitch(width * pixelFormat.computeByteSize()),
pixelFormat(pixelFormat)
{
assert(pitch >= width * pixelFormat.computeByteSize());
}
FrameBufferFormat(Size width, Size height, Size pitch, const PixelFormat &pixelFormat)
: width(width),
height(height),
pitch(pitch),
pixelFormat(pixelFormat)
{
assert(pitch >= width * pixelFormat.computeByteSize());
}
bool operator==(const FrameBufferFormat& format) const
{
return width==format.width
&& height==format.height
&& pitch==format.pitch
&& pixelFormat==format.pixelFormat;
}
bool operator!=(const FrameBufferFormat& format) const
{
return !(*this == format);
}
bool isValid() const { return width > 0 && height > 0 && pitch > 0; }
unsigned int getWidth() const { return width; }
void setWidth(unsigned int width) { this->width = width; }
unsigned int getHeight() const { return height; }
void setHeight(unsigned int height) { this->height = height; }
unsigned int getPitch() const { return pitch; }
void setPitch(unsigned int pitch) { this->pitch = pitch; }
const PixelFormat &getPixelFormat() const { return pixelFormat; }
void setPixelFormat(const PixelFormat &pixelFormat)
{
this->pixelFormat = pixelFormat;
}
size_t computeSize() const
{
// pitch is in bytes
return isValid() ? (getPitch() * getHeight()) : 0;
}
void resize(Size newWidth, Size newHeight)
{
this->width = newWidth;
this->height = newHeight;
}
const FrameBufferFormat resized(Size newWidth, Size newHeight) const
{
return FrameBufferFormat(newWidth, newHeight, pitch, pixelFormat);
}
private:
unsigned int width;
unsigned int height;
unsigned int pitch;
PixelFormat pixelFormat;
};
inline std::ostream &operator<<(std::ostream &o, const FrameBufferFormat &f)
{
o << f.getWidth() << "x" << f.getHeight() << ", pitch " << f.getPitch()
<< ", pixel format: " << f.getPixelFormat();
return o;
}
typedef std::vector<FrameBufferFormat> BufferFormatList;
//-----------------------------------------------------------------------------
class FrameBuffer
{
public:
FrameBuffer(void* data, const FrameBufferFormat &format)
: data(data),
format(format)
{
}
virtual ~FrameBuffer() {}
void *getData() { return data; }
const void *getData() const { return data; }
const FrameBufferFormat &getFormat() const { return format; }
protected:
void setData(void *data) { this->data = data; }
void setFormat(const FrameBufferFormat &format) { this->format = format; }
private:
void *data;
FrameBufferFormat format;
};
typedef boost::shared_ptr<FrameBuffer> FrameBufferPtr;
//-----------------------------------------------------------------------------
class RenderTarget
{
public:
virtual ~RenderTarget() { }
virtual FrameBufferPtr getBuffer() = 0;
virtual FrameBufferFormat getFormat() const = 0;
virtual void releaseBuffer(FrameBufferPtr buffer) = 0;
virtual bool init() = 0;
virtual bool resize(const unsigned int width, const unsigned int height) = 0;
virtual void refresh() = 0;
/* Prepare the window for rendering, e.g., make it current if necessary.
*/
virtual void prepareRendering() = 0;
virtual void setupStereo(float /*eye_separation*/, float /*focal_length*/) {};
virtual bool doNotResize() const = 0;
};
} //namespace VIEW
} // namespace BALL
#endif // BALL_VIEW_RENDERING_RENDERTARGET_H
exception.h
global.h
BALL::VIEW::FrameBufferFormat
Definition renderTarget.h:45
BALL::VIEW::FrameBufferFormat::isValid
bool isValid() const
Definition renderTarget.h:87
BALL::VIEW::FrameBufferFormat::resize
void resize(Size newWidth, Size newHeight)
Definition renderTarget.h:130
BALL::VIEW::FrameBufferFormat::getWidth
unsigned int getWidth() const
Definition renderTarget.h:92
BALL::VIEW::FrameBufferFormat::operator!=
bool operator!=(const FrameBufferFormat &format) const
Definition renderTarget.h:82
BALL::VIEW::FrameBufferFormat::getPitch
unsigned int getPitch() const
Definition renderTarget.h:106
BALL::VIEW::FrameBufferFormat::resized
const FrameBufferFormat resized(Size newWidth, Size newHeight) const
Definition renderTarget.h:139
BALL::VIEW::FrameBufferFormat::getHeight
unsigned int getHeight() const
Definition renderTarget.h:100
BALL::VIEW::FrameBufferFormat::setHeight
void setHeight(unsigned int height)
Definition renderTarget.h:103
BALL::VIEW::FrameBufferFormat::setWidth
void setWidth(unsigned int width)
Definition renderTarget.h:97
BALL::VIEW::FrameBufferFormat::setPitch
void setPitch(unsigned int pitch)
Definition renderTarget.h:109
BALL::VIEW::FrameBufferFormat::getPixelFormat
const PixelFormat & getPixelFormat() const
Definition renderTarget.h:112
BALL::VIEW::FrameBufferFormat::computeSize
size_t computeSize() const
Definition renderTarget.h:123
BALL::VIEW::FrameBufferFormat::FrameBufferFormat
FrameBufferFormat()
Definition renderTarget.h:49
BALL::VIEW::FrameBufferFormat::FrameBufferFormat
FrameBufferFormat(Size width, Size height, const PixelFormat &pixelFormat)
Definition renderTarget.h:56
BALL::VIEW::FrameBufferFormat::operator==
bool operator==(const FrameBufferFormat &format) const
Definition renderTarget.h:74
BALL::VIEW::FrameBufferFormat::FrameBufferFormat
FrameBufferFormat(Size width, Size height, Size pitch, const PixelFormat &pixelFormat)
Definition renderTarget.h:65
BALL::VIEW::FrameBufferFormat::setPixelFormat
void setPixelFormat(const PixelFormat &pixelFormat)
Definition renderTarget.h:115
BALL::VIEW::FrameBuffer::getData
void * getData()
Definition renderTarget.h:193
BALL::VIEW::FrameBuffer::getFormat
const FrameBufferFormat & getFormat() const
Definition renderTarget.h:199
BALL::VIEW::FrameBuffer::getData
const void * getData() const
Definition renderTarget.h:196
BALL::VIEW::FrameBuffer::~FrameBuffer
virtual ~FrameBuffer()
Definition renderTarget.h:190
BALL::VIEW::FrameBuffer::setData
void setData(void *data)
Definition renderTarget.h:204
BALL::VIEW::FrameBuffer::FrameBuffer
FrameBuffer(void *data, const FrameBufferFormat &format)
Definition renderTarget.h:181
BALL::VIEW::FrameBuffer::setFormat
void setFormat(const FrameBufferFormat &format)
Definition renderTarget.h:207
BALL::VIEW::PixelFormat
Definition pixelFormat.h:61
BALL::VIEW::RenderTarget
Definition renderTarget.h:227
BALL::VIEW::RenderTarget::refresh
virtual void refresh()=0
BALL::VIEW::RenderTarget::resize
virtual bool resize(const unsigned int width, const unsigned int height)=0
BALL::VIEW::RenderTarget::prepareRendering
virtual void prepareRendering()=0
BALL::VIEW::RenderTarget::getFormat
virtual FrameBufferFormat getFormat() const =0
BALL::VIEW::RenderTarget::releaseBuffer
virtual void releaseBuffer(FrameBufferPtr buffer)=0
BALL::VIEW::RenderTarget::getBuffer
virtual FrameBufferPtr getBuffer()=0
BALL::VIEW::RenderTarget::init
virtual bool init()=0
BALL::VIEW::RenderTarget::doNotResize
virtual bool doNotResize() const =0
BALL::VIEW::RenderTarget::setupStereo
virtual void setupStereo(float, float)
Definition renderTarget.h:272
BALL::VIEW::RenderTarget::~RenderTarget
virtual ~RenderTarget()
Definition renderTarget.h:230
BALL::VIEW
Definition constraints.h:35
BALL::VIEW::operator<<
std::ostream & operator<<(std::ostream &o, const PixelFormat &f)
Definition pixelFormat.h:209
BALL::VIEW::BufferFormatList
std::vector< FrameBufferFormat > BufferFormatList
Definition renderTarget.h:170
BALL::VIEW::FrameBufferPtr
boost::shared_ptr< FrameBuffer > FrameBufferPtr
Definition renderTarget.h:222
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
pixelFormat.h
BALL::VIEW::Resolution::Resolution
Resolution()
Definition renderTarget.h:29
BALL::VIEW::Resolution::Resolution
Resolution(Size width, Size height)
Definition renderTarget.h:34
BALL::VIEW::Resolution::width
Size width
Definition renderTarget.h:26
BALL::VIEW::Resolution::height
Size height
Definition renderTarget.h:27