mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
SDL/OGL platform improvements
This commit is contained in:
parent
213aea8c82
commit
258a6653f9
16 changed files with 711 additions and 1141 deletions
|
@ -32,12 +32,12 @@ static int BfAllocHook(int nAllocType, void *pvData,
|
|||
size_t nSize, int nBlockUse, long lRequest,
|
||||
const unsigned char * szFileName, int nLine)
|
||||
{
|
||||
if (gLastReqId == lRequest)
|
||||
return TRUE;
|
||||
if (gLastReqId == lRequest)
|
||||
return TRUE;
|
||||
|
||||
gLastReqId = lRequest;
|
||||
gLastReqId = lRequest;
|
||||
if (szFileName == NULL)
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
|
||||
/*char str[1024];
|
||||
sprintf(str, "Alloc: %d File: %s Line: %d\n", lRequest, szFileName, nLine);
|
||||
|
@ -56,7 +56,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|||
//_CrtSetAllocHook(BfAllocHook);
|
||||
#endif
|
||||
|
||||
switch (fdwReason)
|
||||
switch (fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
gDLLInstance = hinstDLL;
|
||||
|
@ -92,7 +92,7 @@ BF_EXPORT void BF_CALLTYPE BFApp_Create()
|
|||
BF_EXPORT void BF_CALLTYPE BFApp_Delete()
|
||||
{
|
||||
delete gBFApp;
|
||||
gBFApp = NULL;
|
||||
gBFApp = NULL;
|
||||
FTFontManager::ClearCache();
|
||||
|
||||
//OutputDebugStrF("Deleting App\n");
|
||||
|
@ -105,16 +105,16 @@ BF_EXPORT void BF_CALLTYPE BFApp_Delete()
|
|||
//{
|
||||
// FT_Library library; /* handle to library */
|
||||
// FT_Face face; /* handle to face object */
|
||||
//
|
||||
// auto error = FT_Init_FreeType(&library);
|
||||
//
|
||||
// auto error = FT_Init_FreeType(&library);
|
||||
// error = FT_New_Face(library, "/temp/SourceCodePro-Regular.ttf", 0, &face);
|
||||
// if (error == FT_Err_Unknown_File_Format)
|
||||
// {
|
||||
//
|
||||
//
|
||||
// }
|
||||
// else if (error)
|
||||
// {
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// error = FT_Set_Char_Size(
|
||||
|
@ -127,7 +127,7 @@ BF_EXPORT void BF_CALLTYPE BFApp_Delete()
|
|||
// String str = ".cHasDebugFlags";
|
||||
//
|
||||
// PNGData image;
|
||||
// image.CreateNew(256, 256);
|
||||
// image.CreateNew(256, 256);
|
||||
// for (int i = 0; i < 256 * 256; i++)
|
||||
// image.mBits[i] = 0xFF000000;
|
||||
//
|
||||
|
@ -201,12 +201,12 @@ BF_EXPORT void BF_CALLTYPE BFApp_SetRefreshRate(int rate)
|
|||
}
|
||||
|
||||
BF_EXPORT const char* BF_CALLTYPE BFApp_GetInstallDir()
|
||||
{
|
||||
{
|
||||
return gBFApp->mInstallDir.c_str();
|
||||
}
|
||||
|
||||
BF_EXPORT const char* BF_CALLTYPE BFApp_GetDataDir()
|
||||
{
|
||||
{
|
||||
return gBFApp->mDataDir.c_str();
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ BF_EXPORT void BF_CALLTYPE BFApp_RehupMouse()
|
|||
}
|
||||
|
||||
BF_EXPORT const char* BF_CALLTYPE BFApp_EnumerateInputDevices()
|
||||
{
|
||||
{
|
||||
String& outString = *gBeefySys_TLStrReturn.Get();
|
||||
outString = gBFApp->EnumerateInputDevices();
|
||||
return outString.c_str();
|
||||
|
@ -284,7 +284,7 @@ BF_EXPORT intptr BF_CALLTYPE BFApp_GetCriticalThreadId(int idx)
|
|||
|
||||
///
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE BFWindow_SetCallbacks(BFWindow* window, BFWindow_MovedFunc movedFunc, BFWindow_CloseQueryFunc closeQueryFunc, BFWindow_ClosedFunc closedFunc,
|
||||
BF_EXPORT void BF_CALLTYPE BFWindow_SetCallbacks(BFWindow* window, BFWindow_MovedFunc movedFunc, BFWindow_CloseQueryFunc closeQueryFunc, BFWindow_ClosedFunc closedFunc,
|
||||
BFWindow_GotFocusFunc gotFocusFunc, BFWindow_LostFocusFunc lostFocusFunc,
|
||||
BFWindow_KeyCharFunc keyCharFunc, BFWindow_KeyDownFunc keyDownFunc, BFWindow_KeyUpFunc keyUpFunc, BFWindow_HitTestFunc hitTestFunc,
|
||||
BFWindow_MouseMove mouseMoveFunc, BFWindow_MouseProxyMove mouseProxyMoveFunc,
|
||||
|
@ -293,7 +293,7 @@ BF_EXPORT void BF_CALLTYPE BFWindow_SetCallbacks(BFWindow* window, BFWindow_Move
|
|||
{
|
||||
window->mMovedFunc = movedFunc;
|
||||
window->mCloseQueryFunc = closeQueryFunc;
|
||||
window->mClosedFunc = closedFunc;
|
||||
window->mClosedFunc = closedFunc;
|
||||
window->mGotFocusFunc = gotFocusFunc;
|
||||
window->mLostFocusFunc = lostFocusFunc;
|
||||
window->mKeyCharFunc = keyCharFunc;
|
||||
|
@ -420,8 +420,8 @@ BF_EXPORT TextureSegment* BF_CALLTYPE Gfx_CreateRenderTarget(int width, int heig
|
|||
{
|
||||
Texture* texture = gBFApp->mRenderDevice->CreateRenderTarget(width, height, destAlpha != 0);
|
||||
|
||||
TextureSegment* aTextureSegment = new TextureSegment();
|
||||
aTextureSegment->InitFromTexture(texture);
|
||||
TextureSegment* aTextureSegment = new TextureSegment();
|
||||
aTextureSegment->InitFromTexture(texture);
|
||||
return aTextureSegment;
|
||||
}
|
||||
|
||||
|
@ -438,10 +438,10 @@ BF_EXPORT TextureSegment* BF_CALLTYPE Gfx_LoadTexture(const char* fileName, int
|
|||
{
|
||||
Texture* texture = gBFApp->mRenderDevice->LoadTexture(fileName, flags);
|
||||
if (texture == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
TextureSegment* aTextureSegment = new TextureSegment();
|
||||
aTextureSegment->InitFromTexture(texture);
|
||||
TextureSegment* aTextureSegment = new TextureSegment();
|
||||
aTextureSegment->InitFromTexture(texture);
|
||||
return aTextureSegment;
|
||||
}
|
||||
|
||||
|
@ -512,12 +512,12 @@ BF_EXPORT void BF_CALLTYPE Gfx_SetDrawSize(TextureSegment* textureSegment, int w
|
|||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE Gfx_DrawTextureSegment(TextureSegment* textureSegment, float a, float b, float c, float d, float tx, float ty, float z, uint32 color, int pixelSnapping)
|
||||
{
|
||||
{
|
||||
DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
|
||||
drawLayer->SetTexture(0, textureSegment->mTexture);
|
||||
DefaultVertex3D* v = (DefaultVertex3D*)drawLayer->AllocStrip(4);
|
||||
|
||||
if ((pixelSnapping == 1) ||
|
||||
if ((pixelSnapping == 1) ||
|
||||
((pixelSnapping == 2) && (a == 1.0f) && (b == 0) && (c == 0) && (d == 1.0f)))
|
||||
{
|
||||
tx = (float) (int) (tx + 100000) - 100000;
|
||||
|
@ -527,13 +527,13 @@ BF_EXPORT void BF_CALLTYPE Gfx_DrawTextureSegment(TextureSegment* textureSegment
|
|||
a *= textureSegment->mScaleX;
|
||||
b *= textureSegment->mScaleX;
|
||||
c *= textureSegment->mScaleY;
|
||||
d *= textureSegment->mScaleY;
|
||||
d *= textureSegment->mScaleY;
|
||||
|
||||
v[0].Set(tx, ty, z, textureSegment->mU1, textureSegment->mV1, color);
|
||||
v[1].Set(tx + a, ty + b, z, textureSegment->mU2, textureSegment->mV1, color);
|
||||
v[2].Set(tx + c, ty + d, z, textureSegment->mU1, textureSegment->mV2, color);
|
||||
v[2].Set(tx + c, ty + d, z, textureSegment->mU1, textureSegment->mV2, color);
|
||||
v[3].Set(tx + (a + c), ty + (b + d), z, textureSegment->mU2, textureSegment->mV2, color);
|
||||
|
||||
|
||||
gPixelsDrawn += (int)((a + b) * (c + d));
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ static DefaultVertex3D* gCurAllocVertices = NULL;
|
|||
|
||||
BF_EXPORT void BF_CALLTYPE Gfx_AllocTris(TextureSegment* textureSegment, int vtxCount)
|
||||
{
|
||||
gCurTextureSegment = textureSegment;
|
||||
gCurTextureSegment = textureSegment;
|
||||
DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
|
||||
drawLayer->SetTexture(0, textureSegment->mTexture);
|
||||
gCurAllocVertices = (DefaultVertex3D*)gBFApp->mRenderDevice->mCurDrawLayer->AllocTris(vtxCount);
|
||||
|
@ -550,8 +550,8 @@ BF_EXPORT void BF_CALLTYPE Gfx_AllocTris(TextureSegment* textureSegment, int vtx
|
|||
|
||||
BF_EXPORT void BF_CALLTYPE Gfx_SetDrawVertex(int idx, float x, float y, float z, float u, float v, uint32 color)
|
||||
{
|
||||
gCurAllocVertices[idx].Set(x, y, z,
|
||||
gCurTextureSegment->mU1 + u * (gCurTextureSegment->mU2 - gCurTextureSegment->mU1),
|
||||
gCurAllocVertices[idx].Set(x, y, z,
|
||||
gCurTextureSegment->mU1 + u * (gCurTextureSegment->mU2 - gCurTextureSegment->mU1),
|
||||
gCurTextureSegment->mV1 + v * (gCurTextureSegment->mV2 - gCurTextureSegment->mV1), color);
|
||||
}
|
||||
|
||||
|
@ -565,7 +565,7 @@ BF_EXPORT void BF_CALLTYPE Gfx_DrawQuads(TextureSegment* textureSegment, Default
|
|||
/*for (int vtxIdx = 0; vtxIdx < vtxCount; vtxIdx += 4)
|
||||
{
|
||||
Vertex3D* v = gBFApp->mRenderDevice->mCurDrawLayer->AllocStrip(textureSegment->mTexture, drawType != 0, 4);
|
||||
|
||||
|
||||
v[0] = vertices[vtxIdx];
|
||||
v[1] = vertices[vtxIdx + 1];
|
||||
v[2] = vertices[vtxIdx + 2];
|
||||
|
@ -573,7 +573,7 @@ BF_EXPORT void BF_CALLTYPE Gfx_DrawQuads(TextureSegment* textureSegment, Default
|
|||
}
|
||||
|
||||
return;*/
|
||||
|
||||
|
||||
DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
|
||||
drawLayer->SetTexture(0, textureSegment->mTexture);
|
||||
|
||||
|
@ -631,24 +631,24 @@ BF_EXPORT void BF_CALLTYPE Gfx_DrawIndexedVertices(int vertexSize, void* vtxData
|
|||
for (int idxIdx = 0; idxIdx < idxCount; idxIdx++)
|
||||
*(drawBatchIdxPtr++) = *(idxPtr++) + idxOfs;
|
||||
|
||||
memcpy(drawBatchVtxPtr, vtxData, vertexSize * vtxCount);
|
||||
memcpy(drawBatchVtxPtr, vtxData, vertexSize * vtxCount);
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE Gfx_DrawIndexedVertices2D(int vertexSize, void* vtxData, int vtxCount, uint16* idxData, int idxCount, float a, float b, float c, float d, float tx, float ty, float z)
|
||||
{
|
||||
DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
|
||||
|
||||
|
||||
uint16 idxOfs;
|
||||
void* drawBatchVtxPtr;
|
||||
uint16* drawBatchIdxPtr;
|
||||
gBFApp->mRenderDevice->mCurDrawLayer->AllocIndexed(vtxCount, idxCount, (void**)&drawBatchVtxPtr, &drawBatchIdxPtr, &idxOfs);
|
||||
BF_ASSERT(gBFApp->mRenderDevice->mCurDrawLayer->mCurDrawBatch->mVtxSize == vertexSize);
|
||||
BF_ASSERT(gBFApp->mRenderDevice->mCurDrawLayer->mCurDrawBatch->mVtxSize == vertexSize);
|
||||
|
||||
uint16* idxPtr = idxData;
|
||||
for (int idxIdx = 0; idxIdx < idxCount; idxIdx++)
|
||||
for (int idxIdx = 0; idxIdx < idxCount; idxIdx++)
|
||||
*(drawBatchIdxPtr++) = *(idxPtr++) + idxOfs;
|
||||
|
||||
//memcpy(drawBatchIdxPtr, idxData, sizeof(uint16) * idxCount);
|
||||
//memcpy(drawBatchIdxPtr, idxData, sizeof(uint16) * idxCount);
|
||||
//memcpy(drawBatchVtxPtr, vtxData, vertexSize * vtxCount);
|
||||
|
||||
void* vtxPtr = vtxData;
|
||||
|
@ -713,12 +713,12 @@ BF_EXPORT void BF_CALLTYPE RenderState_SetWireframe(RenderState* renderState, bo
|
|||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE RenderState_SetClip(RenderState* renderState, float x, float y, float width, float height)
|
||||
{
|
||||
{
|
||||
BF_ASSERT((width >= 0) && (height >= 0));
|
||||
renderState->mClipRect.mX = x;
|
||||
renderState->mClipRect.mY = y;
|
||||
renderState->mClipRect.mWidth = width;
|
||||
renderState->mClipRect.mHeight = height;
|
||||
renderState->mClipRect.mHeight = height;
|
||||
if (!renderState->mClipped)
|
||||
renderState->SetClipped(true);
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ BF_EXPORT Shader* BF_CALLTYPE Gfx_LoadShader(const char* fileName, VertexDefinit
|
|||
BF_EXPORT void BF_CALLTYPE Gfx_SetRenderState(RenderState* renderState)
|
||||
{
|
||||
BF_ASSERT(renderState->mShader != NULL);
|
||||
gBFApp->mRenderDevice->SetRenderState(renderState);
|
||||
gBFApp->mRenderDevice->SetRenderState(renderState);
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE Gfx_Shader_Delete(Shader* shader)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue