1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

SDL/OGL platform improvements

This commit is contained in:
Brian Fiete 2022-11-03 10:58:24 -07:00
parent 213aea8c82
commit 258a6653f9
16 changed files with 711 additions and 1141 deletions

View file

@ -32,12 +32,12 @@ static int BfAllocHook(int nAllocType, void *pvData,
size_t nSize, int nBlockUse, long lRequest, size_t nSize, int nBlockUse, long lRequest,
const unsigned char * szFileName, int nLine) const unsigned char * szFileName, int nLine)
{ {
if (gLastReqId == lRequest) if (gLastReqId == lRequest)
return TRUE; return TRUE;
gLastReqId = lRequest; gLastReqId = lRequest;
if (szFileName == NULL) if (szFileName == NULL)
return TRUE; return TRUE;
/*char str[1024]; /*char str[1024];
sprintf(str, "Alloc: %d File: %s Line: %d\n", lRequest, szFileName, nLine); 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); //_CrtSetAllocHook(BfAllocHook);
#endif #endif
switch (fdwReason) switch (fdwReason)
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
gDLLInstance = hinstDLL; gDLLInstance = hinstDLL;
@ -92,7 +92,7 @@ BF_EXPORT void BF_CALLTYPE BFApp_Create()
BF_EXPORT void BF_CALLTYPE BFApp_Delete() BF_EXPORT void BF_CALLTYPE BFApp_Delete()
{ {
delete gBFApp; delete gBFApp;
gBFApp = NULL; gBFApp = NULL;
FTFontManager::ClearCache(); FTFontManager::ClearCache();
//OutputDebugStrF("Deleting App\n"); //OutputDebugStrF("Deleting App\n");
@ -105,16 +105,16 @@ BF_EXPORT void BF_CALLTYPE BFApp_Delete()
//{ //{
// FT_Library library; /* handle to library */ // FT_Library library; /* handle to library */
// FT_Face face; /* handle to face object */ // 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); // error = FT_New_Face(library, "/temp/SourceCodePro-Regular.ttf", 0, &face);
// if (error == FT_Err_Unknown_File_Format) // if (error == FT_Err_Unknown_File_Format)
// { // {
// //
// } // }
// else if (error) // else if (error)
// { // {
// //
// } // }
// //
// error = FT_Set_Char_Size( // error = FT_Set_Char_Size(
@ -127,7 +127,7 @@ BF_EXPORT void BF_CALLTYPE BFApp_Delete()
// String str = ".cHasDebugFlags"; // String str = ".cHasDebugFlags";
// //
// PNGData image; // PNGData image;
// image.CreateNew(256, 256); // image.CreateNew(256, 256);
// for (int i = 0; i < 256 * 256; i++) // for (int i = 0; i < 256 * 256; i++)
// image.mBits[i] = 0xFF000000; // 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() BF_EXPORT const char* BF_CALLTYPE BFApp_GetInstallDir()
{ {
return gBFApp->mInstallDir.c_str(); return gBFApp->mInstallDir.c_str();
} }
BF_EXPORT const char* BF_CALLTYPE BFApp_GetDataDir() BF_EXPORT const char* BF_CALLTYPE BFApp_GetDataDir()
{ {
return gBFApp->mDataDir.c_str(); return gBFApp->mDataDir.c_str();
} }
@ -261,7 +261,7 @@ BF_EXPORT void BF_CALLTYPE BFApp_RehupMouse()
} }
BF_EXPORT const char* BF_CALLTYPE BFApp_EnumerateInputDevices() BF_EXPORT const char* BF_CALLTYPE BFApp_EnumerateInputDevices()
{ {
String& outString = *gBeefySys_TLStrReturn.Get(); String& outString = *gBeefySys_TLStrReturn.Get();
outString = gBFApp->EnumerateInputDevices(); outString = gBFApp->EnumerateInputDevices();
return outString.c_str(); 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_GotFocusFunc gotFocusFunc, BFWindow_LostFocusFunc lostFocusFunc,
BFWindow_KeyCharFunc keyCharFunc, BFWindow_KeyDownFunc keyDownFunc, BFWindow_KeyUpFunc keyUpFunc, BFWindow_HitTestFunc hitTestFunc, BFWindow_KeyCharFunc keyCharFunc, BFWindow_KeyDownFunc keyDownFunc, BFWindow_KeyUpFunc keyUpFunc, BFWindow_HitTestFunc hitTestFunc,
BFWindow_MouseMove mouseMoveFunc, BFWindow_MouseProxyMove mouseProxyMoveFunc, 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->mMovedFunc = movedFunc;
window->mCloseQueryFunc = closeQueryFunc; window->mCloseQueryFunc = closeQueryFunc;
window->mClosedFunc = closedFunc; window->mClosedFunc = closedFunc;
window->mGotFocusFunc = gotFocusFunc; window->mGotFocusFunc = gotFocusFunc;
window->mLostFocusFunc = lostFocusFunc; window->mLostFocusFunc = lostFocusFunc;
window->mKeyCharFunc = keyCharFunc; 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); Texture* texture = gBFApp->mRenderDevice->CreateRenderTarget(width, height, destAlpha != 0);
TextureSegment* aTextureSegment = new TextureSegment(); TextureSegment* aTextureSegment = new TextureSegment();
aTextureSegment->InitFromTexture(texture); aTextureSegment->InitFromTexture(texture);
return aTextureSegment; return aTextureSegment;
} }
@ -438,10 +438,10 @@ BF_EXPORT TextureSegment* BF_CALLTYPE Gfx_LoadTexture(const char* fileName, int
{ {
Texture* texture = gBFApp->mRenderDevice->LoadTexture(fileName, flags); Texture* texture = gBFApp->mRenderDevice->LoadTexture(fileName, flags);
if (texture == NULL) if (texture == NULL)
return NULL; return NULL;
TextureSegment* aTextureSegment = new TextureSegment(); TextureSegment* aTextureSegment = new TextureSegment();
aTextureSegment->InitFromTexture(texture); aTextureSegment->InitFromTexture(texture);
return aTextureSegment; 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) 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* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
drawLayer->SetTexture(0, textureSegment->mTexture); drawLayer->SetTexture(0, textureSegment->mTexture);
DefaultVertex3D* v = (DefaultVertex3D*)drawLayer->AllocStrip(4); DefaultVertex3D* v = (DefaultVertex3D*)drawLayer->AllocStrip(4);
if ((pixelSnapping == 1) || if ((pixelSnapping == 1) ||
((pixelSnapping == 2) && (a == 1.0f) && (b == 0) && (c == 0) && (d == 1.0f))) ((pixelSnapping == 2) && (a == 1.0f) && (b == 0) && (c == 0) && (d == 1.0f)))
{ {
tx = (float) (int) (tx + 100000) - 100000; tx = (float) (int) (tx + 100000) - 100000;
@ -527,13 +527,13 @@ BF_EXPORT void BF_CALLTYPE Gfx_DrawTextureSegment(TextureSegment* textureSegment
a *= textureSegment->mScaleX; a *= textureSegment->mScaleX;
b *= textureSegment->mScaleX; b *= textureSegment->mScaleX;
c *= textureSegment->mScaleY; c *= textureSegment->mScaleY;
d *= textureSegment->mScaleY; d *= textureSegment->mScaleY;
v[0].Set(tx, ty, z, textureSegment->mU1, textureSegment->mV1, color); 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[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); v[3].Set(tx + (a + c), ty + (b + d), z, textureSegment->mU2, textureSegment->mV2, color);
gPixelsDrawn += (int)((a + b) * (c + d)); 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) BF_EXPORT void BF_CALLTYPE Gfx_AllocTris(TextureSegment* textureSegment, int vtxCount)
{ {
gCurTextureSegment = textureSegment; gCurTextureSegment = textureSegment;
DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer; DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
drawLayer->SetTexture(0, textureSegment->mTexture); drawLayer->SetTexture(0, textureSegment->mTexture);
gCurAllocVertices = (DefaultVertex3D*)gBFApp->mRenderDevice->mCurDrawLayer->AllocTris(vtxCount); 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) 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, gCurAllocVertices[idx].Set(x, y, z,
gCurTextureSegment->mU1 + u * (gCurTextureSegment->mU2 - gCurTextureSegment->mU1), gCurTextureSegment->mU1 + u * (gCurTextureSegment->mU2 - gCurTextureSegment->mU1),
gCurTextureSegment->mV1 + v * (gCurTextureSegment->mV2 - gCurTextureSegment->mV1), color); 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) /*for (int vtxIdx = 0; vtxIdx < vtxCount; vtxIdx += 4)
{ {
Vertex3D* v = gBFApp->mRenderDevice->mCurDrawLayer->AllocStrip(textureSegment->mTexture, drawType != 0, 4); Vertex3D* v = gBFApp->mRenderDevice->mCurDrawLayer->AllocStrip(textureSegment->mTexture, drawType != 0, 4);
v[0] = vertices[vtxIdx]; v[0] = vertices[vtxIdx];
v[1] = vertices[vtxIdx + 1]; v[1] = vertices[vtxIdx + 1];
v[2] = vertices[vtxIdx + 2]; v[2] = vertices[vtxIdx + 2];
@ -573,7 +573,7 @@ BF_EXPORT void BF_CALLTYPE Gfx_DrawQuads(TextureSegment* textureSegment, Default
} }
return;*/ return;*/
DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer; DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
drawLayer->SetTexture(0, textureSegment->mTexture); 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++) for (int idxIdx = 0; idxIdx < idxCount; idxIdx++)
*(drawBatchIdxPtr++) = *(idxPtr++) + idxOfs; *(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) 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; DrawLayer* drawLayer = gBFApp->mRenderDevice->mCurDrawLayer;
uint16 idxOfs; uint16 idxOfs;
void* drawBatchVtxPtr; void* drawBatchVtxPtr;
uint16* drawBatchIdxPtr; uint16* drawBatchIdxPtr;
gBFApp->mRenderDevice->mCurDrawLayer->AllocIndexed(vtxCount, idxCount, (void**)&drawBatchVtxPtr, &drawBatchIdxPtr, &idxOfs); 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; uint16* idxPtr = idxData;
for (int idxIdx = 0; idxIdx < idxCount; idxIdx++) for (int idxIdx = 0; idxIdx < idxCount; idxIdx++)
*(drawBatchIdxPtr++) = *(idxPtr++) + idxOfs; *(drawBatchIdxPtr++) = *(idxPtr++) + idxOfs;
//memcpy(drawBatchIdxPtr, idxData, sizeof(uint16) * idxCount); //memcpy(drawBatchIdxPtr, idxData, sizeof(uint16) * idxCount);
//memcpy(drawBatchVtxPtr, vtxData, vertexSize * vtxCount); //memcpy(drawBatchVtxPtr, vtxData, vertexSize * vtxCount);
void* vtxPtr = vtxData; 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_EXPORT void BF_CALLTYPE RenderState_SetClip(RenderState* renderState, float x, float y, float width, float height)
{ {
BF_ASSERT((width >= 0) && (height >= 0)); BF_ASSERT((width >= 0) && (height >= 0));
renderState->mClipRect.mX = x; renderState->mClipRect.mX = x;
renderState->mClipRect.mY = y; renderState->mClipRect.mY = y;
renderState->mClipRect.mWidth = width; renderState->mClipRect.mWidth = width;
renderState->mClipRect.mHeight = height; renderState->mClipRect.mHeight = height;
if (!renderState->mClipped) if (!renderState->mClipped)
renderState->SetClipped(true); 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_EXPORT void BF_CALLTYPE Gfx_SetRenderState(RenderState* renderState)
{ {
BF_ASSERT(renderState->mShader != NULL); BF_ASSERT(renderState->mShader != NULL);
gBFApp->mRenderDevice->SetRenderState(renderState); gBFApp->mRenderDevice->SetRenderState(renderState);
} }
BF_EXPORT void BF_CALLTYPE Gfx_Shader_Delete(Shader* shader) BF_EXPORT void BF_CALLTYPE Gfx_Shader_Delete(Shader* shader)

View file

@ -11,15 +11,15 @@ USING_NS_BF;
static int sCurBatchId = 0; static int sCurBatchId = 0;
DrawBatch::DrawBatch() DrawBatch::DrawBatch()
{ {
mId = ++sCurBatchId; mId = ++sCurBatchId;
mVtxIdx = 0; mVtxIdx = 0;
mIdxIdx = 0; mIdxIdx = 0;
mAllocatedVertices = 0; mAllocatedVertices = 0;
mAllocatedIndices = 0; mAllocatedIndices = 0;
mIsIndexBufferHead = false; mIsIndexBufferHead = false;
mIsVertexBufferHead = false; mIsVertexBufferHead = false;
mVertices = NULL; mVertices = NULL;
mIndices = NULL; mIndices = NULL;
mRenderState = NULL; mRenderState = NULL;
mDrawLayer = NULL; mDrawLayer = NULL;
@ -41,7 +41,7 @@ void DrawBatch::Clear()
} }
void DrawBatch::Free() void DrawBatch::Free()
{ {
RenderDevice* renderDevice = mDrawLayer->mRenderDevice; RenderDevice* renderDevice = mDrawLayer->mRenderDevice;
if (mIsVertexBufferHead) if (mIsVertexBufferHead)
@ -60,8 +60,8 @@ void DrawBatch::Free()
DrawBatch* DrawBatch::AllocateChainedBatch(int minVtxCount, int minIdxCount) DrawBatch* DrawBatch::AllocateChainedBatch(int minVtxCount, int minIdxCount)
{ {
mDrawLayer->CloseDrawBatch(); mDrawLayer->CloseDrawBatch();
return mDrawLayer->AllocateBatch(minVtxCount, minIdxCount); return mDrawLayer->AllocateBatch(minVtxCount, minIdxCount);
} }
void* DrawBatch::AllocTris(int vtxCount) void* DrawBatch::AllocTris(int vtxCount)
@ -75,14 +75,14 @@ void* DrawBatch::AllocTris(int vtxCount)
DrawBatch* nextBatch = AllocateChainedBatch(0, 0); DrawBatch* nextBatch = AllocateChainedBatch(0, 0);
return nextBatch->AllocTris(vtxCount); return nextBatch->AllocTris(vtxCount);
} }
mRenderState = gBFApp->mRenderDevice->mCurRenderState; mRenderState = gBFApp->mRenderDevice->mCurRenderState;
} }
uint16* idxPtr = mIndices + mIdxIdx; uint16* idxPtr = mIndices + mIdxIdx;
void* vtxPtr = (uint8*)mVertices + (mVtxIdx * mVtxSize); void* vtxPtr = (uint8*)mVertices + (mVtxIdx * mVtxSize);
for (int idxNum = 0; idxNum < idxCount; idxNum++) for (int idxNum = 0; idxNum < idxCount; idxNum++)
{ {
*idxPtr++ = mVtxIdx++; *idxPtr++ = mVtxIdx++;
mIdxIdx++; mIdxIdx++;
@ -96,17 +96,17 @@ void* DrawBatch::AllocStrip(int vtxCount)
int idxCount = (vtxCount - 2) * 3; int idxCount = (vtxCount - 2) * 3;
if ((mRenderState != gBFApp->mRenderDevice->mCurRenderState) || (idxCount + mIdxIdx >= mAllocatedIndices)) if ((mRenderState != gBFApp->mRenderDevice->mCurRenderState) || (idxCount + mIdxIdx >= mAllocatedIndices))
{ {
if (mVtxIdx > 0) if (mVtxIdx > 0)
{ {
DrawBatch* nextBatch = AllocateChainedBatch(0, 0); DrawBatch* nextBatch = AllocateChainedBatch(0, 0);
return nextBatch->AllocStrip(vtxCount); return nextBatch->AllocStrip(vtxCount);
} }
mRenderState = gBFApp->mRenderDevice->mCurRenderState; mRenderState = gBFApp->mRenderDevice->mCurRenderState;
} }
uint16* idxPtr = mIndices + mIdxIdx; uint16* idxPtr = mIndices + mIdxIdx;
void* vtxPtr = (uint8*)mVertices + (mVtxIdx * mVtxSize); void* vtxPtr = (uint8*)mVertices + (mVtxIdx * mVtxSize);
@ -120,21 +120,21 @@ void* DrawBatch::AllocStrip(int vtxCount)
mVtxIdx++; mVtxIdx++;
mIdxIdx += 3; mIdxIdx += 3;
} }
return vtxPtr; return vtxPtr;
} }
void DrawBatch::AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uint16** indicesOut, uint16* idxOfsOut) void DrawBatch::AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uint16** indicesOut, uint16* idxOfsOut)
{ {
if ((mRenderState != gBFApp->mRenderDevice->mCurRenderState) || (idxCount + mIdxIdx > mAllocatedIndices)) if ((mRenderState != gBFApp->mRenderDevice->mCurRenderState) || (idxCount + mIdxIdx > mAllocatedIndices))
{ {
if (mVtxIdx > 0) if (mVtxIdx > 0)
{ {
DrawBatch* nextBatch = AllocateChainedBatch(vtxCount, idxCount); DrawBatch* nextBatch = AllocateChainedBatch(vtxCount, idxCount);
return nextBatch->AllocIndexed(vtxCount, idxCount, verticesOut, indicesOut, idxOfsOut); return nextBatch->AllocIndexed(vtxCount, idxCount, verticesOut, indicesOut, idxOfsOut);
} }
mRenderState = gBFApp->mRenderDevice->mCurRenderState; mRenderState = gBFApp->mRenderDevice->mCurRenderState;
} }
*verticesOut = (uint8*)mVertices + (mVtxIdx * mVtxSize); *verticesOut = (uint8*)mVertices + (mVtxIdx * mVtxSize);
@ -148,8 +148,8 @@ void DrawBatch::AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uin
// //
DrawLayer::DrawLayer() DrawLayer::DrawLayer()
{ {
mRenderWindow = NULL; mRenderWindow = NULL;
mRenderDevice = NULL; mRenderDevice = NULL;
mIdxBuffer = NULL; mIdxBuffer = NULL;
mVtxBuffer = NULL; mVtxBuffer = NULL;
@ -164,7 +164,6 @@ DrawLayer::DrawLayer()
DrawLayer::~DrawLayer() DrawLayer::~DrawLayer()
{ {
NOP;
} }
void DrawLayer::CloseDrawBatch() void DrawLayer::CloseDrawBatch()
@ -178,9 +177,9 @@ void DrawLayer::CloseDrawBatch()
} }
void DrawLayer::QueueRenderCmd(RenderCmd* renderCmd) void DrawLayer::QueueRenderCmd(RenderCmd* renderCmd)
{ {
CloseDrawBatch(); CloseDrawBatch();
mRenderCmdList.PushBack(renderCmd); mRenderCmdList.PushBack(renderCmd);
renderCmd->CommandQueued(this); renderCmd->CommandQueued(this);
} }
@ -196,7 +195,7 @@ DrawBatch* DrawLayer::AllocateBatch(int minVtxCount, int minIdxCount)
minIdxCount = 512; minIdxCount = 512;
minVtxCount = minIdxCount; minVtxCount = minIdxCount;
} }
BF_ASSERT(minIdxCount * sizeof(uint16) <= DRAWBUFFER_IDXBUFFER_SIZE); BF_ASSERT(minIdxCount * sizeof(uint16) <= DRAWBUFFER_IDXBUFFER_SIZE);
BF_ASSERT(minVtxCount * vtxSize <= DRAWBUFFER_VTXBUFFER_SIZE); BF_ASSERT(minVtxCount * vtxSize <= DRAWBUFFER_VTXBUFFER_SIZE);
@ -212,7 +211,7 @@ DrawBatch* DrawLayer::AllocateBatch(int minVtxCount, int minIdxCount)
drawBatch = pool.back(); drawBatch = pool.back();
pool.pop_back(); pool.pop_back();
} }
drawBatch->mDrawLayer = this; drawBatch->mDrawLayer = this;
int needIdxBytes = minIdxCount * sizeof(uint16); int needIdxBytes = minIdxCount * sizeof(uint16);
int needVtxBytes = minVtxCount * vtxSize; int needVtxBytes = minVtxCount * vtxSize;
@ -225,7 +224,7 @@ DrawBatch* DrawLayer::AllocateBatch(int minVtxCount, int minIdxCount)
drawBatch->mIsVertexBufferHead = false; drawBatch->mIsVertexBufferHead = false;
} }
else else
{ {
mVtxBuffer = mRenderDevice->mPooledVertexBuffers.AllocMemoryBlock(); mVtxBuffer = mRenderDevice->mPooledVertexBuffers.AllocMemoryBlock();
mVtxByteIdx = 0; mVtxByteIdx = 0;
drawBatch->mVertices = (Vertex3D*)mVtxBuffer; drawBatch->mVertices = (Vertex3D*)mVtxBuffer;
@ -235,12 +234,12 @@ DrawBatch* DrawLayer::AllocateBatch(int minVtxCount, int minIdxCount)
if (needIdxBytes < DRAWBUFFER_IDXBUFFER_SIZE - mIdxByteIdx) if (needIdxBytes < DRAWBUFFER_IDXBUFFER_SIZE - mIdxByteIdx)
{ {
drawBatch->mIndices = (uint16*)((uint8*)mIdxBuffer + mIdxByteIdx); drawBatch->mIndices = (uint16*)((uint8*)mIdxBuffer + mIdxByteIdx);
drawBatch->mAllocatedIndices = (DRAWBUFFER_IDXBUFFER_SIZE - mIdxByteIdx) / sizeof(uint16); drawBatch->mAllocatedIndices = (DRAWBUFFER_IDXBUFFER_SIZE - mIdxByteIdx) / sizeof(uint16);
drawBatch->mIsIndexBufferHead = false; drawBatch->mIsIndexBufferHead = false;
} }
else else
{ {
mIdxBuffer = mRenderDevice->mPooledIndexBuffers.AllocMemoryBlock(); mIdxBuffer = mRenderDevice->mPooledIndexBuffers.AllocMemoryBlock();
mIdxByteIdx = 0; mIdxByteIdx = 0;
drawBatch->mIndices = (uint16*)mIdxBuffer; drawBatch->mIndices = (uint16*)mIdxBuffer;
@ -250,7 +249,7 @@ DrawBatch* DrawLayer::AllocateBatch(int minVtxCount, int minIdxCount)
drawBatch->mAllocatedIndices = std::min(drawBatch->mAllocatedVertices, drawBatch->mAllocatedIndices); drawBatch->mAllocatedIndices = std::min(drawBatch->mAllocatedVertices, drawBatch->mAllocatedIndices);
drawBatch->mVtxSize = vtxSize; drawBatch->mVtxSize = vtxSize;
mRenderCmdList.PushBack(drawBatch); mRenderCmdList.PushBack(drawBatch);
mCurDrawBatch = drawBatch; mCurDrawBatch = drawBatch;
@ -266,7 +265,7 @@ void DrawLayer::Draw()
{ {
curRenderCmd->Render(mRenderDevice, mRenderWindow); curRenderCmd->Render(mRenderDevice, mRenderWindow);
curRenderCmd = curRenderCmd->mNext; curRenderCmd = curRenderCmd->mNext;
} }
} }
void DrawLayer::Flush() void DrawLayer::Flush()
@ -283,13 +282,13 @@ void DrawLayer::Clear()
RenderCmd* curBatch = mRenderCmdList.mHead; RenderCmd* curBatch = mRenderCmdList.mHead;
while (curBatch != NULL) while (curBatch != NULL)
{ {
RenderCmd* nextBatch = curBatch->mNext; RenderCmd* nextBatch = curBatch->mNext;
curBatch->Free(); curBatch->Free();
curBatch = nextBatch; curBatch = nextBatch;
} }
/*if ((mIdxBuffer == NULL) || (mCurDrawBatch != NULL)) /*if ((mIdxBuffer == NULL) || (mCurDrawBatch != NULL))
mIdxBuffer = mRenderDevice->mPooledIndexBuffers.AllocMemoryBlock(); mIdxBuffer = mRenderDevice->mPooledIndexBuffers.AllocMemoryBlock();
if ((mVtxBuffer == NULL) || (mCurDrawBatch != NULL)) if ((mVtxBuffer == NULL) || (mCurDrawBatch != NULL))
mVtxBuffer = mRenderDevice->mPooledVertexBuffers.AllocMemoryBlock(); mVtxBuffer = mRenderDevice->mPooledVertexBuffers.AllocMemoryBlock();
if ((mRenderCmdBuffer == NULL) || (mRenderCmdByteIdx != 0)) if ((mRenderCmdBuffer == NULL) || (mRenderCmdByteIdx != 0))
@ -357,7 +356,7 @@ BF_EXPORT void BF_CALLTYPE DrawLayer_Delete(DrawLayer* drawLayer)
{ {
if (drawLayer->mRenderWindow != NULL) if (drawLayer->mRenderWindow != NULL)
{ {
drawLayer->mRenderWindow->mDrawLayerList.Remove(drawLayer); drawLayer->mRenderWindow->mDrawLayerList.Remove(drawLayer);
} }
delete drawLayer; delete drawLayer;
@ -382,13 +381,13 @@ BF_EXPORT void BF_CALLTYPE DrawLayer_Activate(DrawLayer* drawLayer)
} }
BF_EXPORT void BF_CALLTYPE DrawLayer_DrawToRenderTarget(DrawLayer* drawLayer, TextureSegment* textureSegment) BF_EXPORT void BF_CALLTYPE DrawLayer_DrawToRenderTarget(DrawLayer* drawLayer, TextureSegment* textureSegment)
{ {
RenderDevice* renderDevice = gBFApp->mRenderDevice; RenderDevice* renderDevice = gBFApp->mRenderDevice;
BP_ZONE("DrawLayer_DrawToRenderTarget DrawPart"); BP_ZONE("DrawLayer_DrawToRenderTarget DrawPart");
RenderTarget* prevTarget = renderDevice->mCurRenderTarget; RenderTarget* prevTarget = renderDevice->mCurRenderTarget;
renderDevice->PhysSetRenderState(renderDevice->mDefaultRenderState); renderDevice->PhysSetRenderState(renderDevice->mDefaultRenderState);
renderDevice->PhysSetRenderTarget(textureSegment->mTexture); renderDevice->PhysSetRenderTarget(textureSegment->mTexture);
drawLayer->Draw(); drawLayer->Draw();
drawLayer->Clear(); drawLayer->Clear();
renderDevice->mCurRenderTarget = prevTarget; renderDevice->mCurRenderTarget = prevTarget;

View file

@ -22,7 +22,7 @@ class RenderState;
class DrawBatch : public RenderCmd class DrawBatch : public RenderCmd
{ {
public: public:
DrawLayer* mDrawLayer; DrawLayer* mDrawLayer;
int mId; int mId;
bool mIsVertexBufferHead; bool mIsVertexBufferHead;
@ -32,11 +32,11 @@ public:
int mVtxSize; int mVtxSize;
int mVtxIdx; int mVtxIdx;
int mAllocatedVertices; int mAllocatedVertices;
uint16* mIndices; uint16* mIndices;
int mIdxIdx; int mIdxIdx;
int mAllocatedIndices; int mAllocatedIndices;
Texture* mCurTextures[MAX_TEXTURES]; Texture* mCurTextures[MAX_TEXTURES];
public: public:
@ -46,10 +46,10 @@ public:
virtual void Free() override; virtual void Free() override;
void Clear(); void Clear();
DrawBatch* AllocateChainedBatch(int minVtxCount, int minIdxCount); DrawBatch* AllocateChainedBatch(int minVtxCount, int minIdxCount);
virtual void* AllocTris(int vtxCount); virtual void* AllocTris(int vtxCount);
virtual void* AllocStrip(int vtxCount); virtual void* AllocStrip(int vtxCount);
virtual void AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uint16** indicesOut, uint16* idxOfsOut); virtual void AllocIndexed(int vtxCount, int idxCount, void** verticesOut, uint16** indicesOut, uint16* idxOfsOut);
}; };
#define DRAWBUFFER_CMDBUFFER_SIZE 64*1024 #define DRAWBUFFER_CMDBUFFER_SIZE 64*1024
@ -58,26 +58,26 @@ public:
class DrawLayer class DrawLayer
{ {
public: public:
SLIList<RenderCmd*> mRenderCmdList; SLIList<RenderCmd*> mRenderCmdList;
DrawBatch* mCurDrawBatch; DrawBatch* mCurDrawBatch;
RenderWindow* mRenderWindow; RenderWindow* mRenderWindow;
RenderDevice* mRenderDevice; RenderDevice* mRenderDevice;
void* mIdxBuffer; void* mIdxBuffer;
void* mVtxBuffer; void* mVtxBuffer;
void* mRenderCmdBuffer; void* mRenderCmdBuffer;
int mIdxByteIdx; int mIdxByteIdx;
int mVtxByteIdx; int mVtxByteIdx;
int mRenderCmdByteIdx; int mRenderCmdByteIdx;
Texture* mCurTextures[MAX_TEXTURES]; Texture* mCurTextures[MAX_TEXTURES];
public: public:
template <typename T> template <typename T>
T* AllocRenderCmd(int extraBytes = 0) T* AllocRenderCmd(int extraBytes = 0)
{ {
if (mRenderCmdByteIdx + sizeof(T) + extraBytes >= DRAWBUFFER_CMDBUFFER_SIZE) if (mRenderCmdByteIdx + sizeof(T) + extraBytes >= DRAWBUFFER_CMDBUFFER_SIZE)
{ {
mRenderCmdBuffer = mRenderDevice->mPooledRenderCmdBuffers.AllocMemoryBlock(); mRenderCmdBuffer = mRenderDevice->mPooledRenderCmdBuffers.AllocMemoryBlock();
@ -93,9 +93,9 @@ public:
return cmd; return cmd;
} }
public: public:
void CloseDrawBatch(); void CloseDrawBatch();
virtual DrawBatch* CreateDrawBatch() = 0; virtual DrawBatch* CreateDrawBatch() = 0;
virtual DrawBatch* AllocateBatch(int minVtxCount, int minIdxCount); virtual DrawBatch* AllocateBatch(int minVtxCount, int minIdxCount);
void QueueRenderCmd(RenderCmd* renderCmd); void QueueRenderCmd(RenderCmd* renderCmd);
virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) = 0; virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) = 0;

View file

@ -56,7 +56,7 @@ void FTFont::Dispose(bool cacheRetain)
} }
} }
} }
mFaceSize = NULL; mFaceSize = NULL;
} }
} }
@ -78,14 +78,14 @@ FTFontManager::FTFontManager()
{ {
uint8 whiteVal = (uint8)(pow(i / 255.0f, 0.75) * 255.0f); uint8 whiteVal = (uint8)(pow(i / 255.0f, 0.75) * 255.0f);
uint8 blackVal = (uint8)(pow(i / 255.0f, 0.9) * 255.0f); uint8 blackVal = (uint8)(pow(i / 255.0f, 0.9) * 255.0f);
mWhiteTab[i] = whiteVal; mWhiteTab[i] = whiteVal;
mBlackTab[i] = blackVal; mBlackTab[i] = blackVal;
} }
} }
FTFontManager::~FTFontManager() FTFontManager::~FTFontManager()
{ {
for (auto page : mPages) for (auto page : mPages)
delete page; delete page;
mPages.Clear(); mPages.Clear();
@ -110,7 +110,7 @@ void FTFontManager::DoClearCache()
} }
else else
++itr; ++itr;
} }
} }
void FTFontManager::ClearCache() void FTFontManager::ClearCache()
@ -133,11 +133,11 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
{ {
if (gFTLibrary == NULL) if (gFTLibrary == NULL)
FT_Init_FreeType(&gFTLibrary); FT_Init_FreeType(&gFTLibrary);
FTFontManager::Face* face = NULL; FTFontManager::Face* face = NULL;
FTFontManager::Face** facePtr = NULL; FTFontManager::Face** facePtr = NULL;
if (gFTFontManager.mFaces.TryAdd(fileName, NULL, &facePtr)) if (gFTFontManager.mFaces.TryAdd(fileName, NULL, &facePtr))
{ {
face = new FTFontManager::Face(); face = new FTFontManager::Face();
*facePtr = face; *facePtr = face;
@ -153,7 +153,7 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
faceIdx = atoi(useFileName.c_str() + atPos + 1); faceIdx = atoi(useFileName.c_str() + atPos + 1);
useFileName.RemoveToEnd(atPos); useFileName.RemoveToEnd(atPos);
} }
auto error = FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace); auto error = FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);
face->mFTFace = ftFace; face->mFTFace = ftFace;
} }
else else
@ -164,7 +164,7 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
return false; return false;
mFace = face; mFace = face;
FTFontManager::FaceSize** faceSizePtr = NULL; FTFontManager::FaceSize** faceSizePtr = NULL;
if (face->mFaceSizes.TryAdd(pointSize, NULL, &faceSizePtr)) if (face->mFaceSizes.TryAdd(pointSize, NULL, &faceSizePtr))
{ {
@ -177,17 +177,17 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
FT_New_Size(mFace->mFTFace, &ftSize); FT_New_Size(mFace->mFTFace, &ftSize);
FT_Activate_Size(ftSize); FT_Activate_Size(ftSize);
auto error = FT_Set_Char_Size(mFace->mFTFace, 0, (int)(pointSize * 64), 72, 72); auto error = FT_Set_Char_Size(mFace->mFTFace, 0, (int)(pointSize * 64), 72, 72);
mFaceSize->mFace = mFace; mFaceSize->mFace = mFace;
mFaceSize->mFTSize = ftSize; mFaceSize->mFTSize = ftSize;
mFaceSize->mPointSize = pointSize; mFaceSize->mPointSize = pointSize;
} }
else else
{ {
mFaceSize = *faceSizePtr; mFaceSize = *faceSizePtr;
} }
mFaceSize->mRefCount++; mFaceSize->mRefCount++;
mHeight = mFaceSize->mFTSize->metrics.height / 64; mHeight = mFaceSize->mFTSize->metrics.height / 64;
mAscent = mFaceSize->mFTSize->metrics.ascender / 64; mAscent = mFaceSize->mFTSize->metrics.ascender / 64;
mDescent = mFaceSize->mFTSize->metrics.descender / 64; mDescent = mFaceSize->mFTSize->metrics.descender / 64;
@ -199,7 +199,7 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
TextureSegment* BF_CALLTYPE Gfx_CreateTextureSegment(TextureSegment* textureSegment, int srcX, int srcY, int srcWidth, int srcHeight); TextureSegment* BF_CALLTYPE Gfx_CreateTextureSegment(TextureSegment* textureSegment, int srcX, int srcY, int srcWidth, int srcHeight);
FTFontManager::Glyph* FTFont::AllocGlyph(int charCode, bool allowDefault) FTFontManager::Glyph* FTFont::AllocGlyph(int charCode, bool allowDefault)
{ {
FT_Activate_Size(mFaceSize->mFTSize); FT_Activate_Size(mFaceSize->mFTSize);
int glyph_index = FT_Get_Char_Index(mFace->mFTFace, charCode); int glyph_index = FT_Get_Char_Index(mFace->mFTFace, charCode);
@ -209,20 +209,20 @@ FTFontManager::Glyph* FTFont::AllocGlyph(int charCode, bool allowDefault)
auto error = FT_Load_Glyph(mFace->mFTFace, glyph_index, FT_LOAD_NO_BITMAP); auto error = FT_Load_Glyph(mFace->mFTFace, glyph_index, FT_LOAD_NO_BITMAP);
if (error != FT_Err_Ok) if (error != FT_Err_Ok)
return NULL; return NULL;
error = FT_Render_Glyph(mFace->mFTFace->glyph, FT_RENDER_MODE_NORMAL); error = FT_Render_Glyph(mFace->mFTFace->glyph, FT_RENDER_MODE_NORMAL);
if (error != FT_Err_Ok) if (error != FT_Err_Ok)
return NULL; return NULL;
auto& bitmap = mFace->mFTFace->glyph->bitmap; auto& bitmap = mFace->mFTFace->glyph->bitmap;
if ((bitmap.rows > FT_PAGE_HEIGHT) || (bitmap.width > FT_PAGE_WIDTH)) if ((bitmap.rows > FT_PAGE_HEIGHT) || (bitmap.width > FT_PAGE_WIDTH))
{ {
return NULL; return NULL;
} }
FTFontManager::Page* page = NULL; FTFontManager::Page* page = NULL;
if (!gFTFontManager.mPages.empty()) if (!gFTFontManager.mPages.empty())
{ {
page = gFTFontManager.mPages.back(); page = gFTFontManager.mPages.back();
@ -231,14 +231,14 @@ FTFontManager::Glyph* FTFont::AllocGlyph(int charCode, bool allowDefault)
// Move down to next row // Move down to next row
page->mCurX = 0; page->mCurX = 0;
page->mCurY += page->mMaxRowHeight; page->mCurY += page->mMaxRowHeight;
page->mMaxRowHeight = 0; page->mMaxRowHeight = 0;
} }
if (page->mCurY + (int)bitmap.rows > page->mTexture->mHeight) if (page->mCurY + (int)bitmap.rows > page->mTexture->mHeight)
{ {
// Doesn't fit // Doesn't fit
page = NULL; page = NULL;
} }
} }
if (page == NULL) if (page == NULL)
@ -261,28 +261,32 @@ FTFontManager::Glyph* FTFont::AllocGlyph(int charCode, bool allowDefault)
glyph->mX = page->mCurX; glyph->mX = page->mCurX;
glyph->mY = page->mCurY; glyph->mY = page->mCurY;
glyph->mWidth = bitmap.width; glyph->mWidth = bitmap.width;
glyph->mHeight = bitmap.rows; glyph->mHeight = bitmap.rows;
if (page->mTexture == NULL) if (page->mTexture == NULL)
{ {
ImageData img; ImageData* img = new ImageData();
img.CreateNew(FT_PAGE_WIDTH, FT_PAGE_HEIGHT); img->CreateNew(FT_PAGE_WIDTH, FT_PAGE_HEIGHT);
auto* bits = img->mBits;
for (int i = 0; i < FT_PAGE_HEIGHT * FT_PAGE_WIDTH; i++) for (int i = 0; i < FT_PAGE_HEIGHT * FT_PAGE_WIDTH; i++)
{ {
if (i % 3 == 0) if (i % 3 == 0)
img.mBits[i] = 0xFFFF0000; bits[i] = 0xFFFF0000;
else if (i % 3 == 1) else if (i % 3 == 1)
img.mBits[i] = 0xFF00FF00; bits[i] = 0xFF00FF00;
else else
img.mBits[i] = 0xFF0000FF; bits[i] = 0xFF0000FF;
} }
page->mTexture = gBFApp->mRenderDevice->LoadTexture(&img, TextureFlag_NoPremult); page->mTexture = gBFApp->mRenderDevice->LoadTexture(img, TextureFlag_NoPremult);
img->Deref();
} }
if (bitmap.width > 0) if (bitmap.width > 0)
{ {
ImageData img; ImageData* img = new ImageData();
img.CreateNew(bitmap.width, bitmap.rows); img->CreateNew(bitmap.width, bitmap.rows);
auto* bits = img->mBits;
int width = img->mWidth;
for (int y = 0; y < (int)bitmap.rows; y++) for (int y = 0; y < (int)bitmap.rows; y++)
{ {
for (int x = 0; x < (int)bitmap.width; x++) for (int x = 0; x < (int)bitmap.width; x++)
@ -292,17 +296,18 @@ FTFontManager::Glyph* FTFont::AllocGlyph(int charCode, bool allowDefault)
uint8 whiteVal = gFTFontManager.mWhiteTab[val]; uint8 whiteVal = gFTFontManager.mWhiteTab[val];
uint8 blackVal = gFTFontManager.mBlackTab[val]; uint8 blackVal = gFTFontManager.mBlackTab[val];
img.mBits[y * img.mWidth + x] = ((int32)whiteVal << 24) | bits[y * width + x] = ((int32)whiteVal << 24) |
((int32)blackVal) | ((int32)0xFF << 8) | ((int32)0xFF << 16); ((int32)blackVal) | ((int32)0xFF << 8) | ((int32)0xFF << 16);
} }
} }
page->mTexture->Blt(&img, page->mCurX, page->mCurY); page->mTexture->Blt(img, page->mCurX, page->mCurY);
img->Deref();
} }
page->mCurX += bitmap.width; page->mCurX += bitmap.width;
page->mMaxRowHeight = std::max(page->mMaxRowHeight, (int)bitmap.rows); page->mMaxRowHeight = std::max(page->mMaxRowHeight, (int)bitmap.rows);
auto texture = page->mTexture; auto texture = page->mTexture;
texture->AddRef(); texture->AddRef();
TextureSegment* textureSegment = new TextureSegment(); TextureSegment* textureSegment = new TextureSegment();
@ -330,7 +335,7 @@ int FTFont::GetKerning(int charA, int charB)
void FTFont::Release(bool cacheRetain) void FTFont::Release(bool cacheRetain)
{ {
Dispose(cacheRetain); Dispose(cacheRetain);
delete this; delete this;
} }
@ -338,7 +343,7 @@ void FTFont::Release(bool cacheRetain)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
BF_EXPORT FTFont* BF_CALLTYPE FTFont_Load(const char* fileName, float pointSize) BF_EXPORT FTFont* BF_CALLTYPE FTFont_Load(const char* fileName, float pointSize)
{ {
auto ftFont = new FTFont(); auto ftFont = new FTFont();
if (!ftFont->Load(fileName, pointSize)) if (!ftFont->Load(fileName, pointSize))
{ {
@ -351,11 +356,11 @@ BF_EXPORT FTFont* BF_CALLTYPE FTFont_Load(const char* fileName, float pointSize)
BF_EXPORT void BF_CALLTYPE FTFont_ClearCache() BF_EXPORT void BF_CALLTYPE FTFont_ClearCache()
{ {
FTFontManager::ClearCache(); FTFontManager::ClearCache();
} }
BF_EXPORT void BF_CALLTYPE FTFont_Delete(FTFont* ftFont, bool cacheRetain) BF_EXPORT void BF_CALLTYPE FTFont_Delete(FTFont* ftFont, bool cacheRetain)
{ {
ftFont->Release(cacheRetain); ftFont->Release(cacheRetain);
} }
@ -366,6 +371,6 @@ BF_EXPORT FTFontManager::Glyph* BF_CALLTYPE FTFont_AllocGlyph(FTFont* ftFont, in
BF_EXPORT int BF_CALLTYPE FTFont_GetKerning(FTFont* ftFont, int charCodeA, int charCodeB) BF_EXPORT int BF_CALLTYPE FTFont_GetKerning(FTFont* ftFont, int charCodeA, int charCodeB)
{ {
auto kerning = ftFont->GetKerning(charCodeA, charCodeB); auto kerning = ftFont->GetKerning(charCodeA, charCodeB);
return kerning; return kerning;
} }

View file

@ -20,7 +20,7 @@ RenderState::RenderState()
mCullMode = CullMode_None; mCullMode = CullMode_None;
mDepthFunc = DepthFunc_Always; mDepthFunc = DepthFunc_Always;
mTopology = Topology3D_TriangleList; mTopology = Topology3D_TriangleList;
mShader = NULL; mShader = NULL;
mClipped = false; mClipped = false;
mTexWrap = false; mTexWrap = false;
mWireframe = false; mWireframe = false;
@ -32,18 +32,18 @@ RenderTarget::RenderTarget()
mHeight = 0; mHeight = 0;
mHasBeenDrawnTo = false; mHasBeenDrawnTo = false;
mHasBeenTargeted = false; mHasBeenTargeted = false;
mResizeNum = 0; mResizeNum = 0;
} }
RenderWindow::RenderWindow() RenderWindow::RenderWindow()
{ {
mCurDrawLayer = NULL; mCurDrawLayer = NULL;
mRenderDevice = NULL; mRenderDevice = NULL;
mWindow = NULL; mWindow = NULL;
} }
RenderWindow::~RenderWindow() RenderWindow::~RenderWindow()
{ {
for (auto drawLayer : mDrawLayerList) for (auto drawLayer : mDrawLayerList)
delete drawLayer; delete drawLayer;
} }
@ -54,14 +54,14 @@ RenderDevice::RenderDevice() :
mPooledIndexBuffers(DRAWBUFFER_IDXBUFFER_SIZE), mPooledIndexBuffers(DRAWBUFFER_IDXBUFFER_SIZE),
mPooledVertexBuffers(DRAWBUFFER_VTXBUFFER_SIZE), mPooledVertexBuffers(DRAWBUFFER_VTXBUFFER_SIZE),
mPooledRenderCmdBuffers(DRAWBUFFER_CMDBUFFER_SIZE) mPooledRenderCmdBuffers(DRAWBUFFER_CMDBUFFER_SIZE)
{ {
mCurRenderState = NULL; mCurRenderState = NULL;
mDefaultRenderState = NULL; mDefaultRenderState = NULL;
mPhysRenderState = mDefaultRenderState; mPhysRenderState = mDefaultRenderState;
mResizeCount = 0; mResizeCount = 0;
mCurRenderTarget = NULL; mCurRenderTarget = NULL;
mCurDrawLayer = NULL; mCurDrawLayer = NULL;
mPhysRenderWindow = NULL; mPhysRenderWindow = NULL;
mApp = NULL; mApp = NULL;
} }
@ -107,7 +107,7 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
int dotPos = (int)fileName.LastIndexOf('.'); int dotPos = (int)fileName.LastIndexOf('.');
String ext; String ext;
if (dotPos != -1) if (dotPos != -1)
ext = fileName.Substring(dotPos); ext = fileName.Substring(dotPos);
ImageData* imageData = NULL; ImageData* imageData = NULL;
bool handled = false; bool handled = false;
@ -121,7 +121,7 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
handled = true; handled = true;
} }
else if (ext == ".tga") else if (ext == ".tga")
imageData = new TGAData(); imageData = new TGAData();
else if (ext == ".png") else if (ext == ".png")
imageData = new PNGData(); imageData = new PNGData();
else if (ext == ".jpg") else if (ext == ".jpg")
@ -133,10 +133,10 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
BF_FATAL("Unknown texture format"); BF_FATAL("Unknown texture format");
return NULL; // Unknown format return NULL; // Unknown format
} }
if (!handled) if (!handled)
{ {
imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0; imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0;
if (fileName.StartsWith("@")) if (fileName.StartsWith("@"))
{ {
int colon = (int)fileName.IndexOf(':'); int colon = (int)fileName.IndexOf(':');
@ -163,8 +163,8 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
Texture* aTexture = NULL; Texture* aTexture = NULL;
if (!failed) if (!failed)
aTexture = LoadTexture(imageData, flags); aTexture = LoadTexture(imageData, flags);
delete imageData; imageData->Deref();
return aTexture; return aTexture;
} }

View file

@ -19,15 +19,28 @@ ImageData::ImageData()
mWantsAlphaPremultiplied = true; mWantsAlphaPremultiplied = true;
mAlphaPremultiplied = false; mAlphaPremultiplied = false;
mIsAdditive = false; mIsAdditive = false;
mSrcDataLen = 0; mSrcDataLen = 0;
mRefCount = 1;
} }
ImageData::~ImageData() ImageData::~ImageData()
{ {
BF_ASSERT(mRefCount <= 1); // Allow direct delete if we only have one reference
delete [] mBits; delete [] mBits;
delete [] mSrcData; delete [] mSrcData;
} }
void ImageData::AddRef()
{
mRefCount++;
}
void ImageData::Deref()
{
if (--mRefCount == 0)
delete this;
}
void ImageData::SwapRAndB() void ImageData::SwapRAndB()
{ {
int aSize = mWidth*mHeight; int aSize = mWidth*mHeight;
@ -101,15 +114,15 @@ ImageData* ImageData::Duplicate()
} }
bool ImageData::LoadFromMemory(void* ptr, int size) bool ImageData::LoadFromMemory(void* ptr, int size)
{ {
SetSrcData((uint8*)ptr, size); SetSrcData((uint8*)ptr, size);
bool result = ReadData(); bool result = ReadData();
mSrcData = NULL; mSrcData = NULL;
return result; return result;
} }
bool ImageData::LoadFromFile(const StringImpl& path) bool ImageData::LoadFromFile(const StringImpl& path)
{ {
int size = 0; int size = 0;
uint8* aData = LoadBinaryData(path, &size); uint8* aData = LoadBinaryData(path, &size);
if (aData == NULL) if (aData == NULL)

View file

@ -15,6 +15,7 @@ enum
class ImageData class ImageData
{ {
public: public:
int mRefCount;
int mX; int mX;
int mY; int mY;
int mWidth; int mWidth;
@ -26,23 +27,25 @@ public:
uint8* mSrcData; uint8* mSrcData;
int mSrcDataLen; int mSrcDataLen;
bool mKeepSrcDataValid; bool mKeepSrcDataValid;
bool mOwnsSrcData; bool mOwnsSrcData;
bool mWantsAlphaPremultiplied; bool mWantsAlphaPremultiplied;
bool mAlphaPremultiplied; bool mAlphaPremultiplied;
bool mIsAdditive; bool mIsAdditive;
public: public:
ImageData(); ImageData();
virtual ~ImageData(); virtual ~ImageData();
void AddRef();
void Deref();
void SwapRAndB(); void SwapRAndB();
void CreateNew(int x, int y, int width, int height, bool clear = true); void CreateNew(int x, int y, int width, int height, bool clear = true);
void CreateNew(int width, int height, bool clear = true); void CreateNew(int width, int height, bool clear = true);
void CopyFrom(ImageData* img, int x, int y); void CopyFrom(ImageData* img, int x, int y);
void Fill(uint32 color); void Fill(uint32 color);
virtual ImageData* Duplicate(); virtual ImageData* Duplicate();
void SetSrcData(uint8* data, int dataLen); void SetSrcData(uint8* data, int dataLen);
virtual bool LoadFromMemory(void* ptr, int size); virtual bool LoadFromMemory(void* ptr, int size);
virtual bool LoadFromFile(const StringImpl& path); virtual bool LoadFromFile(const StringImpl& path);
virtual bool ReadData() { return false; } virtual bool ReadData() { return false; }

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,12 @@
#pragma once #pragma once
#include "Common.h" #include "Common.h"
#include "util/Dictionary.h"
#ifdef BF_PLATFORM_OPENGL_ES2 #ifdef BF_PLATFORM_OPENGL_ES2
#include "SDL_opengles2.h" #include <SDL2/SDL_opengles2.h>
#else #else
#include "SDL_opengl.h" #include <SDL2/SDL_opengl.h>
#endif #endif
#include "gfx/Shader.h" #include "gfx/Shader.h"
@ -26,6 +27,7 @@ public:
GLRenderDevice* mRenderDevice; GLRenderDevice* mRenderDevice;
GLuint mGLTexture; GLuint mGLTexture;
GLuint mGLTexture2; GLuint mGLTexture2;
ImageData* mImageData;
//IGL10RenderTargetView* mGLRenderTargetView; //IGL10RenderTargetView* mGLRenderTargetView;
public: public:
@ -33,6 +35,7 @@ public:
~GLTexture(); ~GLTexture();
virtual void PhysSetAsTarget(); virtual void PhysSetAsTarget();
virtual void Blt(ImageData* imageData, int x, int y) override;
}; };
class GLShaderParam : public ShaderParam class GLShaderParam : public ShaderParam
@ -48,7 +51,7 @@ public:
virtual void SetFloat4(float x, float y, float z, float w) override; virtual void SetFloat4(float x, float y, float z, float w) override;
}; };
typedef std::map<String, GLShaderParam*> GLShaderParamMap; typedef Dictionary<String, GLShaderParam*> GLShaderParamMap;
class GLShader : public Shader class GLShader : public Shader
{ {
@ -63,35 +66,46 @@ public:
GLint mAttribColor; GLint mAttribColor;
GLint mAttribTex0; GLint mAttribTex0;
GLint mAttribTex1; GLint mAttribTex1;
GLShaderParamMap mParamsMap; GLShaderParamMap mParamsMap;
public: public:
GLShader(); GLShader();
~GLShader(); ~GLShader();
virtual ShaderParam* GetShaderParam(const StringImpl& name) override; virtual ShaderParam* GetShaderParam(const StringImpl& name) override;
}; };
class GLSetTextureCmd : public RenderCmd
{
public:
int mTextureIdx;
Texture* mTexture;
public:
virtual void Render(RenderDevice* renderDevice, RenderWindow* renderWindow) override;
};
class GLDrawBatch : public DrawBatch class GLDrawBatch : public DrawBatch
{ {
public: public:
//IGL10Buffer* mGLBuffer; //IGL10Buffer* mGLBuffer;
public: public:
GLDrawBatch(int minVtxSize = 0, int minIdxSize = 0); GLDrawBatch();
~GLDrawBatch(); ~GLDrawBatch();
virtual void Lock(); //virtual void Lock();
virtual void Draw(); virtual void Render(RenderDevice* renderDevice, RenderWindow* renderWindow) override;
}; };
class GLDrawLayer : public DrawLayer class GLDrawLayer : public DrawLayer
{ {
public: public:
virtual DrawBatch* CreateDrawBatch(); virtual DrawBatch* CreateDrawBatch();
virtual DrawBatch* AllocateBatch(int minVtxCount, int minIdxCount) override; virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) override;
virtual void FreeBatch(DrawBatch* drawBatch) override; virtual void SetShaderConstantData(int usageIdx, int slotIdx, void* constData, int size) override;
public: public:
GLDrawLayer(); GLDrawLayer();
@ -108,7 +122,7 @@ public:
//IGL10RenderTargetView* mGLRenderTargetView; //IGL10RenderTargetView* mGLRenderTargetView;
bool mResizePending; bool mResizePending;
int mPendingWidth; int mPendingWidth;
int mPendingHeight; int mPendingHeight;
public: public:
virtual void PhysSetAsTarget(); virtual void PhysSetAsTarget();
@ -136,9 +150,11 @@ public:
//IGL10RasterizerState* mGLRasterizerStateClipped; //IGL10RasterizerState* mGLRasterizerStateClipped;
//IGL10RasterizerState* mGLRasterizerStateUnclipped; //IGL10RasterizerState* mGLRasterizerStateUnclipped;
GLuint mGLVAO;
GLuint mGLVertexBuffer; GLuint mGLVertexBuffer;
GLuint mGLIndexBuffer; GLuint mGLIndexBuffer;
GLuint mBlankTexture; GLuint mBlankTexture;
GLShader* mCurShader;
bool mHasVSync; bool mHasVSync;
@ -146,10 +162,11 @@ public:
GLDrawBatch* mFreeBatchHead; GLDrawBatch* mFreeBatchHead;
public: public:
virtual void PhysSetAdditive(bool additive); //virtual void PhysSetAdditive(bool additive);
virtual void PhysSetShader(Shader* shaderPass); //virtual void PhysSetShader(Shader* shaderPass);
virtual void PhysSetRenderWindow(RenderWindow* renderWindow); virtual void PhysSetRenderWindow(RenderWindow* renderWindow);
virtual void PhysSetRenderTarget(Texture* renderTarget); virtual void PhysSetRenderState(RenderState* renderState) override;
virtual void PhysSetRenderTarget(Texture* renderTarget) override;
public: public:
GLRenderDevice(); GLRenderDevice();
@ -159,13 +176,16 @@ public:
void FrameStart() override; void FrameStart() override;
void FrameEnd() override; void FrameEnd() override;
Texture* LoadTexture(ImageData* imageData, bool additive) override; Texture* LoadTexture(ImageData* imageData, int flags) override;
Shader* LoadShader(const StringImpl& fileName) override; Shader* LoadShader(const StringImpl& fileName, VertexDefinition* vertexDefinition) override;
Texture* CreateRenderTarget(int width, int height, bool destAlpha) override; Texture* CreateRenderTarget(int width, int height, bool destAlpha) override;
void SetShader(Shader* shader) override; virtual Texture* CreateDynTexture(int width, int height) override { return NULL; }
virtual void SetRenderState(RenderState* renderState) override;
/*void SetShader(Shader* shader) override;
virtual void SetClip(float x, float y, float width, float height) override; virtual void SetClip(float x, float y, float width, float height) override;
virtual void DisableClip() override; virtual void DisableClip() override;*/
}; };
NS_BF_END; NS_BF_END;

