#ifndef __C_VIDEO_OPEN_GL_H_INCLUDED__
#define __C_VIDEO_OPEN_GL_H_INCLUDED__
#include "IrrCompileConfig.h"
#include "SIrrCreationParameters.h"
namespace irr
{
class CIrrDeviceWin32;
class CIrrDeviceLinux;
class CIrrDeviceSDL;
class CIrrDeviceMacOSX;
}
#ifdef _IRR_COMPILE_WITH_OPENGL_
#include "CNullDriver.h"
#include "IMaterialRendererServices.h"
#include "COpenGLExtensionHandler.h"
namespace irr
{
namespace video
{
class COpenGLTexture;
class COpenGLDriver : public CNullDriver, public IMaterialRendererServices, public COpenGLExtensionHandler
{
public:
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWin32* device);
bool initDriver(SIrrlichtCreationParameters params, CIrrDeviceWin32* device);
bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWin32* device);
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device);
bool initDriver(SIrrlichtCreationParameters params, CIrrDeviceLinux* device);
bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceLinux* device);
#endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device);
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceMacOSX *device);
#endif
bool changeRenderContext(const SExposedVideoData& videoData, void* device) {return false;}
virtual ~COpenGLDriver();
virtual bool beginScene(bool backBuffer=true, bool zBuffer=true,
SColor color=SColor(255,0,0,0),
const SExposedVideoData& videoData=SExposedVideoData(),
core::rect<s32>* sourceRect=0);
virtual bool endScene();
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
struct SHWBufferLink_opengl : public SHWBufferLink
{
SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer): SHWBufferLink(_MeshBuffer), vbo_verticesID(0),vbo_indicesID(0){}
GLuint vbo_verticesID;
GLuint vbo_indicesID;
GLuint vbo_verticesSize;
GLuint vbo_indicesSize;
};
virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer);
virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb);
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer);
virtual void createOcclusionQuery(scene::ISceneNode* node,
const scene::IMesh* mesh=0);
virtual void removeOcclusionQuery(scene::ISceneNode* node);
virtual void runOcclusionQuery(scene::ISceneNode* node, bool visible=false);
virtual void updateOcclusionQuery(scene::ISceneNode* node, bool block=true);
virtual u32 getOcclusionQueryResult(scene::ISceneNode* node) const;
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
virtual void draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount,
const void* indexList, u32 primitiveCount,
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
virtual bool queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
{
return FeatureEnabled[feature] && COpenGLExtensionHandler::queryFeature(feature);
}
virtual void setMaterial(const SMaterial& material);
void draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect,
SColor color,
bool useAlphaChannelOfTexture);
virtual void draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
SColor color=SColor(255,255,255,255), bool useAlphaChannelOfTexture=false);
virtual void draw2DImage(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::array<core::rect<s32> >& sourceRects,
const core::array<s32>& indices,
const core::rect<s32>* clipRect=0,
SColor color=SColor(255,255,255,255),
bool useAlphaChannelOfTexture=false);
virtual void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
const video::SColor* const colors=0, bool useAlphaChannelOfTexture=false);
virtual void draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip = 0);
virtual void draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip = 0);
virtual void draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255));
virtual void drawPixel(u32 x, u32 y, const SColor & color);
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end,
SColor color = SColor(255,255,255,255));
virtual const wchar_t* getName() const;
virtual void deleteAllDynamicLights();
virtual s32 addDynamicLight(const SLight& light);
virtual void turnLightOn(s32 lightIndex, bool turnOn);
virtual u32 getMaximalDynamicLightAmount() const;
virtual void setAmbientLight(const SColorf& color);
virtual void drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail);
virtual void drawStencilShadow(bool clearStencilBuffer=false,
video::SColor leftUpEdge = video::SColor(0,0,0,0),
video::SColor rightUpEdge = video::SColor(0,0,0,0),
video::SColor leftDownEdge = video::SColor(0,0,0,0),
video::SColor rightDownEdge = video::SColor(0,0,0,0));
virtual void setViewPort(const core::rect<s32>& area);
virtual void setFog(SColor color, E_FOG_TYPE fogType, f32 start,
f32 end, f32 density, bool pixelFog, bool rangeFog);
virtual void OnResize(const core::dimension2d<u32>& size);
virtual E_DRIVER_TYPE getDriverType() const;
virtual ECOLOR_FORMAT getColorFormat() const;
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderstates);
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
bool setActiveTexture(u32 stage, const video::ITexture* texture);
bool disableTextures(u32 fromStage=0);
virtual s32 addShaderMaterial(const c8* vertexShaderProgram, const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback, E_MATERIAL_TYPE baseMaterial, s32 userData);
virtual s32 addHighLevelShaderMaterial(
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
const c8* pixelShaderProgram,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
const c8* geometryShaderProgram,
const c8* geometryShaderEntryPointName = "main",
E_GEOMETRY_SHADER_TYPE gsCompileTarget = EGST_GS_4_0,
scene::E_PRIMITIVE_TYPE inType = scene::EPT_TRIANGLES,
scene::E_PRIMITIVE_TYPE outType = scene::EPT_TRIANGLE_STRIP,
u32 verticesOut = 0,
IShaderConstantSetCallBack* callback = 0,
E_MATERIAL_TYPE baseMaterial = video::EMT_SOLID,
s32 userData = 0);
virtual IVideoDriver* getVideoDriver();
virtual u32 getMaximalPrimitiveCount() const;
virtual ITexture* addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN);
virtual bool setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget,
bool clearZBuffer, SColor color);
virtual bool setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color);
virtual bool setRenderTarget(const core::array<video::IRenderTarget>& texture,
bool clearBackBuffer=true, bool clearZBuffer=true, SColor color=SColor(0,0,0,0));
virtual void clearZBuffer();
virtual IImage* createScreenShot();
bool testGLError();
virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable=false);
virtual void enableClipPlane(u32 index, bool enable);
virtual void enableMaterial2D(bool enable=true);
virtual core::stringc getVendorInfo() {return VendorName;}
virtual core::dimension2du getMaxTextureSize() const;
ITexture* createDepthTexture(ITexture* texture, bool shared=true);
void removeDepthTexture(ITexture* texture);
GLenum primitiveTypeToGL(scene::E_PRIMITIVE_TYPE type) const;
GLenum getGLBlend(E_BLEND_FACTOR factor) const;
private:
void clearBuffers(bool backBuffer, bool zBuffer, bool stencilBuffer, SColor color);
bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
bool updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
void uploadClipPlane(u32 index);
bool genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer);
virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData);
inline void createGLMatrix(GLfloat gl_matrix[16], const core::matrix4& m);
inline void createGLTextureMatrix(GLfloat gl_matrix[16], const core::matrix4& m);
void setWrapMode(const SMaterial& material);
GLint getTextureWrapMode(const u8 clamp);
void setRenderStates3DMode();
void setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel);
virtual const core::dimension2d<u32>& getCurrentRenderTargetSize() const;
void createMaterialRenderers();
void assignHardwareLight(u32 lightIndex);
void createColorBuffer(const void* vertices, u32 vertexCount, E_VERTEX_TYPE vType);
void renderArray(const void* indexList, u32 primitiveCount,
scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType);
core::stringw Name;
core::matrix4 Matrices[ETS_COUNT];
core::array<u8> ColorBuffer;
enum E_RENDER_MODE
{
ERM_NONE = 0,
ERM_2D,
ERM_3D
};
E_RENDER_MODE CurrentRenderMode;
bool ResetRenderStates;
bool Transformation3DChanged;
u8 AntiAlias;
SMaterial Material, LastMaterial;
COpenGLTexture* RenderTargetTexture;
core::array<video::IRenderTarget> MRTargets;
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
core::array<ITexture*> DepthTextures;
struct SUserClipPlane
{
SUserClipPlane() : Enabled(false) {}
core::plane3df Plane;
bool Enabled;
};
core::array<SUserClipPlane> UserClipPlanes;
core::dimension2d<u32> CurrentRendertargetSize;
core::stringc VendorName;
core::matrix4 TextureFlipMatrix;
ECOLOR_FORMAT ColorFormat;
E_RENDER_TARGET CurrentTarget;
bool Doublebuffer;
bool Stereo;
struct RequestedLight
{
RequestedLight(SLight const & lightData)
: LightData(lightData), HardwareLightIndex(-1), DesireToBeOn(true) { }
SLight LightData;
s32 HardwareLightIndex;
bool DesireToBeOn;
};
core::array<RequestedLight> RequestedLights;
#ifdef _IRR_WINDOWS_API_
HDC HDc;
HWND Window;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
CIrrDeviceWin32 *Device;
#endif
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
GLXDrawable Drawable;
Display* X11Display;
CIrrDeviceLinux *Device;
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
CIrrDeviceMacOSX *Device;
#endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
CIrrDeviceSDL *Device;
#endif
E_DEVICE_TYPE DeviceType;
};
}
}
#endif
#endif