1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00
Beef/BeefySysLib/gfx/DrawLayer.h

119 lines
2.8 KiB
C
Raw Normal View History

2019-08-23 11:56:54 -07:00
#pragma once
#include "Common.h"
#include "util/SLIList.h"
#include "fbx/FBXReader.h"
#include "gfx/RenderCmd.h"
#include "gfx/RenderDevice.h"
NS_BF_BEGIN;
class RenderWindow;
class Texture;
class Shader;
class ShaderPass;
class BFApp;
class Vertex3D;
class DrawLayer;
class RenderState;
#define MAX_TEXTURES 4
class DrawBatch : public RenderCmd
{
public:
2022-11-03 10:58:24 -07:00
DrawLayer* mDrawLayer;
2019-08-23 11:56:54 -07:00
int mId;
bool mIsVertexBufferHead;
bool mIsIndexBufferHead;
void* mVertices;
int mVtxSize;
int mVtxIdx;
int mAllocatedVertices;
2022-11-03 10:58:24 -07:00
2019-08-23 11:56:54 -07:00
uint16* mIndices;
int mIdxIdx;
int mAllocatedIndices;
2022-11-03 10:58:24 -07:00
2019-08-23 11:56:54 -07:00
Texture* mCurTextures[MAX_TEXTURES];
public:
DrawBatch();
virtual ~DrawBatch();
virtual void Free() override;
void Clear();
2022-11-03 10:58:24 -07:00
DrawBatch* AllocateChainedBatch(int minVtxCount, int minIdxCount);
2019-08-23 11:56:54 -07:00
virtual void* AllocTris(int vtxCount);
virtual void* AllocStrip(int vtxCount);
2022-11-03 10:58:24 -07:00
virtual void AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uint16** indicesOut, uint16* idxOfsOut);
2019-08-23 11:56:54 -07:00
};
#define DRAWBUFFER_CMDBUFFER_SIZE 64*1024
class DrawLayer
{
2022-11-03 10:58:24 -07:00
public:
2019-08-23 11:56:54 -07:00
SLIList<RenderCmd*> mRenderCmdList;
DrawBatch* mCurDrawBatch;
2022-11-03 10:58:24 -07:00
RenderWindow* mRenderWindow;
2019-08-23 11:56:54 -07:00
RenderDevice* mRenderDevice;
void* mIdxBuffer;
void* mVtxBuffer;
void* mRenderCmdBuffer;
int mIdxByteIdx;
2022-11-03 10:58:24 -07:00
int mVtxByteIdx;
2019-08-23 11:56:54 -07:00
int mRenderCmdByteIdx;
Texture* mCurTextures[MAX_TEXTURES];
2022-11-03 10:58:24 -07:00
2019-08-23 11:56:54 -07:00
public:
template <typename T>
T* AllocRenderCmd(int extraBytes = 0)
2022-11-03 10:58:24 -07:00
{
2019-08-23 11:56:54 -07:00
if (mRenderCmdByteIdx + sizeof(T) + extraBytes >= DRAWBUFFER_CMDBUFFER_SIZE)
{
mRenderCmdBuffer = mRenderDevice->mPooledRenderCmdBuffers.AllocMemoryBlock();
T* cmd = new(mRenderCmdBuffer) T();
cmd->mIsPoolHead = true;
mRenderCmdByteIdx = sizeof(T) + extraBytes;
return cmd;
}
T* cmd = new((uint8*)mRenderCmdBuffer + mRenderCmdByteIdx) T();
cmd->mIsPoolHead = false;
mRenderCmdByteIdx += sizeof(T) + extraBytes;
return cmd;
}
2022-11-03 10:58:24 -07:00
public:
2019-08-23 11:56:54 -07:00
void CloseDrawBatch();
2022-11-03 10:58:24 -07:00
virtual DrawBatch* CreateDrawBatch() = 0;
2019-08-23 11:56:54 -07:00
virtual DrawBatch* AllocateBatch(int minVtxCount, int minIdxCount);
void QueueRenderCmd(RenderCmd* renderCmd);
virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) = 0;
2021-05-12 07:24:29 -04:00
virtual void SetShaderConstantData(int usageIdx, int slotIdx, void* constData, int size) = 0;
virtual void SetShaderConstantDataTyped(int usageIdx, int slotIdx, void* constData, int size, int* typeData, int typeCount);
2019-08-23 11:56:54 -07:00
public:
DrawLayer();
virtual ~DrawLayer();
virtual void Draw();
virtual void Flush();
virtual void Clear();
virtual void* AllocTris(int vtxCount);
virtual void* AllocStrip(int vtxCount);
virtual void AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uint16** indicesOut, uint16* idxOfsOut);
virtual void SetTexture(int texIdx, Texture* texture);
};
NS_BF_END;