void CSystem::InitShader() { SharePtr<CShader> pVS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.vs"), false); SharePtr<CShader> pPS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.ps"), false); BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!")); m_pProgram = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID()); }
CTextureFrag *CTextureAtlas::CreateTextureFrag(const TString &name, kmVec2 point, kmVec2 size) { BEATS_ASSERT(m_textureFrags.find(name) == m_textureFrags.end()); SharePtr<CResource> pSelf; CResourceManager::GetInstance()->QueryResource(GetFilePath(), pSelf); BEATS_ASSERT(pSelf.Get() == this); CTextureFrag *frag = new CTextureFrag(name, pSelf, point, size); m_textureFrags[name] = frag; return frag; }
void CFontFace::NewPage() { SharePtr<CTexture> texture = new CTexture; texture->InitWithData(nullptr, 0, PixelFormat::A8, PAGE_WIDTH, PAGE_HEIGHT); ++m_nCurrPage; m_textures.push_back(texture); SharePtr<CMaterial> material = CFontManager::GetInstance()->CreateDefaultMaterial(); material->SetTexture(0, texture); m_materialMap[texture->ID()] = material; }
CSpriteFrameBatchManager::CSpriteFrameBatchManager() { SharePtr<CShader> pVS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.vs"), false); SharePtr<CShader> pPS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.ps"), false); BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!")); m_pProgram = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID()); m_pCamera = new CCamera(CCamera::eCT_2D); int width, height; CRenderManager::GetInstance()->GetWindowSize(width, height); m_pCamera->SetWidth(width); m_pCamera->SetHeight(height); }
bool Spy_SendMessageCommand(SOCKET sock, const TCHAR* pszMsg, const TCHAR* pszCapital) { bool bRet = false; CSpyCommandMessageBox cmd; cmd.SetMessage(pszMsg); cmd.SetCaption(pszCapital); SharePtr<SSocketContext> socketContent = CSpyManager::GetInstance()->GetSocket(sock); BEATS_ASSERT(socketContent.Get() != NULL, _T("Invalid socket!")); if (socketContent.Get() != NULL) { bRet = CSpyCommandManager::GetInstance()->SendCommand(socketContent, &cmd); } return bRet; }
bool Spy_SendFileInfoCommand(SOCKET sock, const TCHAR* pszCmd, TFileInfoFeedbackFunc pFeedbackFunc, void* pUserData) { bool bRet = false; CSpyCommandGetFileInfo cmd; cmd.SetFeedBackFuncAddr((uint32_t)pFeedbackFunc, (uint32_t)pUserData); cmd.SetFileName(pszCmd); SharePtr<SSocketContext> socketContent = CSpyManager::GetInstance()->GetSocket(sock); BEATS_ASSERT(socketContent.Get() != NULL, _T("Invalid socket!")); if (socketContent.Get() != NULL) { bRet = CSpyCommandManager::GetInstance()->SendCommand(socketContent, &cmd); } return bRet; }
bool Spy_UploadFiles(SOCKET sock, const std::vector<TString>& files, const TString& strStorePath, CFileFilter* pFilter) { bool bRet = false; CSpyCommandUploadFile cmd; cmd.SetUploadFile(files); cmd.SetStorePath(strStorePath.c_str()); cmd.SetFileFilter(pFilter); SharePtr<SSocketContext> socketContent = CSpyManager::GetInstance()->GetSocket(sock); BEATS_ASSERT(socketContent.Get() != NULL, _T("Invalid socket!")); if (socketContent.Get() != NULL) { bRet = CSpyCommandManager::GetInstance()->SendCommand(socketContent, &cmd); } return bRet; }
const SBeatsSocket* Spy_Connect(uint32_t uIPAddress) { const SBeatsSocket* pRet = NULL; SOCKET socket = Beats_CreateSocket(SOCK_STREAM, 0); BEATS_ASSERT(socket != INVALID_SOCKET, _T("Create socket failed!")); if (socket != INVALID_SOCKET) { sockaddr_in address_in; memset(&address_in, 0, sizeof(address_in)); address_in.sin_family = AF_INET; address_in.sin_port = htons(SPY_DEFAULT_PORT); address_in.sin_addr.S_un.S_addr = uIPAddress; SharePtr<SSocketContext> pContext = CSpyManager::GetInstance()->ConnectToSpy(socket, &address_in, true); if (pContext.Get() != NULL) { pRet = Beats_GetSockInfo(pContext->m_socket); } } return pRet; }
void CSpriteFrameBatchManager::AddQuad( const CQuadPT &quad, SharePtr<CTexture> texture ) { if(texture) { GLuint textureID = texture->ID(); auto itr = m_batches.find(textureID); CSpriteFrameBatch *batch = nullptr; if(itr == m_batches.end()) { batch = new CSpriteFrameBatch; m_batches[textureID] = batch; } else { batch = itr->second; } batch->AddQuad(quad, texture); } }
SharePtr<CMaterial> CSystem::CreateDefaultMaterial() { if(!m_pProgram) { InitShader(); } BEATS_ASSERT(m_pProgram); SharePtr<CMaterial> material = new CMaterial(true); material->GetRenderState()->SetBoolState(GL_DEPTH_TEST, false); material->GetRenderState()->SetBoolState(GL_BLEND, true); material->GetRenderState()->SetBlendFuncSrcFactor(GL_SRC_ALPHA); material->GetRenderState()->SetBlendFuncTargetFactor(GL_ONE_MINUS_SRC_ALPHA); material->GetRenderState()->SetShaderProgram(m_pProgram->ID()); return material; }
void CFontFace::PrepareCharacters( const TString &chars ) { SetSize(); #ifndef _UNICODE //TODO: translate chars to unicode #pragma error("non-unicode unsupported") #endif FT_Error err = 0; for(size_t i = 0; i < chars.size(); ++i) { wchar_t character = chars[i]; if(m_glyphMap.find(character) != m_glyphMap.end()) continue; err = FT_Load_Char(m_pFont->Face(), character, FT_LOAD_RENDER); BEATS_ASSERT(!err); FT_Bitmap &bitmap = m_pFont->Face()->glyph->bitmap; FT_Glyph_Metrics &metrics = m_pFont->Face()->glyph->metrics; long x = metrics.horiBearingX >> FT_SHIFT_NUM; long y = metrics.horiBearingY >> FT_SHIFT_NUM; long xAdvance = metrics.horiAdvance >> FT_SHIFT_NUM; long width = metrics.width >> FT_SHIFT_NUM; long height = metrics.height >> FT_SHIFT_NUM; width, height; if(x < 0) x = 0; if(xAdvance < x + width) xAdvance = x + width; long xOffset = x; long yOffset = m_nAscender - y; long destWidth = nextMOE(bitmap.width); long destHeight = nextMOE(bitmap.rows); if(m_uCurrX + xOffset + destWidth > PAGE_WIDTH) { m_uCurrX = 0; m_uCurrY += m_nLineHeight; if(m_uCurrY + yOffset + destHeight > PAGE_HEIGHT) { m_uCurrY = 0; NewPage(); } } unsigned char *data = bitmap.buffer; bool needRealloc = bitmap.width != bitmap.pitch || destWidth != bitmap.width || destHeight != bitmap.rows; if(needRealloc) { data = new unsigned char[destWidth * destHeight]; for(long i = 0; i < destHeight; ++i) { for(long j = 0; j < destWidth; ++j) { data[i * destWidth + j] = (i < bitmap.rows && j < bitmap.width) ? bitmap.buffer[i * bitmap.pitch + j] : 0; } } } SharePtr<CTexture> texture = m_textures[m_nCurrPage]; texture->UpdateSubImage(m_uCurrX + xOffset, m_uCurrY + yOffset, destWidth, destHeight, data); if(needRealloc) { BEATS_SAFE_DELETE_ARRAY(data); } CFontGlyph *glyph = new CFontGlyph; glyph->width = (float)xAdvance; glyph->height = (float)m_nLineHeight; glyph->u = (float)m_uCurrX / PAGE_WIDTH; glyph->v = (float)m_uCurrY / PAGE_HEIGHT; glyph->texture = m_textures[m_nCurrPage]; m_glyphMap[character] = glyph; m_uCurrX += xAdvance; } }
SharePtr<CMaterial> CFontManager::CreateDefaultMaterial(bool bBitmapFont) { if(!m_pProgramFreetypeText) { SharePtr<CShader> pVS = CResourceManager::GetInstance()-> GetResource<CShader>(_T("TextShader.vs")); SharePtr<CShader> pPS = CResourceManager::GetInstance()-> GetResource<CShader>(_T("TextShader.ps")); BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!")); m_pProgramFreetypeText = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID()); } if(!m_pProgramBitmapText) { SharePtr<CShader> pVS = CResourceManager::GetInstance()-> GetResource<CShader>(_T("PointTexShader.vs")); SharePtr<CShader> pPS = CResourceManager::GetInstance()-> GetResource<CShader>(_T("PointTexShader.ps")); BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!")); m_pProgramBitmapText = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID()); } SharePtr<CMaterial> material = new CMaterial(); material->GetRenderState()->SetBoolState(CBoolRenderStateParam::eBSP_ScissorTest, false); material->GetRenderState()->SetBoolState(CBoolRenderStateParam::eBSP_Blend, true); material->GetRenderState()->SetBlendFuncSrcFactor(GL_SRC_ALPHA); material->GetRenderState()->SetBlendFuncTargetFactor(GL_ONE_MINUS_SRC_ALPHA); material->GetRenderState()->SetShaderProgram(bBitmapFont ? m_pProgramBitmapText->ID() : m_pProgramFreetypeText->ID()); return material; }
SharePtr<CMaterial> CComponentGraphic_GL::CreateMaterial(const TString &textureFileName) { SharePtr<CMaterial> material = new CMaterial(true); material->GetRenderState()->SetBoolState(GL_DEPTH_TEST, true); material->GetRenderState()->SetBoolState(GL_ALPHA_TEST, true); material->GetRenderState()->SetAlphaFunc(GL_GREATER); material->GetRenderState()->SetAlphaRef(0); material->GetRenderState()->SetBoolState(GL_BLEND, true); material->GetRenderState()->SetBlendFuncSrcFactor(GL_SRC_ALPHA); material->GetRenderState()->SetBlendFuncTargetFactor(GL_ONE_MINUS_SRC_ALPHA); SharePtr<CShader> pVS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.vs"), false); SharePtr<CShader> pPS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.ps"), false); BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!")); CShaderProgram *program = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID()); material->GetRenderState()->SetShaderProgram(program->ID()); SharePtr<CTexture> texture = CResourceManager::GetInstance()->GetResource<CTexture>(textureFileName, false); BEATS_ASSERT(texture, _T("Create Component Texture Failed!")); material->SetTexture(0, texture); return material; }