game(client): fix touch drawing problems
This commit is contained in:
parent
a7611c481e
commit
9c4ace30c3
@ -448,7 +448,12 @@ void CTouchControls::CreateAtlasTexture()
|
|||||||
|
|
||||||
FileHandle_t fp;
|
FileHandle_t fp;
|
||||||
fp = ::filesystem->Open( fullFileName, "rb" );
|
fp = ::filesystem->Open( fullFileName, "rb" );
|
||||||
if( !fp ) return;
|
if( !fp )
|
||||||
|
{
|
||||||
|
t->textureID = vgui::surface()->CreateNewTextureID();
|
||||||
|
vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
::filesystem->Seek( fp, 0, FILESYSTEM_SEEK_TAIL );
|
::filesystem->Seek( fp, 0, FILESYSTEM_SEEK_TAIL );
|
||||||
int srcVTFLength = ::filesystem->Tell( fp );
|
int srcVTFLength = ::filesystem->Tell( fp );
|
||||||
@ -467,19 +472,27 @@ void CTouchControls::CreateAtlasTexture()
|
|||||||
{
|
{
|
||||||
if( t->vtf->Format() != IMAGE_FORMAT_RGBA8888 && t->vtf->Format() != IMAGE_FORMAT_BGRA8888 )
|
if( t->vtf->Format() != IMAGE_FORMAT_RGBA8888 && t->vtf->Format() != IMAGE_FORMAT_BGRA8888 )
|
||||||
{
|
{
|
||||||
Msg("Format=%d\n", t->vtf->Format());
|
t->textureID = vgui::surface()->CreateNewTextureID();
|
||||||
Error("Use RGBA8888/BGRA88888 for touch buttons!\n");
|
vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false);
|
||||||
|
DestroyVTFTexture(t->vtf);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if( t->vtf->Height() != t->vtf->Width() || (t->vtf->Height() & (t->vtf->Height() - 1)) != 0 )
|
if( t->vtf->Height() != t->vtf->Width() || (t->vtf->Height() & (t->vtf->Height() - 1)) != 0 )
|
||||||
Error("Touch texture is wrong! Don't use npot textures for touch.");
|
Error("%s texture is wrong! Don't use npot textures for touch.");
|
||||||
|
|
||||||
t->height = t->vtf->Height();
|
t->height = t->vtf->Height();
|
||||||
t->width = t->vtf->Width();
|
t->width = t->vtf->Width();
|
||||||
|
t->isInAtlas = true;
|
||||||
|
|
||||||
atlasSize += t->width*t->height;
|
atlasSize += t->width*t->height;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
buf.Clear();
|
{
|
||||||
|
DestroyVTFTexture(t->vtf);
|
||||||
|
t->textureID = vgui::surface()->CreateNewTextureID();
|
||||||
|
vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
rects[i].h = t->height;
|
rects[i].h = t->height;
|
||||||
rects[i].w = t->width;
|
rects[i].w = t->width;
|
||||||
@ -504,6 +517,9 @@ void CTouchControls::CreateAtlasTexture()
|
|||||||
for( int i = 0; i < textureList.Count(); i++ )
|
for( int i = 0; i < textureList.Count(); i++ )
|
||||||
{
|
{
|
||||||
CTouchTexture *t = textureList[i];
|
CTouchTexture *t = textureList[i];
|
||||||
|
if( t->textureID )
|
||||||
|
continue;
|
||||||
|
|
||||||
t->X0 = rects[i].x / (float)atlasHeight;
|
t->X0 = rects[i].x / (float)atlasHeight;
|
||||||
t->Y0 = rects[i].y / (float)atlasHeight;
|
t->Y0 = rects[i].y / (float)atlasHeight;
|
||||||
t->X1 = t->X0 + t->width / (float)atlasHeight;
|
t->X1 = t->X0 + t->width / (float)atlasHeight;
|
||||||
@ -519,13 +535,11 @@ void CTouchControls::CreateAtlasTexture()
|
|||||||
}
|
}
|
||||||
|
|
||||||
DestroyVTFTexture(t->vtf);
|
DestroyVTFTexture(t->vtf);
|
||||||
t->isInAtlas = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
touchTextureID = vgui::surface()->CreateNewTextureID( true );
|
touchTextureID = vgui::surface()->CreateNewTextureID( true );
|
||||||
vgui::surface()->DrawSetTextureRGBA( touchTextureID, dest, atlasHeight, atlasHeight, 1, true );
|
vgui::surface()->DrawSetTextureRGBA( touchTextureID, dest, atlasHeight, atlasHeight, 1, true );
|
||||||
|
|
||||||
|
|
||||||
free(nodes);
|
free(nodes);
|
||||||
free(rects);
|
free(rects);
|
||||||
delete[] dest;
|
delete[] dest;
|
||||||
@ -603,7 +617,6 @@ void CTouchControls::Paint( )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
CUtlLinkedList<CTouchButton*>::iterator it;
|
CUtlLinkedList<CTouchButton*>::iterator it;
|
||||||
|
|
||||||
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
|
||||||
|
|
||||||
if( state == state_edit )
|
if( state == state_edit )
|
||||||
@ -638,7 +651,6 @@ void CTouchControls::Paint( )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(touchTextureID) );
|
|
||||||
m_pMesh = pRenderContext->GetDynamicMesh();
|
m_pMesh = pRenderContext->GetDynamicMesh();
|
||||||
|
|
||||||
int meshCount = 0;
|
int meshCount = 0;
|
||||||
@ -648,20 +660,53 @@ void CTouchControls::Paint( )
|
|||||||
|
|
||||||
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) )
|
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) )
|
||||||
{
|
{
|
||||||
if( !btn->texture->isInAtlas )
|
CTouchTexture *t = btn->texture;
|
||||||
|
|
||||||
|
if( t->textureID )
|
||||||
|
{
|
||||||
|
pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(t->textureID) );
|
||||||
|
meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount );
|
||||||
|
|
||||||
|
rgba_t color(btn->color.r, btn->color.g, btn->color.b, btn->color.a);
|
||||||
|
meshBuilder.Position3f( btn->x1*screen_w, btn->y1*screen_h, 0 );
|
||||||
|
meshBuilder.Color4ubv( color );
|
||||||
|
meshBuilder.TexCoord2f( 0, 0, 0 );
|
||||||
|
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||||
|
|
||||||
|
meshBuilder.Position3f( btn->x2*screen_w, btn->y1*screen_h, 0 );
|
||||||
|
meshBuilder.Color4ubv( color );
|
||||||
|
meshBuilder.TexCoord2f( 0, 1, 0 );
|
||||||
|
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||||
|
|
||||||
|
meshBuilder.Position3f( btn->x2*screen_w, btn->y2*screen_h, 0 );
|
||||||
|
meshBuilder.Color4ubv( color );
|
||||||
|
meshBuilder.TexCoord2f( 0, 1, 1 );
|
||||||
|
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||||
|
|
||||||
|
meshBuilder.Position3f( btn->x1*screen_w, btn->y2*screen_h, 0 );
|
||||||
|
meshBuilder.Color4ubv( color );
|
||||||
|
meshBuilder.TexCoord2f( 0, 0, 1 );
|
||||||
|
meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
|
||||||
|
|
||||||
|
meshBuilder.End();
|
||||||
|
m_pMesh->Draw();
|
||||||
|
}
|
||||||
|
else if( !btn->texture->isInAtlas )
|
||||||
CreateAtlasTexture();
|
CreateAtlasTexture();
|
||||||
|
|
||||||
meshCount++;
|
if( !t->textureID )
|
||||||
|
meshCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(touchTextureID) );
|
||||||
meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount );
|
meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount );
|
||||||
|
|
||||||
for( it = btns.begin(); it != btns.end(); it++ )
|
for( it = btns.begin(); it != btns.end(); it++ )
|
||||||
{
|
{
|
||||||
CTouchButton *btn = *it;
|
CTouchButton *btn = *it;
|
||||||
|
|
||||||
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) )
|
if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) && !btn->texture->textureID )
|
||||||
{
|
{
|
||||||
CTouchTexture *t = btn->texture;
|
CTouchTexture *t = btn->texture;
|
||||||
|
|
||||||
@ -744,6 +789,7 @@ void CTouchControls::AddButton( const char *name, const char *texturefile, const
|
|||||||
CTouchTexture *texture = new CTouchTexture;
|
CTouchTexture *texture = new CTouchTexture;
|
||||||
btn->texture = texture;
|
btn->texture = texture;
|
||||||
texture->isInAtlas = false;
|
texture->isInAtlas = false;
|
||||||
|
texture->textureID = 0;
|
||||||
texture->X0 = 0; texture->X1 = 0; texture->Y0 = 0; texture->Y1 = 0;
|
texture->X0 = 0; texture->X1 = 0; texture->Y0 = 0; texture->Y1 = 0;
|
||||||
Q_strncpy( texture->szName, btn->texturefile, sizeof(btn->texturefile) );
|
Q_strncpy( texture->szName, btn->texturefile, sizeof(btn->texturefile) );
|
||||||
textureList.AddToTail(texture);
|
textureList.AddToTail(texture);
|
||||||
|
@ -83,6 +83,7 @@ struct CTouchTexture
|
|||||||
|
|
||||||
float X0, Y0, X1, Y1; // position in atlas texture
|
float X0, Y0, X1, Y1; // position in atlas texture
|
||||||
int height, width;
|
int height, width;
|
||||||
|
int textureID;
|
||||||
bool isInAtlas;
|
bool isInAtlas;
|
||||||
char szName[1024];
|
char szName[1024];
|
||||||
};
|
};
|
||||||
@ -164,7 +165,7 @@ public:
|
|||||||
|
|
||||||
void Paint( );
|
void Paint( );
|
||||||
void Frame( );
|
void Frame( );
|
||||||
|
|
||||||
void AddButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, rgba_t color = rgba_t(255, 255, 255, 255), int round = 2, float aspect = 1.f, int flags = 0 );
|
void AddButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, rgba_t color = rgba_t(255, 255, 255, 255), int round = 2, float aspect = 1.f, int flags = 0 );
|
||||||
void RemoveButton( const char *name );
|
void RemoveButton( const char *name );
|
||||||
void ResetToDefaults();
|
void ResetToDefaults();
|
||||||
@ -172,7 +173,7 @@ public:
|
|||||||
void ShowButton( const char *name );
|
void ShowButton( const char *name );
|
||||||
void ListButtons();
|
void ListButtons();
|
||||||
void RemoveButtons();
|
void RemoveButtons();
|
||||||
|
|
||||||
CTouchButton *FindButton( const char *name );
|
CTouchButton *FindButton( const char *name );
|
||||||
// bool FindNextButton( const char *name, CTouchButton &button );
|
// bool FindNextButton( const char *name, CTouchButton &button );
|
||||||
void SetTexture( const char *name, const char *file );
|
void SetTexture( const char *name, const char *file );
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct GeneratePolyhedronFromPlanes_Point;
|
struct GeneratePolyhedronFromPlanes_Point;
|
||||||
struct GeneratePolyhedronFromPlanes_PointLL;
|
struct GeneratePolyhedronFromPlanes_PointLL;
|
||||||
struct GeneratePolyhedronFromPlanes_Line;
|
struct GeneratePolyhedronFromPlanes_Line;
|
||||||
@ -73,18 +72,18 @@ void CreateDumpDirectory( const char *szDirectoryName )
|
|||||||
|
|
||||||
void CPolyhedron_AllocByNew::Release( void )
|
void CPolyhedron_AllocByNew::Release( void )
|
||||||
{
|
{
|
||||||
free(this);
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation
|
CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation
|
||||||
{
|
{
|
||||||
void *pMemory = malloc(sizeof( CPolyhedron_AllocByNew ) +
|
void *pMemory = new unsigned char [ sizeof( CPolyhedron_AllocByNew ) +
|
||||||
(iVertices * sizeof(Vector)) +
|
(iVertices * sizeof(Vector)) +
|
||||||
(iLines * sizeof(Polyhedron_IndexedLine_t)) +
|
(iLines * sizeof(Polyhedron_IndexedLine_t)) +
|
||||||
(iIndices * sizeof( Polyhedron_IndexedLineReference_t )) +
|
(iIndices * sizeof( Polyhedron_IndexedLineReference_t )) +
|
||||||
(iPolygons * sizeof( Polyhedron_IndexedPolygon_t )));
|
(iPolygons * sizeof( Polyhedron_IndexedPolygon_t ))];
|
||||||
|
|
||||||
#include "tier0/memdbgoff.h"
|
#include "tier0/memdbgoff.h" //the following placement new doesn't compile with memory debugging
|
||||||
CPolyhedron_AllocByNew *pAllocated = new ( pMemory ) CPolyhedron_AllocByNew;
|
CPolyhedron_AllocByNew *pAllocated = new ( pMemory ) CPolyhedron_AllocByNew;
|
||||||
#include "tier0/memdbgon.h"
|
#include "tier0/memdbgon.h"
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ public:
|
|||||||
int iReferenceCount;
|
int iReferenceCount;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Release( void ) override
|
virtual void Release( void )
|
||||||
{
|
{
|
||||||
#ifdef DBGFLAG_ASSERT
|
#ifdef DBGFLAG_ASSERT
|
||||||
--iReferenceCount;
|
--iReferenceCount;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user