1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00
Beef/BeefySysLib/platform/sdl/GLRenderDevice.h

192 lines
4.3 KiB
C
Raw Normal View History

2019-08-23 11:56:54 -07:00
#pragma once
#include "Common.h"
2022-11-03 10:58:24 -07:00
#include "util/Dictionary.h"
2019-08-23 11:56:54 -07:00
#ifdef BF_PLATFORM_OPENGL_ES2
2022-11-03 10:58:24 -07:00
#include <SDL2/SDL_opengles2.h>
2019-08-23 11:56:54 -07:00
#else
2022-11-03 10:58:24 -07:00
#include <SDL2/SDL_opengl.h>
2019-08-23 11:56:54 -07:00
#endif
#include "gfx/Shader.h"
#include "gfx/Texture.h"
#include "gfx/RenderDevice.h"
#include "gfx/DrawLayer.h"
struct SDL_Window;
NS_BF_BEGIN;
class BFApp;
class GLRenderDevice;
class GLTexture : public Texture
{
public:
GLRenderDevice* mRenderDevice;
GLuint mGLTexture;
GLuint mGLTexture2;
2022-11-03 10:58:24 -07:00
ImageData* mImageData;
2019-08-23 11:56:54 -07:00
//IGL10RenderTargetView* mGLRenderTargetView;
public:
GLTexture();
~GLTexture();
virtual void PhysSetAsTarget();
2022-11-03 10:58:24 -07:00
virtual void Blt(ImageData* imageData, int x, int y) override;
2019-08-23 11:56:54 -07:00
};
class GLShaderParam : public ShaderParam
{
public:
GLint mGLVariable;
public:
GLShaderParam();
~GLShaderParam();
virtual void SetTexture(Texture* texture);
virtual void SetFloat4(float x, float y, float z, float w) override;
};
2022-11-03 10:58:24 -07:00
typedef Dictionary<String, GLShaderParam*> GLShaderParamMap;
2019-08-23 11:56:54 -07:00
class GLShader : public Shader
{
public:
//IGL10Effect* mGLEffect;
GLuint mGLVertexShader;
GLuint mGLFragmentShader;
GLuint mGLProgram;
GLint mAttribPosition;
GLint mAttribTexCoord0;
GLint mAttribColor;
GLint mAttribTex0;
GLint mAttribTex1;
2022-11-03 10:58:24 -07:00
GLShaderParamMap mParamsMap;
2019-08-23 11:56:54 -07:00
public:
GLShader();
~GLShader();
2022-11-03 10:58:24 -07:00
2019-08-23 11:56:54 -07:00
virtual ShaderParam* GetShaderParam(const StringImpl& name) override;
};
2022-11-03 10:58:24 -07:00
class GLSetTextureCmd : public RenderCmd
{
public:
int mTextureIdx;
Texture* mTexture;
public:
virtual void Render(RenderDevice* renderDevice, RenderWindow* renderWindow) override;
};
2019-08-23 11:56:54 -07:00
class GLDrawBatch : public DrawBatch
{
public:
//IGL10Buffer* mGLBuffer;
public:
2022-11-03 10:58:24 -07:00
GLDrawBatch();
2019-08-23 11:56:54 -07:00
~GLDrawBatch();
2022-11-03 10:58:24 -07:00
//virtual void Lock();
virtual void Render(RenderDevice* renderDevice, RenderWindow* renderWindow) override;
2019-08-23 11:56:54 -07:00
};
class GLDrawLayer : public DrawLayer
{
public:
virtual DrawBatch* CreateDrawBatch();
2022-11-03 10:58:24 -07:00
virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) override;
virtual void SetShaderConstantData(int usageIdx, int slotIdx, void* constData, int size) override;
2019-08-23 11:56:54 -07:00
public:
GLDrawLayer();
~GLDrawLayer();
};
class GLRenderWindow : public RenderWindow
{
public:
SDL_Window* mSDLWindow;
GLRenderDevice* mRenderDevice;
//IGLGISwapChain* mGLSwapChain;
//IGL10Texture2D* mGLBackBuffer;
//IGL10RenderTargetView* mGLRenderTargetView;
bool mResizePending;
int mPendingWidth;
2022-11-03 10:58:24 -07:00
int mPendingHeight;
2019-08-23 11:56:54 -07:00
public:
virtual void PhysSetAsTarget();
public:
GLRenderWindow(GLRenderDevice* renderDevice, SDL_Window* sdlWindow);
~GLRenderWindow();
void SetAsTarget() override;
void Resized() override;
virtual void Present() override;
void CopyBitsTo(uint32* dest, int width, int height);
};
typedef std::vector<GLDrawBatch*> GLDrawBatchVector;
class GLRenderDevice : public RenderDevice
{
public:
//IGLGIFactory* mGLGIFactory;
//IGL10Device* mGLDevice;
//IGL10BlendState* mGLNormalBlendState;
//IGL10BlendState* mGLAdditiveBlendState;
//IGL10RasterizerState* mGLRasterizerStateClipped;
//IGL10RasterizerState* mGLRasterizerStateUnclipped;
2022-11-03 10:58:24 -07:00
GLuint mGLVAO;
2019-08-23 11:56:54 -07:00
GLuint mGLVertexBuffer;
GLuint mGLIndexBuffer;
GLuint mBlankTexture;
2022-11-03 10:58:24 -07:00
GLShader* mCurShader;
2019-08-23 11:56:54 -07:00
bool mHasVSync;
GLDrawBatchVector mDrawBatchPool;
GLDrawBatch* mFreeBatchHead;
public:
2022-11-03 10:58:24 -07:00
//virtual void PhysSetAdditive(bool additive);
//virtual void PhysSetShader(Shader* shaderPass);
2019-08-23 11:56:54 -07:00
virtual void PhysSetRenderWindow(RenderWindow* renderWindow);
2022-11-03 10:58:24 -07:00
virtual void PhysSetRenderState(RenderState* renderState) override;
virtual void PhysSetRenderTarget(Texture* renderTarget) override;
2019-08-23 11:56:54 -07:00
public:
GLRenderDevice();
virtual ~GLRenderDevice();
bool Init(BFApp* app) override;
void FrameStart() override;
void FrameEnd() override;
2022-11-03 10:58:24 -07:00
Texture* LoadTexture(ImageData* imageData, int flags) override;
Shader* LoadShader(const StringImpl& fileName, VertexDefinition* vertexDefinition) override;
2019-08-23 11:56:54 -07:00
Texture* CreateRenderTarget(int width, int height, bool destAlpha) override;
2022-11-03 10:58:24 -07:00
virtual Texture* CreateDynTexture(int width, int height) override { return NULL; }
virtual void SetRenderState(RenderState* renderState) override;
/*void SetShader(Shader* shader) override;
2019-08-23 11:56:54 -07:00
virtual void SetClip(float x, float y, float width, float height) override;
2022-11-03 10:58:24 -07:00
virtual void DisableClip() override;*/
2019-08-23 11:56:54 -07:00
};
NS_BF_END;