Skip to content

Commit

Permalink
UPBGE: Use KX_OffScreen as python proxy of RAS_IOffScreen.
Browse files Browse the repository at this point in the history
Previously the RAS_IOffScreen was used in a raw python proxy: PyRASOffScreen.
To make the off screen python proxy homogenous with the other sources, a python
proxy based on CValue was created.
  • Loading branch information
panzergame committed Jul 6, 2016
1 parent 413e5d3 commit 78c816e
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 200 deletions.
37 changes: 1 addition & 36 deletions doc/python_api/rst/bge.render.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,6 @@ Constants

The pixel buffer for offscreen render is a Texture. Argument to :func:`offScreenCreate`


*****
Types
*****

.. class:: RASOffScreen

An off-screen render buffer object.

Use :func:`offScreenCreate` to create it.
Currently it can only be used in the :class:`bge.texture.ImageRender`
constructor to render on a FBO rather than the default viewport.

.. attribute:: width

The width in pixel of the FBO

:type: integer

.. attribute:: height

The height in pixel of the FBO

:type: integer

.. attribute:: color

The underlying OpenGL bind code of the texture object that holds
the rendered image, 0 if the FBO is using RenderBuffer.
The choice between RenderBuffer and Texture is determined
by the target argument of :func:`offScreenCreate`.

:type: integer


*********
Functions
*********
Expand Down Expand Up @@ -431,5 +396,5 @@ Functions
Otherwise the default is preferable as it's more widely supported by GPUs and more efficient.
If the GPU does not support MSAA+Texture (e.g. Intel HD GPU), MSAA will be disabled.
:type target: integer
:rtype: :class:`RASOffScreen`
:rtype: :class:`KX_OffScreen`

35 changes: 35 additions & 0 deletions doc/python_api/rst/bge_types/bge.types.KX_OffScreen.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
KX_OffScreen(CValue)
====================

.. module:: bge.types

base class --- :class:`CValue`

.. class:: KX_OffScreen(CValue)

An off-screen render buffer object.

Use :func:`bge.render.offScreenCreate` to create it.
Currently it can only be used in the :class:`bge.texture.ImageRender`
constructor to render on a FBO rather than the default viewport.

.. attribute:: width

The width in pixel of the FBO

:type: integer

.. attribute:: height

The height in pixel of the FBO

:type: integer

.. attribute:: color

The underlying OpenGL bind code of the texture object that holds
the rendered image, 0 if the FBO is using RenderBuffer.
The choice between RenderBuffer and Texture is determined
by the target argument of :func:`bge.render.offScreenCreate`.

:type: integer
2 changes: 2 additions & 0 deletions source/gameengine/Ketsji/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ set(SRC
KX_ObColorIpoSGController.cpp
KX_ObjectActuator.cpp
KX_ObstacleSimulation.cpp
KX_OffScreen.cpp
KX_OrientationInterpolator.cpp
KX_ParentActuator.cpp
KX_PolyProxy.cpp
Expand Down Expand Up @@ -187,6 +188,7 @@ set(SRC
KX_ObColorIpoSGController.h
KX_ObjectActuator.h
KX_ObstacleSimulation.h
KX_OffScreen.h
KX_OrientationInterpolator.h
KX_ParentActuator.h
KX_PhysicsEngineEnums.h
Expand Down
107 changes: 107 additions & 0 deletions source/gameengine/Ketsji/KX_OffScreen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Tristan Porteries.
*
* ***** END GPL LICENSE BLOCK *****
*/

/** \file gameengine/Ketsji/KX_OffScreen.cpp
* \ingroup ketsji
*/

#include "KX_OffScreen.h"
#include "RAS_IRasterizer.h"

KX_OffScreen::KX_OffScreen(RAS_IRasterizer *rasterizer, RAS_ICanvas *canvas, int width, int height, int samples, RAS_IOffScreen::RAS_OFS_RENDER_TARGET target)
{
m_ofs = rasterizer->CreateOffScreen(canvas, width, height, samples, target);
}

KX_OffScreen::~KX_OffScreen()
{
delete m_ofs;
}

STR_String& KX_OffScreen::GetName()
{
static STR_String offscreenname = "KX_OffScreen";
return offscreenname;
}

RAS_IOffScreen *KX_OffScreen::GetOffScreen() const
{
return m_ofs;
}

#ifdef WITH_PYTHON

PyTypeObject KX_OffScreen::Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"KX_OffScreen",
sizeof(PyObjectPlus_Proxy),
0,
py_base_dealloc,
0,
0,
0,
0,
py_base_repr,
0, 0, 0, 0, 0, 0, 0, 0, 0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
0, 0, 0, 0, 0, 0, 0,
Methods,
0,
0,
&CValue::Type,
0, 0, 0, 0, 0, 0,
py_base_new
};

PyMethodDef KX_OffScreen::Methods[] = {
{NULL, NULL} // Sentinel
};

PyAttributeDef KX_OffScreen::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("width", KX_OffScreen, pyattr_get_width),
KX_PYATTRIBUTE_RO_FUNCTION("height", KX_OffScreen, pyattr_get_height),
KX_PYATTRIBUTE_RO_FUNCTION("color", KX_OffScreen, pyattr_get_color),
{NULL} // Sentinel
};

PyObject *KX_OffScreen::pyattr_get_width(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_OffScreen *self = static_cast<KX_OffScreen *>(self_v);

return PyLong_FromLong(self->GetOffScreen()->GetWidth());
}

PyObject *KX_OffScreen::pyattr_get_height(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_OffScreen *self = static_cast<KX_OffScreen *>(self_v);

return PyLong_FromLong(self->GetOffScreen()->GetHeight());
}

PyObject *KX_OffScreen::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_OffScreen *self = static_cast<KX_OffScreen *>(self_v);

return PyLong_FromLong(self->GetOffScreen()->GetColor());
}

#endif // WITH_PYTHON
60 changes: 60 additions & 0 deletions source/gameengine/Ketsji/KX_OffScreen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Tristan Porteries.
*
* ***** END GPL LICENSE BLOCK *****
*/

/** \file KX_OffScreen.h
* \ingroup ketsji
* \brief Python proxy of RAS_IOffScreen and RAS_OpenGLOffScreen.
*/

#ifndef __KX_OFFSCREEN_H__
#define __KX_OFFSCREEN_H__

#include "EXP_Value.h"
#include "RAS_IOffScreen.h"

class RAS_IRasterizer;
class RAS_ICanvas;

class KX_OffScreen : public CValue
{
Py_Header
private:
RAS_IOffScreen *m_ofs;

public:
KX_OffScreen(RAS_IRasterizer *rasterizer, RAS_ICanvas *canvas, int width, int height, int samples, RAS_IOffScreen::RAS_OFS_RENDER_TARGET target);
virtual ~KX_OffScreen();

virtual STR_String& GetName();

RAS_IOffScreen *GetOffScreen() const;

#ifdef WITH_PYTHON

static PyObject *pyattr_get_width(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_height(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);

#endif
};

#endif // __KX_OFFSCREEN_H__
Loading

0 comments on commit 78c816e

Please sign in to comment.