Skip to content

Commit

Permalink
UPBGE: Use pimpl idiom for RAS_OpenGLRasterizer.
Browse files Browse the repository at this point in the history
Previously all the function in RAS_IRasterizer were virtual pure functions
overrided in RAS_OpenGlRasterizer. This was because some of the functions
definition were using OpenGL calls.

An alternative is to use an implemnt an interface. But this interface must
be not included by all the includer of RAS_IRasterizer. To do so we must
use a pointer to the interface.

The interface is the previous RAS_OpenGLRasterizer, it is instantiated
from the RAS_Irasterizer constructor into a std::unique_ptr which delete
it automatically in the destructor. Function using OpenGL call like
Enable(…) and Disable(…) are forwarded to interface instance.
This mechanism is called the pimpl idom.

The pimpl idiom avoid the virtual calls and then the multiple declaration.
In the same time a little optimization is noticed of 4% (1/2ms less of 31ms).
  • Loading branch information
panzergame committed Feb 1, 2017
1 parent aa4b6a0 commit 849d065
Show file tree
Hide file tree
Showing 14 changed files with 2,182 additions and 1,924 deletions.
2 changes: 1 addition & 1 deletion build_files/cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ function(SETUP_BLENDER_SORTED_LIBS)
extern_recastnavigation
ge_logic
ge_device
ge_oglrasterizer
ge_rasterizer
ge_oglrasterizer
ge_common
ge_logic_expressions
ge_scenegraph
Expand Down
2 changes: 1 addition & 1 deletion source/blenderplayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ endif()
ge_phys_dummy
ge_logic
ge_device
ge_oglrasterizer
ge_rasterizer
ge_oglrasterizer
ge_logic_expressions
ge_common
ge_scenegraph
Expand Down
1 change: 0 additions & 1 deletion source/gameengine/Launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ set(INC
../Ketsji/KXNetwork
../Rasterizer
../Rasterizer/Node
../Rasterizer/RAS_OpenGLRasterizer
../SceneGraph
../VideoTexture
../../blender/blenkernel
Expand Down
3 changes: 1 addition & 2 deletions source/gameengine/Launcher/LA_Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "LA_SystemCommandLine.h"

#include "RAS_ICanvas.h"
#include "RAS_OpenGLRasterizer.h"

#include "GPG_Canvas.h"

Expand Down Expand Up @@ -160,7 +159,7 @@ void LA_Launcher::InitEngine()
}
m_pythonConsole.use = (gm->flag & GAME_PYTHON_CONSOLE);

m_rasterizer = new RAS_OpenGLRasterizer();
m_rasterizer = new RAS_IRasterizer();

// Stereo parameters - Eye Separation from the UI - stereomode from the command-line/UI
m_rasterizer->SetStereoMode(m_stereoMode);
Expand Down
1 change: 0 additions & 1 deletion source/gameengine/Launcher/LA_Launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class KX_ISystem;
class KX_ISceneConverter;
class KX_NetworkMessageManager;
class RAS_ICanvas;
class RAS_IRasterizer;
class DEV_EventConsumer;
class DEV_InputDevice;
class GHOST_ISystem;
Expand Down
4 changes: 4 additions & 0 deletions source/gameengine/Rasterizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
set(INC
.
Node
RAS_OpenGLRasterizer
../Common
../Expressions
../Ketsji
../Physics/Common
../SceneGraph
../GameLogic
../../blender/makesdna
../../blender/blenfont
../../blender/blenlib
../../blender/blenkernel
../../blender/gpu
Expand Down Expand Up @@ -64,6 +67,7 @@ set(SRC
RAS_IBatchDisplayArray.cpp
RAS_InstancingBuffer.cpp
RAS_IPolygonMaterial.cpp
RAS_IRasterizer.cpp
RAS_ITexVert.cpp
RAS_MaterialBucket.cpp
RAS_MeshObject.cpp
Expand Down
Loading

0 comments on commit 849d065

Please sign in to comment.