View file

@ -1,6 +1,7 @@
#include "SdlBFApp.h" #include "SdlBFApp.h"
#include "GLRenderDevice.h" #include "GLRenderDevice.h"
#include "SDL.h" #include "platform/PlatformHelper.h"
#include <SDL2/SDL.h>
USING_NS_BF; USING_NS_BF;
@ -9,6 +10,7 @@ USING_NS_BF;
#pragma comment(lib, "imm32.lib") #pragma comment(lib, "imm32.lib")
#pragma comment(lib, "version.lib") #pragma comment(lib, "version.lib")
SdlBFWindow::SdlBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags) SdlBFWindow::SdlBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags)
{ {
int sdlWindowFlags = 0; int sdlWindowFlags = 0;
@ -19,362 +21,55 @@ SdlBFWindow::SdlBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
#ifdef BF_PLATFORM_FULLSCREEN #ifdef BF_PLATFORM_FULLSCREEN
sdlWindowFlags |= SDL_WINDOW_FULLSCREEN; sdlWindowFlags |= SDL_WINDOW_FULLSCREEN;
#endif #endif
mSDLWindow = SDL_CreateWindow(title.c_str(), x, y, width, height, sdlWindowFlags); mSDLWindow = SDL_CreateWindow(title.c_str(), x, y, width, height, sdlWindowFlags);
if (!SDL_GL_CreateContext(mSDLWindow)) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
if (!SDL_GL_CreateContext(mSDLWindow))
{ {
BF_FATAL(StrFormat("Unable to create OpenGL context: %s", SDL_GetError()).c_str()); BF_FATAL(StrFormat("Unable to create OpenGL context: %s", SDL_GetError()).c_str());
SDL_Quit(); SDL_Quit();
exit(2); exit(2);
} }
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glEnable(GL_BLEND); glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#ifndef BF_PLATFORM_OPENGL_ES2 #ifndef BF_PLATFORM_OPENGL_ES2
glEnableClientState(GL_INDEX_ARRAY); //glEnableClientState(GL_INDEX_ARRAY);
#endif #endif
//glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//glEnableClientState(GL_COLOR_ARRAY);
mIsMouseInside = false; mIsMouseInside = false;
mRenderWindow = new GLRenderWindow((GLRenderDevice*)gBFApp->mRenderDevice, mSDLWindow); mRenderWindow = new GLRenderWindow((GLRenderDevice*)gBFApp->mRenderDevice, mSDLWindow);
mRenderWindow->mWindow = this; mRenderWindow->mWindow = this;
gBFApp->mRenderDevice->AddRenderWindow(mRenderWindow); gBFApp->mRenderDevice->AddRenderWindow(mRenderWindow);
if (parent != NULL) if (parent != NULL)
parent->mChildren.push_back(this); parent->mChildren.push_back(this);
} }
SdlBFWindow::~SdlBFWindow() SdlBFWindow::~SdlBFWindow()
{ {
if (mSDLWindow != NULL) if (mSDLWindow != NULL)
TryClose(); TryClose();
} }
bool SdlBFWindow::TryClose() bool SdlBFWindow::TryClose()
{ {
SdlBFApp* app = (SdlBFApp*)gBFApp; SdlBFApp* app = (SdlBFApp*)gBFApp;
SdlWindowMap::iterator itr = app->mSdlWindowMap.find(SDL_GetWindowID(mSDLWindow)); app->mSdlWindowMap.Remove(SDL_GetWindowID(mSDLWindow));
app->mSdlWindowMap.erase(itr);
SDL_DestroyWindow(mSDLWindow); SDL_DestroyWindow(mSDLWindow);
mSDLWindow = NULL; mSDLWindow = NULL;
return true; return true;
} }
//LRESULT SdlBFWindow::WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
//{
// SdlBFApp* app = (SdlBFApp*) gBFApp;
//
// switch (Msg)
// {
// case WM_CLOSE:
// {
// if (mCloseQueryFunc(this) != 0)
// gBFApp->RemoveWindow(this);
// return 0;
// }
// break;
// case WM_DESTROY:
// /*if (mFlags & BFWINDOW_QUIT_ON_CLOSE)
// {
// gBFApp->mRunning = false;
// }*/
// mHWnd = NULL;
// break;
// }
//
// LRESULT result = 0;
// bool doResult = false;
//
// if (!app->mInMsgProc)
// {
// app->mInMsgProc = true;
//
// switch (Msg)
// {
//
// case WM_SIZE:
// mRenderWindow->Resized();
// if (mMovedFunc != NULL)
// mMovedFunc(this);
// break;
// case WM_PAINT:
// break;
// case WM_LBUTTONDOWN:
// case WM_RBUTTONDOWN:
// case WM_MBUTTONDOWN:
// case WM_LBUTTONDBLCLK:
// case WM_RBUTTONDBLCLK:
// case WM_LBUTTONUP:
// case WM_RBUTTONUP:
// case WM_MBUTTONUP:
// case WM_MOUSEWHEEL:
// case WM_MOUSEMOVE:
// {
// int x = (short) LOWORD(lParam);
// int y = (short) HIWORD(lParam);
//
// bool releaseCapture = false;
//
// POINT point = {x, y};
// ::ClientToScreen(hWnd, &point);
// HWND windowAtPoint = ::WindowFromPoint(point);
//
// bool isMouseOver = windowAtPoint == hWnd;
//
// if ((!mIsMouseInside) && (isMouseOver))
// {
// TRACKMOUSEEVENT tme;
// tme.cbSize = sizeof(TRACKMOUSEEVENT);
// tme.dwFlags = TME_LEAVE;
// tme.hwndTrack = hWnd;
// TrackMouseEvent(&tme);
// mIsMouseInside = true;
// }
//
// if ((mIsMouseInside) && (!isMouseOver))
// {
// mIsMouseInside = false;
// mMouseLeaveFunc(this);
// }
//
// switch (Msg)
// {
// case WM_LBUTTONDOWN:
// SetCapture(hWnd);
// mMouseDownFunc(this, x, y, 0, 1);
// break;
// case WM_RBUTTONDOWN:
// SetCapture(hWnd);
// mMouseDownFunc(this, x, y, 1, 1);
// break;
// case WM_MBUTTONDOWN:
// SetCapture(hWnd);
// mMouseDownFunc(this, x, y, 2, 1);
// break;
// case WM_LBUTTONDBLCLK:
// SetCapture(hWnd);
// mMouseDownFunc(this, x, y, 0, 2);
// break;
// case WM_RBUTTONDBLCLK:
// SetCapture(hWnd);
// mMouseDownFunc(this, x, y, 1, 2);
// break;
// case WM_MBUTTONDBLCLK:
// SetCapture(hWnd);
// mMouseDownFunc(this, x, y, 2, 2);
// break;
// case WM_LBUTTONUP:
// releaseCapture = true;
// mMouseUpFunc(this, x, y, 0);
// break;
// case WM_RBUTTONUP:
// releaseCapture = true;
// mMouseUpFunc(this, x, y, 1);
// break;
// case WM_MBUTTONUP:
// releaseCapture = true;
// mMouseUpFunc(this, x, y, 2);
// break;
// case WM_MOUSEWHEEL:
// {
// POINT pt = {x, y};
// ScreenToClient(mHWnd, &pt);
//
// int delta = ((int16)HIWORD(wParam)) / 120;
// mMouseWheelFunc(this, pt.x, pt.y, delta);
// }
// break;
// case WM_MOUSEMOVE:
// {
// mMouseMoveFunc(this, x, y);
//
// if ((wParam != 0) && (gBFApp->mWindowList.size() > 1))
// {
// // See if our mouse is down and has entered into another window's space
// POINT point = {x, y};
// ::ClientToScreen(hWnd, &point);
//
// HWND windowAtPoint = ::WindowFromPoint(point);
//
// BFWindowList::iterator itr = gBFApp->mWindowList.begin();
// while (itr != gBFApp->mWindowList.end())
// {
// SdlBFWindow* aWindow = (SdlBFWindow*) *itr;
// if (aWindow != this)
// {
// if (aWindow->mHWnd == windowAtPoint)
// {
// POINT clientPt = point;
// ::ScreenToClient(aWindow->mHWnd, &clientPt);
// aWindow->mMouseProxyMoveFunc(this, clientPt.x, clientPt.y);
// aWindow->mIsMouseInside = true;
// }
// else if (aWindow->mIsMouseInside)
// {
// aWindow->mMouseLeaveFunc(this);
// aWindow->mIsMouseInside = false;
// }
// }
// ++itr;
// }
// }
// }
// break;
// }
//
// if (releaseCapture)
// {
// ReleaseCapture();
//
// BFWindowList::iterator itr = gBFApp->mWindowList.begin();
// while (itr != gBFApp->mWindowList.end())
// {
// SdlBFWindow* aWindow = (SdlBFWindow*) *itr;
// if ((aWindow != this) && (aWindow->mIsMouseInside))
// {
// aWindow->mMouseLeaveFunc(this);
// aWindow->mIsMouseInside = false;
// }
// ++itr;
// }
// }
// }
// break;
//
// case WM_COMMAND:
// {
// SdlBFMenu* aMenu = mMenuIDMap[(uint32)wParam];
// if (aMenu != NULL)
// mMenuItemSelectedFunc(this, aMenu);
// }
// break;
// case WM_INITMENUPOPUP:
// {
// HMENU hMenu = (HMENU) wParam;
// SdlBFMenu* aMenu = mHMenuMap[hMenu];
// if (aMenu != NULL)
// mMenuItemSelectedFunc(this, aMenu);
// }
// break;
//
// case WM_MOUSEACTIVATE:
// if (mFlags & BFWINDOW_NO_MOUSE_ACTIVATE)
// {
// doResult = true;
// result = MA_NOACTIVATE;
// }
// break;
//
// case WM_KILLFOCUS:
// mLostFocusFunc(this);
// break;
// case WM_SETFOCUS:
// mGotFocusFunc(this);
// break;
// case WM_MOUSELEAVE:
// mIsMouseInside = false;
// mMouseLeaveFunc(this);
// break;
//
// case WM_CHAR:
// mKeyCharFunc(this, (WCHAR)wParam);
// break;
// case WM_SYSKEYDOWN:
// case WM_KEYDOWN:
// {
// int keyCode = (int) wParam;
// mIsKeyDown[keyCode] = true;
//
// WinMenuIDMap::iterator itr = mMenuIDMap.begin();
// while (itr != mMenuIDMap.end())
// {
// SdlBFMenu* aMenu = itr->second;
// if ((aMenu->mKeyCode == keyCode) &&
// (aMenu->mKeyShift == mIsKeyDown[VK_SHIFT]) &&
// (aMenu->mKeyCtrl == mIsKeyDown[VK_CONTROL]) &&
// (aMenu->mKeyAlt == mIsKeyDown[VK_MENU]))
// {
// mMenuItemSelectedFunc(this, aMenu);
// doResult = true;
// break;
// }
// ++itr;
// }
// mKeyDownFunc(this, (int) wParam, (lParam & 0x7FFF) != 0);
// }
// break;
// case WM_SYSCHAR:
// {
// int keyCode = toupper((int) wParam);
//
// WinMenuIDMap::iterator itr = mMenuIDMap.begin();
// while (itr != mMenuIDMap.end())
// {
// SdlBFMenu* aMenu = itr->second;
// if ((aMenu->mKeyCode == keyCode) &&
// (aMenu->mKeyShift == mIsKeyDown[VK_SHIFT]) &&
// (aMenu->mKeyCtrl == mIsKeyDown[VK_CONTROL]) &&
// (aMenu->mKeyAlt == mIsKeyDown[VK_MENU]))
// {
// doResult = true;
// break;
// }
// ++itr;
// }
// }
// break;
// case WM_SYSKEYUP:
// case WM_KEYUP:
// {
// int keyCode = (int) wParam;
// if (mIsKeyDown[keyCode])
// {
// mKeyUpFunc(this, (int) wParam);
// mIsKeyDown[keyCode] = false;
// }
// }
// break;
//
// case WM_TIMER:
// if (gBFApp->mSysDialogCnt == 0)
// gBFApp->Process();
// break;
//
// case WM_SETCURSOR:
// gBFApp->PhysSetCursor();
// break;
//
// case WM_MOVING:
// if (mMovedFunc != NULL)
// mMovedFunc(this);
// break;
// case WM_SIZING:
// mRenderWindow->Resized();
// if (mMovedFunc != NULL)
// mMovedFunc(this);
// if (gBFApp->mSysDialogCnt == 0)
// gBFApp->Process();
// break;
// }
//
//
// app->mInMsgProc = false;
// }
//
// if (doResult)
// return result;
//
// return DefWindowProc(hWnd, Msg, wParam, lParam);
//}
static int SDLConvertScanCode(int scanCode) static int SDLConvertScanCode(int scanCode)
{ {
if ((scanCode >= SDL_SCANCODE_A) && (scanCode <= SDL_SCANCODE_Z)) if ((scanCode >= SDL_SCANCODE_A) && (scanCode <= SDL_SCANCODE_Z))
@ -383,8 +78,8 @@ static int SDLConvertScanCode(int scanCode)
return (scanCode - SDL_SCANCODE_0) + '0'; return (scanCode - SDL_SCANCODE_0) + '0';
switch (scanCode) switch (scanCode)
{ {
case SDL_SCANCODE_CANCEL: return 0x03; case SDL_SCANCODE_CANCEL: return 0x03;
case SDL_SCANCODE_AC_BACK: return 0x08; case SDL_SCANCODE_AC_BACK: return 0x08;
case SDL_SCANCODE_TAB: return 0x09; case SDL_SCANCODE_TAB: return 0x09;
case SDL_SCANCODE_CLEAR: return 0x0C; case SDL_SCANCODE_CLEAR: return 0x0C;
@ -394,14 +89,14 @@ static int SDLConvertScanCode(int scanCode)
case SDL_SCANCODE_LCTRL: return 0x11; case SDL_SCANCODE_LCTRL: return 0x11;
case SDL_SCANCODE_RCTRL: return 0x11; case SDL_SCANCODE_RCTRL: return 0x11;
case SDL_SCANCODE_MENU: return 0x12; case SDL_SCANCODE_MENU: return 0x12;
case SDL_SCANCODE_PAUSE: return 0x13; case SDL_SCANCODE_PAUSE: return 0x13;
case SDL_SCANCODE_LANG1: return 0x15; case SDL_SCANCODE_LANG1: return 0x15;
case SDL_SCANCODE_LANG2: return 0x15; case SDL_SCANCODE_LANG2: return 0x15;
case SDL_SCANCODE_LANG3: return 0x17; case SDL_SCANCODE_LANG3: return 0x17;
case SDL_SCANCODE_LANG4: return 0x18; case SDL_SCANCODE_LANG4: return 0x18;
case SDL_SCANCODE_LANG5: return 0x19; case SDL_SCANCODE_LANG5: return 0x19;
case SDL_SCANCODE_LANG6: return 0x19; case SDL_SCANCODE_LANG6: return 0x19;
case SDL_SCANCODE_ESCAPE: return 0x1B; case SDL_SCANCODE_ESCAPE: return 0x1B;
case SDL_SCANCODE_SPACE: return 0x20; case SDL_SCANCODE_SPACE: return 0x20;
case SDL_SCANCODE_PAGEUP: return 0x21; case SDL_SCANCODE_PAGEUP: return 0x21;
case SDL_SCANCODE_PAGEDOWN: return 0x22; case SDL_SCANCODE_PAGEDOWN: return 0x22;
@ -413,7 +108,7 @@ static int SDLConvertScanCode(int scanCode)
case SDL_SCANCODE_DOWN: return 0x28; case SDL_SCANCODE_DOWN: return 0x28;
case SDL_SCANCODE_SELECT: return 0x29; case SDL_SCANCODE_SELECT: return 0x29;
case SDL_SCANCODE_PRINTSCREEN: return 0x2A; case SDL_SCANCODE_PRINTSCREEN: return 0x2A;
case SDL_SCANCODE_EXECUTE: return 0x2B; case SDL_SCANCODE_EXECUTE: return 0x2B;
case SDL_SCANCODE_INSERT: return 0x2D; case SDL_SCANCODE_INSERT: return 0x2D;
case SDL_SCANCODE_DELETE: return 0x2E; case SDL_SCANCODE_DELETE: return 0x2E;
case SDL_SCANCODE_HELP: return 0x2F; case SDL_SCANCODE_HELP: return 0x2F;
@ -461,62 +156,50 @@ extern HINSTANCE gDLLInstance;
SdlBFApp::SdlBFApp() SdlBFApp::SdlBFApp()
{ {
//_CrtSetReportHook(SdlBFReportHook);
mRunning = false; mRunning = false;
mRenderDevice = NULL; mRenderDevice = NULL;
wchar_t aStr[MAX_PATH]; Beefy::String exePath;
#ifdef _WIN32 BfpGetStrHelper(exePath, [](char* outStr, int* inOutStrSize, BfpResult* result)
GetModuleFileNameW(gDLLInstance, aStr, MAX_PATH); {
#else BfpSystem_GetExecutablePath(outStr, inOutStrSize, (BfpSystemResult*)result);
GetModuleFileNameW(NULL, aStr, MAX_PATH); });
#endif
if (aStr[0] == '!')
{
new SdlBFWindow(NULL, "", 0, 0, 0, 0, 0);
}
mInstallDir = aStr;
int lastSlash = std::max((int)mInstallDir.rfind('\\'), (int)mInstallDir.rfind('/')); mInstallDir = GetFileDir(exePath) + "/";
int lastSlash = std::max((int)mInstallDir.LastIndexOf('\\'), (int)mInstallDir.LastIndexOf('/'));
if (lastSlash != -1) if (lastSlash != -1)
mInstallDir = mInstallDir.substr(0, lastSlash); mInstallDir = mInstallDir.Substring(0, lastSlash);
//TODO: We're not properly using DataDir vs InstallDir //TODO: We're not properly using DataDir vs InstallDir
#if (!defined BFSYSLIB_DYNAMIC) && (defined BF_RESOURCES_REL_DIR) #if (!defined BFSYSLIB_DYNAMIC) && (defined BF_RESOURCES_REL_DIR)
mInstallDir += "/" + Beefy::UTF8Decode(BF_RESOURCES_REL_DIR); mInstallDir += "/" + Beefy::UTF8Decode(BF_RESOURCES_REL_DIR);
#endif #endif
mInstallDir += "/"; mInstallDir += "/";
//OutputDebugStrF(L"DataDir: %s\n", mInstallDir.c_str());
mDataDir = mInstallDir; mDataDir = mInstallDir;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
BF_FATAL(StrFormat("Unable to initialize SDL: %s", SDL_GetError()).c_str()); BF_FATAL(StrFormat("Unable to initialize SDL: %s", SDL_GetError()).c_str());
} }
SdlBFApp::~SdlBFApp() SdlBFApp::~SdlBFApp()
{ {
} }
SdlBFWindow* SdlBFApp::GetSdlWindowFromId(uint32 id) SdlBFWindow* SdlBFApp::GetSdlWindowFromId(uint32 id)
{ {
SdlWindowMap::iterator itr = mSdlWindowMap.find(id); SdlBFWindow* window = NULL;
if (itr != mSdlWindowMap.end()) mSdlWindowMap.TryGetValue(id, &window);
return itr->second; return window;
return NULL;
} }
void SdlBFApp::Init() void SdlBFApp::Init()
{ {
mRunning = true; mRunning = true;
mInMsgProc = false; mInMsgProc = false;
mRenderDevice = new GLRenderDevice(); mRenderDevice = new GLRenderDevice();
mRenderDevice->Init(this); mRenderDevice->Init(this);
} }
@ -533,9 +216,9 @@ void SdlBFApp::Run()
if (!SDL_PollEvent(&sdlEvent)) if (!SDL_PollEvent(&sdlEvent))
break; break;
} }
//Beefy::DebugTimeGuard suspendTimeGuard(30, "BFApp::Run2"); //Beefy::DebugTimeGuard suspendTimeGuard(30, "BFApp::Run2");
switch (sdlEvent.type) switch (sdlEvent.type)
{ {
case SDL_QUIT: case SDL_QUIT:
@ -551,7 +234,7 @@ void SdlBFApp::Run()
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
{ {
SdlBFWindow* sdlBFWindow = GetSdlWindowFromId(sdlEvent.button.windowID); SdlBFWindow* sdlBFWindow = GetSdlWindowFromId(sdlEvent.button.windowID);
sdlBFWindow->mMouseDownFunc(sdlBFWindow, sdlEvent.button.x, sdlEvent.button.y, sdlEvent.button.button, 1); sdlBFWindow->mMouseDownFunc(sdlBFWindow, sdlEvent.button.x, sdlEvent.button.y, sdlEvent.button.button, 1);
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
@ -572,10 +255,10 @@ void SdlBFApp::Run()
SdlBFWindow* sdlBFWindow = GetSdlWindowFromId(sdlEvent.key.windowID); SdlBFWindow* sdlBFWindow = GetSdlWindowFromId(sdlEvent.key.windowID);
sdlBFWindow->mKeyUpFunc(sdlBFWindow, SDLConvertScanCode(sdlEvent.key.keysym.scancode)); sdlBFWindow->mKeyUpFunc(sdlBFWindow, SDLConvertScanCode(sdlEvent.key.keysym.scancode));
} }
break; break;
} }
} }
Process(); Process();
} }
} }
@ -586,25 +269,25 @@ int gBFDrawBatchCount = 0;
void SdlBFApp::Draw() void SdlBFApp::Draw()
{ {
//Beefy::DebugTimeGuard suspendTimeGuard(30, "SdlBFApp::Draw"); //Beefy::DebugTimeGuard suspendTimeGuard(30, "SdlBFApp::Draw");
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glClearColor(1.0f, 0.0f, 1.0f, 1.0f); glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gPixelsDrawn = 0; gPixelsDrawn = 0;
gBFDrawBatchCount = 0; gBFDrawBatchCount = 0;
mRenderDevice->FrameStart(); mRenderDevice->FrameStart();
BFApp::Draw(); BFApp::Draw();
mRenderDevice->FrameEnd(); mRenderDevice->FrameEnd();
gFrameCount++; gFrameCount++;
//if (gFrameCount % 60 == 0) //if (gFrameCount % 60 == 0)
//OutputDebugStrF("Pixels: %d Batches: %d\n", gPixelsDrawn / 1000, gBFDrawBatchCount); //OutputDebugStrF("Pixels: %d Batches: %d\n", gPixelsDrawn / 1000, gBFDrawBatchCount);
} }
BFWindow* SdlBFApp::CreateNewWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags) BFWindow* SdlBFApp::CreateNewWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags)
{ {
SdlBFWindow* aWindow = new SdlBFWindow(parent, title, x, y, width, height, windowFlags); SdlBFWindow* aWindow = new SdlBFWindow(parent, title, x, y, width, height, windowFlags);
@ -623,29 +306,7 @@ void SdlBFWindow::GetPosition(int* x, int* y, int* width, int* height, int* clie
void SdlBFApp::PhysSetCursor() void SdlBFApp::PhysSetCursor()
{ {
//
//static HCURSOR cursors [] =
// {
// ::LoadCursor(NULL, IDC_ARROW),
//
// //TODO: mApp->mHandCursor);
// ::LoadCursor(NULL, IDC_ARROW),
// //TODO: mApp->mDraggingCursor);
// ::LoadCursor(NULL, IDC_ARROW),
// ::LoadCursor(NULL, IDC_IBEAM),
//
// ::LoadCursor(NULL, IDC_NO),
// ::LoadCursor(NULL, IDC_SIZEALL),
// ::LoadCursor(NULL, IDC_SIZENESW),
// ::LoadCursor(NULL, IDC_SIZENS),
// ::LoadCursor(NULL, IDC_SIZENWSE),
// ::LoadCursor(NULL, IDC_SIZEWE),
// ::LoadCursor(NULL, IDC_WAIT),
// NULL
// };
//::SetCursor(cursors[mCursor]);
} }
void SdlBFWindow::SetClientPosition(int x, int y) void SdlBFWindow::SetClientPosition(int x, int y)
@ -668,7 +329,7 @@ uint32 SdlBFApp::GetClipboardFormat(const StringImpl& format)
void* SdlBFApp::GetClipboardData(const StringImpl& format, int* size) void* SdlBFApp::GetClipboardData(const StringImpl& format, int* size)
{ {
return SDL_GetClipboardText(); return SDL_GetClipboardText();
} }
void SdlBFApp::ReleaseClipboardData(void* ptr) void SdlBFApp::ReleaseClipboardData(void* ptr)
@ -677,17 +338,17 @@ void SdlBFApp::ReleaseClipboardData(void* ptr)
} }
void SdlBFApp::SetClipboardData(const StringImpl& format, const void* ptr, int size, bool resetClipboard) void SdlBFApp::SetClipboardData(const StringImpl& format, const void* ptr, int size, bool resetClipboard)
{ {
SDL_SetClipboardText((const char*)ptr); SDL_SetClipboardText((const char*)ptr);
} }
BFMenu* SdlBFWindow::AddMenuItem(BFMenu* parent, const wchar_t* text, const wchar_t* hotKey, BFSysBitmap* sysBitmap, bool enabled, int checkState, bool radioCheck) BFMenu* SdlBFWindow::AddMenuItem(BFMenu* parent, int insertIdx, const char* text, const char* hotKey, BFSysBitmap* bitmap, bool enabled, int checkState, bool radioCheck)
{ {
return NULL; return NULL;
} }
void SdlBFWindow::RemoveMenuItem(BFMenu* item) void SdlBFWindow::RemoveMenuItem(BFMenu* item)
{ {
} }
BFSysBitmap* SdlBFApp::LoadSysBitmap(const wchar_t* fileName) BFSysBitmap* SdlBFApp::LoadSysBitmap(const wchar_t* fileName)
@ -706,20 +367,21 @@ DrawLayer* SdlBFApp::CreateDrawLayer(BFWindow* window)
GLDrawLayer* drawLayer = new GLDrawLayer(); GLDrawLayer* drawLayer = new GLDrawLayer();
if (window != NULL) if (window != NULL)
{ {
drawLayer->mRenderWindow = window->mRenderWindow; drawLayer->mRenderWindow = window->mRenderWindow;
window->mRenderWindow->mDrawLayerList.push_back(drawLayer); window->mRenderWindow->mDrawLayerList.push_back(drawLayer);
} }
drawLayer->mRenderDevice = mRenderDevice;
return drawLayer; return drawLayer;
} }
void SdlBFApp::GetDesktopResolution(int& width, int& height) override void SdlBFApp::GetDesktopResolution(int& width, int& height)
{ {
width = 1024; width = 1024;
height = 768; height = 768;
} }
void SdlBFApp::GetWorkspaceRect(int& x, int& y, int& width, int& height) override void SdlBFApp::GetWorkspaceRect(int& x, int& y, int& width, int& height)
{ {
x = 0; x = 0;
y = 0; y = 0;

View file

@ -3,6 +3,7 @@
#include "BFApp.h" #include "BFApp.h"
#include "BFWindow.h" #include "BFWindow.h"
#include <map> #include <map>
#include "util/Dictionary.h"
struct SDL_Window; struct SDL_Window;
@ -16,24 +17,38 @@ class SdlBFWindow : public BFWindow
{ {
public: public:
SDL_Window* mSDLWindow; SDL_Window* mSDLWindow;
bool mIsMouseInside; bool mIsMouseInside;
int mModalCount; int mModalCount;
public: public:
SdlBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags); SdlBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags);
~SdlBFWindow(); ~SdlBFWindow();
virtual void* GetUnderlying() {return mSDLWindow; };
virtual void Destroy() { }
virtual void SetTitle(const char* title) override {}
virtual void SetMinimumSize(int minWidth, int minHeight, bool clientSized) override {}
virtual void GetPlacement(int* normX, int* normY, int* normWidth, int* normHeight, int* showKind) override { }
virtual void Resize(int x, int y, int width, int height, int showKind) override {}
virtual void SetMouseVisible(bool isMouseVisible) override {}
virtual bool TryClose() override; virtual bool TryClose() override;
virtual void GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight) override; virtual void GetPosition(int* x, int* y, int* width, int* height, int* clientX, int* clientY, int* clientWidth, int* clientHeight) override;
virtual void SetClientPosition(int x, int y) override; virtual void SetClientPosition(int x, int y) override;
virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) override; virtual void SetAlpha(float alpha, uint32 destAlphaSrcMask, bool isMouseVisible) override;
virtual BFMenu* AddMenuItem(BFMenu* parent, const wchar_t* text, const wchar_t* hotKey, BFSysBitmap* sysBitmap, bool enabled, int checkState, bool radioCheck); virtual BFMenu* AddMenuItem(BFMenu* parent, int insertIdx, const char* text, const char* hotKey, BFSysBitmap* bitmap, bool enabled, int checkState, bool radioCheck) override;
virtual void ModifyMenuItem(BFMenu* item, const char* text, const char* hotKey, BFSysBitmap* bitmap, bool enabled, int checkState, bool radioCheck) override {}
virtual void RemoveMenuItem(BFMenu* item) override; virtual void RemoveMenuItem(BFMenu* item) override;
virtual void LostFocus(BFWindow* newFocus) override {};
virtual void ModalsRemoved() override; virtual void ModalsRemoved() override;
virtual void SetForeground() override {};
}; };
typedef std::map<uint32, SdlBFWindow*> SdlWindowMap; typedef Dictionary<uint32, SdlBFWindow*> SdlWindowMap;
class SdlBFApp : public BFApp class SdlBFApp : public BFApp
{ {

10
IDE/dist/shaders/Std.frag vendored Normal file
View file

@ -0,0 +1,10 @@
uniform sampler2D tex;
uniform sampler2D tex2;
varying vec4 varying_color;
varying vec2 varying_texCoord0;
void main()
{
vec4 texColor = texture2D(tex, varying_texCoord0);
gl_FragColor = texColor * varying_color;
}

12
IDE/dist/shaders/Std_font.frag vendored Normal file
View file

@ -0,0 +1,12 @@
uniform sampler2D tex;
uniform sampler2D tex2;
varying vec4 varying_color;
varying vec2 varying_texCoord0;
void main()
{
vec4 texColor = texture2D(tex, varying_texCoord0);
float gray = varying_color.r * 0.299 + varying_color.g * 0.587 + varying_color.b * 0.114;
float a = mix(texColor.a, texColor.r, gray);
gl_FragColor = vec4(a, a, a, a) * varying_color;
}

15
IDE/dist/shaders/Std_font.vert vendored Normal file
View file

@ -0,0 +1,15 @@
uniform mat4 screenMatrix;
attribute vec4 position;
attribute vec2 texCoord0;
attribute vec4 color;
varying vec4 varying_color;
varying vec2 varying_texCoord0;
void main()
{
gl_Position = screenMatrix * position;
varying_color = vec4(color.b * color.a, color.g * color.a, color.r * color.a, color.a);
varying_texCoord0 = texCoord0;
}

14
IDE/dist/shaders/Std_font_es.frag vendored Normal file
View file

@ -0,0 +1,14 @@
precision lowp float;
uniform lowp sampler2D tex;
uniform lowp sampler2D tex2;
varying lowp vec4 varying_color;
varying mediump vec2 varying_texCoord0;
void main()
{
lowp vec4 texColor = texture2D(tex, varying_texCoord0);
float gray = varying_color.r * 0.299 + varying_color.g * 0.587 + varying_color.b * 0.114;
float a = mix(texColor.a, texColor.r, gray);
gl_FragColor = vec4(a, a, a, a) * varying_color;
}

17
IDE/dist/shaders/Std_font_es.vert vendored Normal file
View file

@ -0,0 +1,17 @@
precision mediump float;
uniform mat4 screenMatrix;
attribute vec4 position;
attribute vec2 texCoord0;
attribute vec4 color;
precision lowp float;
varying lowp vec4 varying_color;
varying mediump vec2 varying_texCoord0;
void main()
{
gl_Position = screenMatrix * position;
varying_color = vec4(color.b * color.a, color.g * color.a, color.r * color.a, color.a);
varying_texCoord0 = texCoord0;
}