diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 481d8d6df..c2e64c774 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -800,6 +800,9 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Update(const CCommandBuffe IsAndUpdateTextureSlotBound(Slot, pCommand->m_Slot); glActiveTexture(GL_TEXTURE0 + Slot); } + + //fix the alignment to allow even 1byte changes, e.g. for alpha components + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); glTexSubImage2D(GL_TEXTURE_2D, 0, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height, TexFormatToOpenGLFormat(pCommand->m_Format), GL_UNSIGNED_BYTE, pCommand->m_pData); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 78a822d22..a686ca144 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -333,6 +333,7 @@ int CGraphics_Threaded::LoadTextureRawSub(int TextureID, int x, int y, int Width // m_pCommandBuffer->AddCommand(Cmd); + KickCommandBuffer(); return 0; } diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index 429090630..51414ac9b 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -745,7 +745,7 @@ public: pCursor->m_Y = DrawY; } - virtual void UploadText(int TextureID, const char *pText, int Length, float x, float y, float Size) + virtual void UploadText(int TextureID, const char *pText, int Length, float x, float y, int Size, int MaxWidth) { CFont *pFont = m_pDefaultFont; FT_Bitmap *pBitmap; @@ -766,7 +766,6 @@ public: while(pCurrent < pEnd) { - int NewLine = 0; const char *pBatchEnd = pEnd; const char *pTmp = pCurrent; @@ -774,12 +773,6 @@ public: if(NextCharacter) { - int SlotID = 0; - int SlotW = Size; - int SlotH = Size; - int SlotSize = SlotW*SlotH; - int xt = 1; - int yt = 1; unsigned int px, py; FT_Set_Pixel_Sizes(pFont->m_FtFace, 0, Size); @@ -792,28 +785,38 @@ public: } pBitmap = &pFont->m_FtFace->glyph->bitmap; // ignore_convention - - // prepare glyph data - mem_zero(ms_aGlyphData, SlotSize); - - if(pBitmap->pixel_mode == FT_PIXEL_MODE_GRAY) // ignore_convention - { - for(py = 0; py < (unsigned)pBitmap->rows; py++) // ignore_convention - for(px = 0; px < (unsigned)pBitmap->width; px++) // ignore_convention - ms_aGlyphData[(py+yt)*SlotW+px+xt] = pBitmap->buffer[py*pBitmap->pitch+px]; // ignore_convention - } - else if(pBitmap->pixel_mode == FT_PIXEL_MODE_MONO) // ignore_convention - { - for(py = 0; py < (unsigned)pBitmap->rows; py++) // ignore_convention - for(px = 0; px < (unsigned)pBitmap->width; px++) // ignore_convention - { - if(pBitmap->buffer[py*pBitmap->pitch+px/8]&(1<<(7-(px%8)))) // ignore_convention - ms_aGlyphData[(py+yt)*SlotW+px+xt] = 255; - } - } - Graphics()->LoadTextureRawSub(TextureID, x + WidthLastChars, y, Size, Size, CImageInfo::FORMAT_ALPHA, ms_aGlyphData); - WidthLastChars += (pBitmap->width + 1); + int MaxSize = (MaxWidth - WidthLastChars); + if (MaxSize > 0) + { + int SlotW = (MaxSize < pBitmap->width ? MaxSize : pBitmap->width); + int SlotH = pBitmap->rows; + int SlotSize = SlotW*SlotH; + + // prepare glyph data + mem_zero(ms_aGlyphData, SlotSize); + + if(pBitmap->pixel_mode == FT_PIXEL_MODE_GRAY) // ignore_convention + { + for (py = 0; py < (unsigned)SlotH; py++) // ignore_convention + for (px = 0; px < (unsigned)SlotW; px++) + { + ms_aGlyphData[(py)*SlotW + px] = pBitmap->buffer[py*pBitmap->width + px]; // ignore_convention + } + } + /*else if(pBitmap->pixel_mode == FT_PIXEL_MODE_MONO) // ignore_convention + { + for(py = 0; py < (unsigned)pBitmap->rows; py++) // ignore_convention + for(px = 0; px < (unsigned)pBitmap->width; px++) // ignore_convention + { + if(pBitmap->buffer[py*pBitmap->pitch+px/8]&(1<<(7-(px%8)))) // ignore_convention + ms_aGlyphData[(py)*SlotW+px] = 255; + } + }*/ + + Graphics()->LoadTextureRawSub(TextureID, x + WidthLastChars, y, SlotW, SlotH, CImageInfo::FORMAT_ALPHA, ms_aGlyphData); + WidthLastChars += (SlotW + 1); + } } ++ChrCount; pCurrent = pTmp; diff --git a/src/engine/textrender.h b/src/engine/textrender.h index 39ec35462..5a6ef24fa 100644 --- a/src/engine/textrender.h +++ b/src/engine/textrender.h @@ -43,7 +43,7 @@ public: // virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length) = 0; - virtual void UploadText(int TextureID, const char *pText, int Length, float x, float y, float Size) = 0; + virtual void UploadText(int TextureID, const char *pText, int Length, float x, float y, int Size, int MaxWidth) = 0; // old foolish interface virtual void TextColor(float r, float g, float b, float a) = 0; diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index af61eb547..d400e8474 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -27,6 +27,7 @@ void CMapImages::OnInit() void *pMem = mem_alloc(1024*1024, 1); mem_zero(pMem, 1024*1024); m_OverlayBottomTexture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS); + mem_free(pMem); for(int i = 0; i < 256; ++i) { @@ -36,16 +37,15 @@ void CMapImages::OnInit() float x = (i%16) * 64; float y = (int)(i/16)* 64; - Graphics()->LoadTextureRawSub(m_OverlayBottomTexture, x, y, 64, 64, CImageInfo::FORMAT_ALPHA, pMem); - TextRender()->UploadText(m_OverlayBottomTexture, buff, -1, x, y + 12 + 32, 20); + TextRender()->UploadText(m_OverlayBottomTexture, buff, -1, x+1, y + 12 + 32, 20, 64-1); } - mem_free(pMem); } if(m_OverlayTopTexture == -1) { void *pMem = mem_alloc(1024*1024, 1); mem_zero(pMem, 1024*1024); m_OverlayTopTexture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS); + mem_free(pMem); for(int i = 0; i < 256; ++i) { @@ -55,17 +55,16 @@ void CMapImages::OnInit() float x = (i%16) * 64; float y = (int)(i/16)* 64; - Graphics()->LoadTextureRawSub(m_OverlayTopTexture, x, y, 64, 64, CImageInfo::FORMAT_ALPHA, pMem); - TextRender()->UploadText(m_OverlayTopTexture, buff, -1, x, y, 20); + TextRender()->UploadText(m_OverlayTopTexture, buff, -1, x+1, y+1, 20, 64-1); } - mem_free(pMem); } if(m_OverlayCenterTexture == -1) { void *pMem = mem_alloc(1024*1024, 1); mem_zero(pMem, 1024*1024); m_OverlayCenterTexture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS); - + mem_free(pMem); + for(int i = 0; i < 256; ++i) { char buff[4]; @@ -76,14 +75,11 @@ void CMapImages::OnInit() float y = (int)(i/16)* 64; int Size = (len == 3 ? 20 : 64); - int Width = (len == 3 ? 15 : 32); int OffY = (len == 3 ? 10 : 5); - int OffX = (len == 3 ? 10 : 0); + int OffX = (len == 3 ? 10 : 1); - Graphics()->LoadTextureRawSub(m_OverlayCenterTexture, x, y, 64, 64, CImageInfo::FORMAT_ALPHA, pMem); - TextRender()->UploadText(m_OverlayCenterTexture, buff, -1, x + OffX, y + OffY, Size); + TextRender()->UploadText(m_OverlayCenterTexture, buff, -1, x + OffX, y + OffY, Size, 64-OffX); } - mem_free(pMem); } }