1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 23:36:00 +02:00

Additional 3d support

This commit is contained in:
Brian Fiete 2021-05-12 07:24:29 -04:00
parent 70680fdf39
commit f26df6c86b
32 changed files with 2370 additions and 165 deletions

View file

@ -727,7 +727,7 @@ namespace Beefy
0.10f, 0.00f, 1.05f, 0,
0, 0, 0, 1);*/
mGraphics.SetShaderConstantData(0, &mColorMatrix.ValueRef, mColorMatrixDataDef);
mGraphics.SetVertexShaderConstantData(0, &mColorMatrix.ValueRef, mColorMatrixDataDef);
}
window.Draw(mGraphics);
window.PostDraw(mGraphics);

View file

@ -78,7 +78,11 @@ namespace Beefy.gfx
protected DisposeProxy mClipDisposeProxy ~ delete _;
const int32 CLIP_STACK_SIZE = 256;
public Rect?[] mClipStack = new Rect?[CLIP_STACK_SIZE] ~ delete _;
public bool mTexWrap;
protected DisposeProxy mTexWrapDisableProxy ~ delete _;
protected DisposeProxy mTexWrapEnableProxy ~ delete _;
public int32 mClipStackIdx = 0;
public Rect? mClipRect = null;
@ -106,6 +110,10 @@ namespace Beefy.gfx
mClipDisposeProxy = new DisposeProxy();
mClipDisposeProxy.mDisposeProxyDelegate = new => PopClip;
mRenderStateDisposeProxy = new DisposeProxy();
mTexWrapDisableProxy = new DisposeProxy();
mTexWrapDisableProxy.mDisposeProxyDelegate = new () => { PopTexWrap(false); };
mTexWrapEnableProxy = new DisposeProxy();
mTexWrapEnableProxy.mDisposeProxyDelegate = new () => { PopTexWrap(true); };
mWhiteDot = Image.LoadFromFile("!white");
@ -341,15 +349,15 @@ namespace Beefy.gfx
Rect rectThing = mClipRect.Value;
mClipRect = rectThing;
var clipRenderState = AllocRenderState(mDefaultShader, mClipRect);
var clipRenderState = AllocRenderState(mDefaultShader, mClipRect, mTexWrap);
//clipRenderState.ClipRect = mClipRect;
PushRenderState(clipRenderState);
PushRenderState(clipRenderState);
return mClipDisposeProxy;
}
RenderState AllocRenderState(Shader shader, Rect? clipRect)
RenderState AllocRenderState(Shader shader, Rect? clipRect, bool texWrap)
{
RenderState renderState = null;
var curRenderState = mRenderStateStack[mRenderStateStackIdx];
@ -365,6 +373,7 @@ namespace Beefy.gfx
}
else
renderState = RenderState.Create(curRenderState);
renderState.TexWrap = texWrap;
renderState.Shader = shader;
renderState.ClipRect = clipRect;
return renderState;
@ -375,16 +384,33 @@ namespace Beefy.gfx
mClipStackIdx++;
mClipStack[mClipStackIdx] = null;
mClipRect = null;
var clipRenderState = AllocRenderState(mDefaultShader, null);
var clipRenderState = AllocRenderState(mDefaultShader, mClipRect, mTexWrap);
//clipRenderState.ClipRect = null;
PushRenderState(clipRenderState);
return mClipDisposeProxy;
}
public DisposeProxy PushTexWrap(bool texWrap)
{
bool prevTexWrap = mTexWrap;
mTexWrap = texWrap;
var clipRenderState = AllocRenderState(mDefaultShader, mClipRect, mTexWrap);
PushRenderState(clipRenderState);
return prevTexWrap ? mTexWrapEnableProxy : mTexWrapDisableProxy;
}
protected void PopTexWrap(bool texWrap)
{
mTexWrap = texWrap;
PopRenderState();
}
public void PushTextRenderState()
{
var textRenderState = AllocRenderState(mTextShader, mClipRect);
var textRenderState = AllocRenderState(mTextShader, mClipRect, mTexWrap);
//textRenderState.ClipRect = mClipRect;
//textRenderState.Shader = mTextShader;
PushRenderState(textRenderState);
@ -419,10 +445,10 @@ namespace Beefy.gfx
static extern void Gfx_DrawIndexedVertices2D(int32 vertexSize, void* vtxData, int32 vtxCount, uint16* idxData, int32 idxCount, float a, float b, float c, float d, float tx, float ty, float z);
[CallingConvention(.Stdcall), CLink]
static extern void Gfx_SetShaderConstantData(int32 slotIdx, void* data, int32 size);
static extern void Gfx_SetShaderConstantData(int32 usageIdx, int32 slotIdx, void* data, int32 size);
[CallingConvention(.Stdcall), CLink]
static extern void Gfx_SetShaderConstantDataTyped(int32 slotIdx, void* data, int32 size, int32* typeData, int32 typeCount);
static extern void Gfx_SetShaderConstantDataTyped(int usageIdx, int32 slotIdx, void* data, int32 size, int32* typeData, int32 typeCount);
[CallingConvention(.Stdcall), CLink]
static extern void Gfx_DrawQuads(void* textureSegment, Vertex3D* vertices, int32 vtxCount);
@ -778,22 +804,33 @@ namespace Beefy.gfx
mMatrix.a, mMatrix.b, mMatrix.c, mMatrix.d, mMatrix.tx, mMatrix.ty, ZDepth);
}
public void SetShaderConstantData(int slotIdx, void* data, int size)
public void SetVertexShaderConstantData(int slotIdx, void* data, int size)
{
Gfx_SetShaderConstantData((int32)slotIdx, data, (int32)size);
Gfx_SetShaderConstantData(0, (int32)slotIdx, data, (int32)size);
}
public void SetShaderConstantData(int32 slotIdx, void* data, ConstantDataDefinition constantDataDefinition)
public void SetPixelShaderConstantData(int slotIdx, void* data, int size)
{
Gfx_SetShaderConstantData(1, (int32)slotIdx, data, (int32)size);
}
public void SetVertexShaderConstantData(int32 slotIdx, void* data, ConstantDataDefinition constantDataDefinition)
{
int32* dataTypesPtr = (int32*)constantDataDefinition.mDataTypes.CArray();
Gfx_SetShaderConstantDataTyped(slotIdx, data, constantDataDefinition.mDataSize, dataTypesPtr, (int32)constantDataDefinition.mDataTypes.Count);
Gfx_SetShaderConstantDataTyped(0, slotIdx, data, constantDataDefinition.mDataSize, dataTypesPtr, (int32)constantDataDefinition.mDataTypes.Count);
}
public void SetShaderConstantData(int32 slotIdx, Matrix4 matrix)
public void SetVertexShaderConstantData(int32 slotIdx, Matrix4 matrix)
{
var mtx = matrix;
Gfx_SetShaderConstantData(0, slotIdx, &mtx, (int32)sizeof(Matrix4));
}
public void SetPixelShaderConstantData(int32 slotIdx, Matrix4 matrix)
{
var mtx = matrix;
Gfx_SetShaderConstantData(slotIdx, &mtx, (int32)sizeof(Matrix4));
}
Gfx_SetShaderConstantData(1, slotIdx, &mtx, (int32)sizeof(Matrix4));
}
public float DrawString(StringView theString, float x, float y, FontAlign alignment = FontAlign.Left, float width = 0, FontOverflowMode overflowMode = FontOverflowMode.Overflow, FontMetrics* fontMetrics = null)
{

View file

@ -90,15 +90,24 @@ namespace Beefy.gfx
public void* mNativeModelDef;
public float mFrameRate;
public int32 mJointCount;
public Animation[] mAnims;
public Dictionary<String, Animation> mAnimMap = new Dictionary<String, Animation>();
public Animation[] mAnims ~ DeleteContainerAndItems!(_);
public Dictionary<String, Animation> mAnimMap = new Dictionary<String, Animation>() ~ DeleteDictionaryAndKeys!(_);
[CallingConvention(.Stdcall), CLink]
extern static void* Res_OpenFBX(String fileName, void* nativeVertexDef);
extern static void* Res_OpenFBX(char8* fileName, void* nativeVertexDef);
[CallingConvention(.Stdcall), CLink]
extern static void* Res_OpenGLTF(char8* fileName, char8* baseDir, void* nativeVertexDef);
[CallingConvention(.Stdcall), CLink]
extern static void* Res_OpenModel(char8* fileName, char8* baseDir, void* nativeVertexDef);
[CallingConvention(.Stdcall), CLink]
extern static void* ModelDef_CreateModelInstance(void* nativeModel);
[CallingConvention(.Stdcall), CLink]
extern static char8* ModelDef_GetInfo(void* nativeModel);
[CallingConvention(.Stdcall), CLink]
extern static float ModelDef_GetFrameRate(void* nativeModel);
@ -111,6 +120,12 @@ namespace Beefy.gfx
[CallingConvention(.Stdcall), CLink]
extern static void* ModelDef_GetAnimation(void* nativeModel, int32 animIdx);
[CallingConvention(.Stdcall), CLink]
extern static void ModelDef_SetTextures(void* nativeModel, int32 meshIdx, int32 primitivesIdx, char8** paths, int32 pathCount);
[CallingConvention(.Stdcall), CLink]
extern static Span<uint8> Res_SerializeModel(void* nativeModel);
this(void* nativeModelDef)
{
mNativeModelDef = nativeModelDef;
@ -129,9 +144,15 @@ namespace Beefy.gfx
}
}
public static ModelDef LoadModel(String fileName)
public static ModelDef LoadModel(String fileName, String baseDir)
{
void* nativeModelDef = Res_OpenFBX(fileName, VertexDef.sVertexDefinition.mNativeVertexDefinition);
void* nativeModelDef = null;
if (fileName.EndsWith(".bfm", .OrdinalIgnoreCase))
nativeModelDef = Res_OpenModel(fileName, baseDir, VertexDef.sVertexDefinition.mNativeVertexDefinition);
else if (fileName.EndsWith(".fbx", .OrdinalIgnoreCase))
nativeModelDef = Res_OpenFBX(fileName, VertexDef.sVertexDefinition.mNativeVertexDefinition);
else
nativeModelDef = Res_OpenGLTF(fileName, baseDir, VertexDef.sVertexDefinition.mNativeVertexDefinition);
if (nativeModelDef == null)
return null;
return new ModelDef(nativeModelDef);
@ -150,6 +171,22 @@ namespace Beefy.gfx
{
return mAnimMap[name];
}
public void GetInfo(String str)
{
str.Append(ModelDef_GetInfo(mNativeModelDef));
}
public void SetTextures(int meshIdx, int primitivesIdx, Span<char8*> paths)
{
ModelDef_SetTextures(mNativeModelDef, (.)meshIdx, (.)primitivesIdx, paths.Ptr, (.)paths.Length);
}
public void Serialize(List<uint8> data)
{
var span = Res_SerializeModel(mNativeModelDef);
data.AddRange(span);
}
}
public class ModelInstance : RenderCmd

View file

@ -31,6 +31,9 @@ namespace Beefy.gfx
[CallingConvention(.Stdcall), CLink]
static extern void RenderState_SetClip(void* renderState, float x, float y, float width, float height);
[CallingConvention(.Stdcall), CLink]
static extern void RenderState_SetTexWrap(void* renderState, bool texWrap);
[CallingConvention(.Stdcall), CLink]
static extern void RenderState_DisableClip(void* renderState);
@ -103,7 +106,15 @@ namespace Beefy.gfx
else
RenderState_DisableClip(mNativeRenderState);
}
}
}
public bool TexWrap
{
set
{
RenderState_SetTexWrap(mNativeRenderState, value);
}
}
}
#else
public class RenderState