Commit 4dc82327 authored by hybrid's avatar hybrid

Added the getColorFormat for some drivers. Added the GLX context in exposed...

Added the getColorFormat for some drivers. Added the GLX context in exposed video data under OpenGL/X11.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1387 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 67da89e3
......@@ -73,6 +73,7 @@ struct SExposedVideoData
{
// XWindow handles
void* X11Display;
void* X11Context;
unsigned long X11Window;
} OpenGLLinux;
};
......
......@@ -49,7 +49,7 @@ COpenGLDriver::COpenGLDriver(const core::dimension2d<s32>& screenSize,
bool COpenGLDriver::initDriver(const core::dimension2d<s32>& screenSize,
HWND window, u32 bits, bool fullscreen, bool vsync, bool stencilBuffer)
{
static PIXELFORMATDESCRIPTOR pfd = {
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
......@@ -142,6 +142,26 @@ bool COpenGLDriver::initDriver(const core::dimension2d<s32>& screenSize,
break;
}
if (HDc)
{
int pf = GetPixelFormat(HDc);
DescribePixelFormat(HDc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
if (pfd.cAlphaBits != 0)
{
if (pfd.cRedBits == 8)
ColorFormat = ECF_A8R8G8B8;
else
ColorFormat = ECF_A1R5G5B5;
}
else
{
if (pfd.cRedBits == 8)
ColorFormat = ECF_R8G8B8;
else
ColorFormat = ECF_R5G6B5;
}
}
genericDriverInit(screenSize, stencilBuffer);
// set vsync
......@@ -168,7 +188,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
AntiAlias(params.AntiAlias), RenderTargetTexture(0), LastSetLight(-1),
CurrentRendertargetSize(0,0), _device(device)
CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8), _device(device)
{
#ifdef _DEBUG
setDebugName("COpenGLDriver");
......@@ -188,15 +208,14 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias),
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0)
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8)
{
#ifdef _DEBUG
setDebugName("COpenGLDriver");
#endif
XWindow = glXGetCurrentDrawable();
XDisplay = glXGetCurrentDisplay();
ExposedData.OpenGLLinux.X11Display = XDisplay;
ExposedData.OpenGLLinux.X11Window = XWindow;
ExposedData.OpenGLLinux.X11Context = glXGetCurrentContext();
ExposedData.OpenGLLinux.X11Display = glXGetCurrentDisplay();
ExposedData.OpenGLLinux.X11Window = glXGetCurrentDrawable();
genericDriverInit(params.WindowSize, params.Stencilbuffer);
......@@ -225,7 +244,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias),
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0)
RenderTargetTexture(0), LastSetLight(-1), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8)
{
#ifdef _DEBUG
setDebugName("COpenGLDriver");
......@@ -423,7 +442,7 @@ bool COpenGLDriver::endScene( void* windowId, core::rect<s32>* sourceRect )
#ifdef _IRR_USE_WINDOWS_DEVICE_
return SwapBuffers(HDc) == TRUE;
#elif defined(_IRR_USE_LINUX_DEVICE_)
glXSwapBuffers(XDisplay, XWindow);
glXSwapBuffers((Display*)ExposedData.OpenGLLinux.X11Display, ExposedData.OpenGLLinux.X11Window);
return true;
#elif defined(_IRR_USE_OSX_DEVICE_)
_device->flush();
......@@ -2360,7 +2379,6 @@ void COpenGLDriver::OnResize(const core::dimension2d<s32>& size)
}
//! Returns type of video driver
E_DRIVER_TYPE COpenGLDriver::getDriverType() const
{
......@@ -2368,6 +2386,12 @@ E_DRIVER_TYPE COpenGLDriver::getDriverType() const
}
//! returns color format
ECOLOR_FORMAT COpenGLDriver::getColorFormat() const
{
return ColorFormat;
}
//! Sets a vertex shader constant.
void COpenGLDriver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
......@@ -2511,8 +2535,6 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
// check if we should set the previous RT back
bool ret = true;
setTexture(0, 0);
ResetRenderStates=true;
if (RenderTargetTexture!=0)
......@@ -2567,7 +2589,7 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
glClear(mask);
return ret;
return true;
}
......
......@@ -245,6 +245,9 @@ namespace video
//! Returns type of video driver
virtual E_DRIVER_TYPE getDriverType() const;
//! get color format of the current color buffer
virtual ECOLOR_FORMAT getColorFormat() const;
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
......@@ -352,9 +355,6 @@ namespace video
void createMaterialRenderers();
core::stringw Name;
core::matrix4 Matrices[ETS_COUNT];
core::array<u8> ColorBuffer;
......@@ -386,13 +386,13 @@ namespace video
core::matrix4 TextureFlipMatrix;
//! Color buffer format
ECOLOR_FORMAT ColorFormat;
#ifdef _IRR_WINDOWS_API_
HDC HDc; // Private GDI Device Context
HWND Window;
HGLRC HRc; // Permanent Rendering Context
#elif defined(_IRR_USE_LINUX_DEVICE_)
GLXDrawable XWindow;
Display* XDisplay;
#elif defined(_IRR_USE_OSX_DEVICE_)
CIrrDeviceMacOSX *_device;
#endif
......
......@@ -46,6 +46,7 @@ COpenGLTexture::COpenGLTexture(IImage* origImage, const char* name, COpenGLDrive
}
}
//! ColorFrameBuffer constructor
COpenGLTexture::COpenGLTexture(const core::dimension2d<s32>& size,
bool extPackedDepthStencilSupported,
......@@ -247,7 +248,6 @@ void COpenGLTexture::getImageData(IImage* image)
}
//! copies the the texture into an open gl texture.
void COpenGLTexture::copyTexture(bool newTexture)
{
......@@ -335,7 +335,6 @@ void COpenGLTexture::copyTexture(bool newTexture)
}
//! returns the size of a texture which would be the optimal size for rendering it
inline s32 COpenGLTexture::getTextureSizeFromSurfaceSize(s32 size) const
{
......@@ -360,7 +359,6 @@ void* COpenGLTexture::lock()
}
//! unlock function
void COpenGLTexture::unlock()
{
......@@ -373,7 +371,6 @@ void COpenGLTexture::unlock()
}
//! Returns size of the original image.
const core::dimension2d<s32>& COpenGLTexture::getOriginalSize() const
{
......@@ -381,7 +378,6 @@ const core::dimension2d<s32>& COpenGLTexture::getOriginalSize() const
}
//! Returns of the texture.
const core::dimension2d<s32>& COpenGLTexture::getSize() const
{
......@@ -392,15 +388,13 @@ const core::dimension2d<s32>& COpenGLTexture::getSize() const
}
//! returns driver type of texture (=the driver, who created the texture)
//! returns driver type of texture, i.e. the driver, which created the texture
E_DRIVER_TYPE COpenGLTexture::getDriverType() const
{
return EDT_OPENGL;
}
//! returns color format of texture
ECOLOR_FORMAT COpenGLTexture::getColorFormat() const
{
......@@ -411,7 +405,6 @@ ECOLOR_FORMAT COpenGLTexture::getColorFormat() const
}
//! returns pitch of texture (in bytes)
u32 COpenGLTexture::getPitch() const
{
......@@ -422,7 +415,6 @@ u32 COpenGLTexture::getPitch() const
}
//! return open gl texture name
GLuint COpenGLTexture::getOpenGLTextureName() const
{
......@@ -474,11 +466,13 @@ bool COpenGLTexture::isFrameBufferObject() const
return ColorFrameBuffer != 0;
}
bool COpenGLTexture::isRenderTarget() const
{
return IsRenderTarget;
}
void COpenGLTexture::setRenderTarget(bool isTarget)
{
IsRenderTarget = isTarget;
......@@ -504,6 +498,7 @@ void COpenGLTexture::unbindFrameBufferObject()
#endif
}
#ifdef GL_EXT_framebuffer_object
bool checkFBOStatus(COpenGLDriver* Driver)
{
......@@ -558,6 +553,7 @@ bool checkFBOStatus(COpenGLDriver* Driver)
}
#endif
} // end namespace video
} // end namespace irr
......
......@@ -20,7 +20,7 @@ namespace video
//! constructor
CSoftwareDriver::CSoftwareDriver(const core::dimension2d<s32>& windowSize, bool fullscreen, io::IFileSystem* io, video::IImagePresenter* presenter)
: CNullDriver(io, windowSize), RenderTargetTexture(0), RenderTargetSurface(0),
CurrentTriangleRenderer(0), ZBuffer(0), Texture(0)
CurrentTriangleRenderer(0), ZBuffer(0), Texture(0), Presenter(presenter)
{
#ifdef _DEBUG
setDebugName("CSoftwareDriver");
......@@ -29,15 +29,13 @@ CSoftwareDriver::CSoftwareDriver(const core::dimension2d<s32>& windowSize, bool
// create backbuffer
BackBuffer = new CImage(ECF_A1R5G5B5, windowSize);
if (BackBuffer)
{
BackBuffer->fill(SColor(0));
// get presenter
Presenter = presenter;
// create z buffer
ZBuffer = video::createZBuffer(BackBuffer->getDimension());
}
// create triangle renderers
......@@ -67,6 +65,7 @@ CSoftwareDriver::CSoftwareDriver(const core::dimension2d<s32>& windowSize, bool
CSoftwareDriver::~CSoftwareDriver()
{
// delete Backbuffer
if (BackBuffer)
BackBuffer->drop();
// delete triangle renderers
......@@ -232,7 +231,7 @@ bool CSoftwareDriver::beginScene(bool backBuffer, bool zBuffer, SColor color)
{
CNullDriver::beginScene(backBuffer, zBuffer, color);
if (backBuffer)
if (backBuffer && BackBuffer)
BackBuffer->fill( color );
if (ZBuffer && zBuffer)
......@@ -753,6 +752,7 @@ void CSoftwareDriver::OnResize(const core::dimension2d<s32>& size)
bool resetRT = (RenderTargetSurface == BackBuffer);
if (BackBuffer)
BackBuffer->drop();
BackBuffer = new CImage(ECF_A1R5G5B5, realSize);
......@@ -853,6 +853,16 @@ E_DRIVER_TYPE CSoftwareDriver::getDriverType() const
}
//! returns color format
ECOLOR_FORMAT CSoftwareDriver::getColorFormat() const
{
if (BackBuffer)
return BackBuffer->getColorFormat();
else
return CNullDriver::getColorFormat();
}
//! Returns the transformation set by setTransform
const core::matrix4& CSoftwareDriver::getTransform(E_TRANSFORMATION_STATE state) const
{
......@@ -880,7 +890,10 @@ void CSoftwareDriver::clearZBuffer()
//! Returns an image created from the last rendered frame.
IImage* CSoftwareDriver::createScreenShot()
{
if (BackBuffer)
return new CImage(BackBuffer->getColorFormat(), BackBuffer);
else
return 0;
}
......
......@@ -87,6 +87,9 @@ namespace video
//! Returns type of video driver
virtual E_DRIVER_TYPE getDriverType() const;
//! get color format of the current color buffer
virtual ECOLOR_FORMAT getColorFormat() const;
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
......
......@@ -36,11 +36,13 @@ CBurningVideoDriver::CBurningVideoDriver(const core::dimension2d<s32>& windowSiz
// create backbuffer
BackBuffer = new CImage(BURNINGSHADER_COLOR_FORMAT, windowSize);
if (BackBuffer)
{
BackBuffer->fill(SColor(0));
// create z buffer
DepthBuffer = video::createDepthBuffer(BackBuffer->getDimension());
}
// create triangle renderers
......@@ -110,33 +112,28 @@ CBurningVideoDriver::CBurningVideoDriver(const core::dimension2d<s32>& windowSiz
tmr->drop ();
umr->drop ();
// select render target
setRenderTarget(BackBuffer);
LightSpace.Global_AmbientLight.set ( 0.f, 0.f, 0.f, 0.f );
// select the right renderer
//CurrentShader = BurningShader[ETR_REFERENCE];
setCurrentShader();
}
//! destructor
CBurningVideoDriver::~CBurningVideoDriver()
{
s32 i;
// delete Backbuffer
if (BackBuffer)
BackBuffer->drop();
// delete triangle renderers
for (i=0; i<ETR2_COUNT; ++i)
for (s32 i=0; i<ETR2_COUNT; ++i)
if (BurningShader[i])
BurningShader[i]->drop();
......@@ -153,7 +150,6 @@ CBurningVideoDriver::~CBurningVideoDriver()
}
//! void selects the right triangle renderer based on the render states.
void CBurningVideoDriver::setCurrentShader()
{
......@@ -389,7 +385,7 @@ bool CBurningVideoDriver::beginScene(bool backBuffer, bool zBuffer, SColor color
{
CNullDriver::beginScene(backBuffer, zBuffer, color);
if (backBuffer)
if (backBuffer && BackBuffer)
BackBuffer->fill( color );
if (DepthBuffer && zBuffer)
......@@ -403,7 +399,7 @@ bool CBurningVideoDriver::endScene( void* windowId, core::rect<s32>* sourceRect
{
CNullDriver::endScene();
Presenter->present(BackBuffer, windowId, sourceRect );
Presenter->present(BackBuffer, windowId, sourceRect);
return true;
}
......@@ -1556,7 +1552,6 @@ void CBurningVideoDriver::draw2DLine(const core::position2d<s32>& start,
}
//! draw an 2d rectangle
void CBurningVideoDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip)
......@@ -1581,6 +1576,7 @@ void CBurningVideoDriver::draw2DRectangle(SColor color, const core::rect<s32>& p
}
}
//! Only used by the internal engine. Used to notify the driver that
//! the window was resized.
void CBurningVideoDriver::OnResize(const core::dimension2d<s32>& size)
......@@ -1606,6 +1602,7 @@ void CBurningVideoDriver::OnResize(const core::dimension2d<s32>& size)
bool resetRT = (RenderTargetSurface == BackBuffer);
if (BackBuffer)
BackBuffer->drop();
BackBuffer = new CImage(BURNINGSHADER_COLOR_FORMAT, realSize);
......@@ -1614,12 +1611,14 @@ void CBurningVideoDriver::OnResize(const core::dimension2d<s32>& size)
}
}
//! returns the current render target size
const core::dimension2d<s32>& CBurningVideoDriver::getCurrentRenderTargetSize() const
{
return RenderTargetSize;
}
//!Draws an 2d rectangle with a gradient.
void CBurningVideoDriver::draw2DRectangle(const core::rect<s32>& position,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
......@@ -1733,7 +1732,6 @@ void CBurningVideoDriver::draw2DRectangle(const core::rect<s32>& position,
}
//! Draws a 3d line.
void CBurningVideoDriver::draw3DLine(const core::vector3df& start,
const core::vector3df& end, SColor color)
......@@ -1782,7 +1780,6 @@ void CBurningVideoDriver::draw3DLine(const core::vector3df& start,
}
//! \return Returns the name of the video driver. Example: In case of the DirectX8
//! driver, it would return "Direct3D8.1".
const wchar_t* CBurningVideoDriver::getName() const
......@@ -1798,18 +1795,28 @@ const wchar_t* CBurningVideoDriver::getName() const
#endif
}
//! Returns type of video driver
E_DRIVER_TYPE CBurningVideoDriver::getDriverType() const
{
return EDT_BURNINGSVIDEO;
}
//! returns color format
ECOLOR_FORMAT CBurningVideoDriver::getColorFormat() const
{
return BURNINGSHADER_COLOR_FORMAT;
}
//! Returns the transformation set by setTransform
const core::matrix4& CBurningVideoDriver::getTransform(E_TRANSFORMATION_STATE state) const
{
return Transformation[state].m;
}
//! Creates a render target texture.
ITexture* CBurningVideoDriver::createRenderTargetTexture(const core::dimension2d<s32>& size, const c8* name)
{
......@@ -1832,7 +1839,10 @@ void CBurningVideoDriver::clearZBuffer()
//! Returns an image created from the last rendered frame.
IImage* CBurningVideoDriver::createScreenShot()
{
if (BackBuffer)
return new CImage(BackBuffer->getColorFormat(), BackBuffer);
else
return 0;
}
......@@ -1844,6 +1854,7 @@ ITexture* CBurningVideoDriver::createDeviceDependentTexture(IImage* surface, con
}
//! Returns the maximum amount of primitives (mostly vertices) which
//! the device is able to render with one drawIndexedTriangleList
//! call.
......@@ -1852,8 +1863,9 @@ u32 CBurningVideoDriver::getMaximalPrimitiveCount() const
return 0x00800000;
}
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
//! this: Frist, draw all geometry. Then use this method, to draw the shadow
//! this: First, draw all geometry. Then use this method, to draw the shadow
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
void CBurningVideoDriver::drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail)
{
......
......@@ -103,6 +103,9 @@ namespace video
//! Returns type of video driver
virtual E_DRIVER_TYPE getDriverType() const;
//! get color format of the current color buffer
virtual ECOLOR_FORMAT getColorFormat() const;
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
......@@ -134,7 +137,6 @@ namespace video
video::SColor leftDownEdge = video::SColor(0,0,0,0),
video::SColor rightDownEdge = video::SColor(0,0,0,0));
protected:
//! sets a render target
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment