axmol/extensions/Effekseer/EffekseerRendererGL/EffekseerRendererGL.h

684 lines
17 KiB
C
Raw Normal View History


#ifndef __EFFEKSEERRENDERER_GL_BASE_PRE_H__
#define __EFFEKSEERRENDERER_GL_BASE_PRE_H__
#include <Effekseer.h>
#include <vector>
2022-11-01 11:40:06 +08:00
// #if defined(_WIN32)
// #include <windows.h>
// #endif
// #if defined(__EFFEKSEER_RENDERER_GLES2__)
// #if defined(__APPLE__)
// #include <OpenGLES/ES2/gl.h>
// #include <OpenGLES/ES2/glext.h>
// #else
// #include <GLES2/gl2.h>
// #include <GLES2/gl2ext.h>
// #endif
// #elif defined(__EFFEKSEER_RENDERER_GLES3__)
// #if defined(__APPLE__)
// #include <OpenGLES/ES3/gl.h>
// #else
// #define GL_GLEXT_PROTOTYPES
// #include <GLES3/gl3.h>
// #endif
// #elif defined(__EFFEKSEER_RENDERER_GL2__)
// #if _WIN32
// #include <GL/gl.h>
// #elif defined(__APPLE__)
// #define GL_SILENCE_DEPRECATION
// #include <OpenGL/gl.h>
// #else
// #include <GL/gl.h>
// #endif
// #else
// #if defined(_WIN32)
// #include <GL/gl.h>
// #pragma comment(lib, "opengl32.lib")
// #elif defined(__APPLE__)
// #define GL_SILENCE_DEPRECATION
// #include <OpenGL/gl3.h>
// #else
// #define GL_GLEXT_PROTOTYPES
// #include <GL/gl.h>
// #endif
// #endif
#include "platform/GL.h"
namespace EffekseerRendererGL
{
class Renderer;
enum class OpenGLDeviceType
{
OpenGL2,
OpenGL3,
OpenGLES2,
OpenGLES3,
};
} // namespace EffekseerRendererGL
#endif // __EFFEKSEERRENDERER_GL_BASE_PRE_H__
#ifndef __EFFEKSEERRENDERER_RENDERER_H__
#define __EFFEKSEERRENDERER_RENDERER_H__
//----------------------------------------------------------------------------------
// Include
//----------------------------------------------------------------------------------
#include <Effekseer.h>
//-----------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------
namespace Effekseer
{
namespace Backend
{
class VertexBuffer;
class IndexBuffer;
class GraphicsDevice;
} // namespace Backend
} // namespace Effekseer
namespace EffekseerRenderer
{
class Renderer;
using RendererRef = ::Effekseer::RefPtr<Renderer>;
/**
@brief Specify a shader for renderer from external class
@note
For Effekseer tools
*/
struct ExternalShaderSettings
{
Effekseer::Backend::ShaderRef StandardShader;
Effekseer::Backend::ShaderRef ModelShader;
Effekseer::AlphaBlendType Blend;
};
/**
@brief
\~english A callback to distort a background before drawing
\~japanese
*/
class DistortingCallback
{
public:
DistortingCallback()
{
}
virtual ~DistortingCallback()
{
}
/**
@brief
\~english A callback
\~japanese
@note
\~english Don't hold renderer in the instance
\~japanese rendererを保持してはいけない
*/
virtual bool OnDistorting(Renderer* renderer)
{
return false;
}
};
/**
@brief
\~english A status of UV when particles are rendered.
\~japanese UVの状態
*/
enum class UVStyle
{
Normal,
VerticalFlipped,
};
/**
@brief
\~english A type of texture which is rendered when textures are not assigned.
\~japanese
*/
enum class ProxyTextureType
{
White,
Normal,
};
class CommandList : public ::Effekseer::IReference
{
public:
CommandList() = default;
virtual ~CommandList() = default;
};
class SingleFrameMemoryPool : public ::Effekseer::IReference
{
public:
SingleFrameMemoryPool() = default;
virtual ~SingleFrameMemoryPool() = default;
/**
@brief
\~English notify that new frame is started.
\~Japanese
*/
virtual void NewFrame()
{
}
};
struct DepthReconstructionParameter
{
float DepthBufferScale = 1.0f;
float DepthBufferOffset = 0.0f;
float ProjectionMatrix33 = 0.0f;
float ProjectionMatrix34 = 0.0f;
float ProjectionMatrix43 = 0.0f;
float ProjectionMatrix44 = 0.0f;
};
::Effekseer::ModelLoaderRef CreateModelLoader(::Effekseer::Backend::GraphicsDeviceRef gprahicsDevice, ::Effekseer::FileInterfaceRef fileInterface = nullptr);
class Renderer : public ::Effekseer::IReference
{
protected:
Renderer();
virtual ~Renderer();
class Impl;
std::unique_ptr<Impl> impl;
public:
/**
@brief only for Effekseer backend developer. Effekseer User doesn't need it.
*/
Impl* GetImpl();
/**
@brief
*/
virtual void OnLostDevice() = 0;
/**
@brief
*/
virtual void OnResetDevice() = 0;
/**
@brief
*/
virtual void SetRestorationOfStatesFlag(bool flag) = 0;
/**
@brief
*/
virtual bool BeginRendering() = 0;
/**
@brief
*/
virtual bool EndRendering() = 0;
/**
@brief Get the direction of light
*/
virtual ::Effekseer::Vector3D GetLightDirection() const;
/**
@brief Specifiy the direction of light
*/
virtual void SetLightDirection(const ::Effekseer::Vector3D& direction);
/**
@brief Get the color of light
*/
virtual const ::Effekseer::Color& GetLightColor() const;
/**
@brief Specify the color of light
*/
virtual void SetLightColor(const ::Effekseer::Color& color);
/**
@brief Get the color of ambient
*/
virtual const ::Effekseer::Color& GetLightAmbientColor() const;
/**
@brief Specify the color of ambient
*/
virtual void SetLightAmbientColor(const ::Effekseer::Color& color);
/**
@brief
*/
virtual int32_t GetSquareMaxCount() const = 0;
/**
@brief Get a projection matrix
*/
virtual ::Effekseer::Matrix44 GetProjectionMatrix() const;
/**
@brief Set a projection matrix
*/
virtual void SetProjectionMatrix(const ::Effekseer::Matrix44& mat);
/**
@brief Get a camera matrix
*/
virtual ::Effekseer::Matrix44 GetCameraMatrix() const;
/**
@brief Set a camera matrix
*/
virtual void SetCameraMatrix(const ::Effekseer::Matrix44& mat);
/**
@brief Get a camera projection matrix
*/
virtual ::Effekseer::Matrix44 GetCameraProjectionMatrix() const;
/**
@brief Get a front direction of camera
@note
We don't recommend to use it without understanding of internal code.
*/
virtual ::Effekseer::Vector3D GetCameraFrontDirection() const;
/**
@brief Get a position of camera
@note
We don't recommend to use it without understanding of internal code.
*/
virtual ::Effekseer::Vector3D GetCameraPosition() const;
/**
@brief Set a front direction and position of camera manually
@param front (Right Hand) a direction from focus to eye, (Left Hand) a direction from eye to focus,
@note
These are set based on camera matrix automatically.
It is failed on some platform.
*/
virtual void SetCameraParameter(const ::Effekseer::Vector3D& front, const ::Effekseer::Vector3D& position);
/**
@brief
*/
virtual ::Effekseer::SpriteRendererRef CreateSpriteRenderer() = 0;
/**
@brief
*/
virtual ::Effekseer::RibbonRendererRef CreateRibbonRenderer() = 0;
/**
@brief
*/
virtual ::Effekseer::RingRendererRef CreateRingRenderer() = 0;
/**
@brief
*/
virtual ::Effekseer::ModelRendererRef CreateModelRenderer() = 0;
/**
@brief
*/
virtual ::Effekseer::TrackRendererRef CreateTrackRenderer() = 0;
/**
@brief
*/
virtual ::Effekseer::TextureLoaderRef CreateTextureLoader(::Effekseer::FileInterfaceRef fileInterface = nullptr) = 0;
/**
@brief
*/
virtual ::Effekseer::ModelLoaderRef CreateModelLoader(::Effekseer::FileInterfaceRef fileInterface = nullptr) = 0;
/**
@brief
\~english Create default material loader
\~japanese
*/
virtual ::Effekseer::MaterialLoaderRef CreateMaterialLoader(::Effekseer::FileInterfaceRef fileInterface = nullptr) = 0;
/**
@brief
*/
virtual void ResetRenderState() = 0;
/**
@brief
*/
virtual DistortingCallback* GetDistortingCallback() = 0;
/**
@brief
*/
virtual void SetDistortingCallback(DistortingCallback* callback) = 0;
/**
@brief
\~english Get draw call count
\~japanese
*/
virtual int32_t GetDrawCallCount() const;
/**
@brief
\~english Get the number of vertex drawn
\~japanese
*/
virtual int32_t GetDrawVertexCount() const;
/**
@brief
\~english Reset draw call count
\~japanese
*/
virtual void ResetDrawCallCount();
/**
@brief
\~english Reset the number of vertex drawn
\~japanese
*/
virtual void ResetDrawVertexCount();
/**
@brief
\~english Get a render mode.
\~japanese
*/
virtual Effekseer::RenderMode GetRenderMode() const;
/**
@brief
\~english Specify a render mode.
\~japanese
*/
virtual void SetRenderMode(Effekseer::RenderMode renderMode);
/**
@brief
\~english Get an UV Style of texture when particles are rendered.
\~japanese UVの状態を取得する
*/
virtual UVStyle GetTextureUVStyle() const;
/**
@brief
\~english Set an UV Style of texture when particles are rendered.
\~japanese UVの状態を設定する
*/
virtual void SetTextureUVStyle(UVStyle style);
/**
@brief
\~english Get an UV Style of background when particles are rendered.
\~japanese UVの状態を取得する
*/
virtual UVStyle GetBackgroundTextureUVStyle() const;
/**
@brief
\~english Set an UV Style of background when particles are rendered.
\~japanese UVの状態を設定する
*/
virtual void SetBackgroundTextureUVStyle(UVStyle style);
/**
@brief
\~english Get a current time (s)
\~japanese ()
*/
virtual float GetTime() const;
/**
@brief
\~english Set a current time (s)
\~japanese ()
*/
virtual void SetTime(float time);
/**
@brief
\~English specify a command list to render. This function is available except DirectX9, DirectX11 and OpenGL.
\~Japanese 使DirectX9DirectX11OpenGL以外で使用できる
*/
virtual void SetCommandList(Effekseer::RefPtr<CommandList> commandList)
{
}
/**
@brief \~English Get a background texture.
\~Japanese
@note
\~English Textures are generated by a function specific to each backend or SetBackground.
\~Japanese SetBackgroundで生成される
*/
virtual const ::Effekseer::Backend::TextureRef& GetBackground();
/**
@brief
\~English Specify a background texture.
\~Japanese
*/
virtual void SetBackground(::Effekseer::Backend::TextureRef texture);
/**
@brief
\~English Create a proxy texture
\~Japanese
*/
virtual ::Effekseer::Backend::TextureRef CreateProxyTexture(ProxyTextureType type);
/**
@brief
\~English Delete a proxy texture
\~Japanese
*/
virtual void DeleteProxyTexture(Effekseer::Backend::TextureRef& texture);
/**
@brief
\~English Get a depth texture and parameters to reconstruct from z to depth
\~Japanese Zから深度を復元するためのパラメーターを取得する
*/
virtual void GetDepth(::Effekseer::Backend::TextureRef& texture, DepthReconstructionParameter& reconstructionParam);
/**
@brief
\~English Specify a depth texture and parameters to reconstruct from z to depth
\~Japanese Zから深度を復元するためのパラメーターを設定する
*/
virtual void SetDepth(::Effekseer::Backend::TextureRef texture, const DepthReconstructionParameter& reconstructionParam);
/**
@brief
\~English Specify whether maintain gamma color in a linear color space
\~Japanese
*/
virtual void SetMaintainGammaColorInLinearColorSpace(bool value);
/**
@brief
\~English Get the graphics device
\~Japanese
*/
virtual Effekseer::Backend::GraphicsDeviceRef GetGraphicsDevice() const;
/**
@brief Get external shader settings
@note
For Effekseer tools
*/
virtual std::shared_ptr<ExternalShaderSettings> GetExternalShaderSettings() const;
/**
@brief Specify external shader settings
@note
For Effekseer tools
*/
virtual void SetExternalShaderSettings(const std::shared_ptr<ExternalShaderSettings>& settings);
};
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
} // namespace EffekseerRenderer
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
#endif // __EFFEKSEERRENDERER_RENDERER_H__
#ifndef __EFFEKSEERRENDERER_TEXTURELOADER_H__
#define __EFFEKSEERRENDERER_TEXTURELOADER_H__
#include <Effekseer.h>
namespace EffekseerRenderer
{
::Effekseer::TextureLoaderRef CreateTextureLoader(::Effekseer::Backend::GraphicsDeviceRef gprahicsDevice,
::Effekseer::FileInterfaceRef fileInterface = nullptr,
::Effekseer::ColorSpaceType colorSpaceType = ::Effekseer::ColorSpaceType::Gamma);
} // namespace EffekseerRenderer
#endif // __EFFEKSEERRENDERER_TEXTURELOADER_H__
#ifndef __EFFEKSEERRENDERER_GL_RENDERER_H__
#define __EFFEKSEERRENDERER_GL_RENDERER_H__
//----------------------------------------------------------------------------------
// Include
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Lib
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
namespace EffekseerRendererGL
{
::Effekseer::Backend::GraphicsDeviceRef CreateGraphicsDevice(OpenGLDeviceType deviceType, bool isExtensionsEnabled = true);
::Effekseer::MaterialLoaderRef CreateMaterialLoader(Effekseer::Backend::GraphicsDeviceRef graphicsDevice,
::Effekseer::FileInterfaceRef fileInterface = nullptr);
Effekseer::Backend::TextureRef CreateTexture(Effekseer::Backend::GraphicsDeviceRef graphicsDevice, GLuint buffer, bool hasMipmap, const std::function<void()>& onDisposed);
/**
@brief \~English Properties in a texture
\~Japanese
*/
struct TextureProperty
{
GLuint Buffer = 0;
};
TextureProperty GetTextureProperty(::Effekseer::Backend::TextureRef texture);
class Renderer;
using RendererRef = ::Effekseer::RefPtr<Renderer>;
class Renderer : public ::EffekseerRenderer::Renderer
{
protected:
Renderer()
{
}
virtual ~Renderer()
{
}
public:
/**
@brief
\~english Create an instance
\~japanese
@param squareMaxCount
\~english the number of maximum sprites
\~japanese
@param deviceType
\~english device type of opengl
\~japanese
@param isExtensionsEnabled
\~english whether does make extensions enabled.
\~japanese
@return
\~english instance
\~japanese
*/
static RendererRef Create(int32_t squareMaxCount, OpenGLDeviceType deviceType = OpenGLDeviceType::OpenGL2, bool isExtensionsEnabled = true);
static RendererRef Create(Effekseer::Backend::GraphicsDeviceRef graphicsDevice, int32_t squareMaxCount);
/**
@brief
*/
virtual int32_t GetSquareMaxCount() const = 0;
/**
@brief
@note
使
*/
virtual void SetSquareMaxCount(int32_t count) = 0;
/**
@brief
\~english Specify a background.
\~japanese
*/
virtual void SetBackground(GLuint background, bool hasMipmap = false) = 0;
/**
@brief
\~english get a device type
\~japanese
*/
virtual OpenGLDeviceType GetDeviceType() const = 0;
/**
@brief
\~english get whether VAO is supported
\~japanese VAOがサポートされているか取得する
*/
virtual bool IsVertexArrayObjectSupported() const = 0;
};
} // namespace EffekseerRendererGL
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
#endif // __EFFEKSEERRENDERER_GL_RENDERER_H__