Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memory>
- #include "hud.h"
- #include "cl_util.h"
- #include "logging.h"
- #include "gl_texture.h"
- cl_texture_t m_pTextures[ MAX_TEXTURES ];
- int m_iNumTextures;
- GLuint curTexID = TEXTURE_BASE;
- cl_texture_t* PrecacheVTFFile( const char* szFileName )
- {
- cl_texture_t* pTexture = NULL; // Tidy stuff.
- char szPath[ MAX_PATH ],
- szFinalPath[ MAX_PATH ];
- VTFLib :: CVTFFile vtf; // Put all of this here?
- int iMipLevel = MIP_DUMMY;
- if( !gVTFM.IsVTFAllowed( ) || !g_pFileSystem || !gOGLM.IsGLAllowed( ) )
- return nullptr;
- if( !g_pFileSystem -> GetLocalPath( "materials", szPath, sizeof( szPath ) ) )
- return nullptr;
- snprintf( szFinalPath, sizeof( szFinalPath ), "%s\\%s.vtf", szPath, szFileName );
- if( !vtf.Load( szFinalPath ) || !vtf.IsLoaded( ) ) // This can probably be improved along with the first checks.
- return nullptr;
- pTexture = &m_pTextures[ m_iNumTextures ]; // Some Trinity thing, figure out what this is.
- int someSizeData = vtf.ComputeImageSize( vtf.GetWidth( ), vtf.GetHeight( ), vtf.GetDepth( ), iMipLevel, vtf.GetFormat( ) ); // Raw image (for testing) actually has 7 (or 8?) mipmaps that I can use, implement that.
- vlByte* rawImageData = vtf.GetData( 0, 0, 0, 0 ); // Can't get raw data so just replace with them all with 0.
- auto allocMemData = std :: make_unique< vlByte[ ] >( someSizeData ); // Don't forget deletions of it!
- if( ( !vtf.GetFormat( ) == IMAGE_FORMAT_RGBA8888 ) && !vtf.Convert( rawImageData, allocMemData.get( ), vtf.GetWidth( ), vtf.GetHeight( ), vtf.GetFormat( ), IMAGE_FORMAT_RGBA8888 ) )
- return nullptr; // This check is quite stupid, redo.
- glGenTextures( 1, &curTexID ); // Nasty displaying hack. Look more into for future bug report.
- glBindTexture( GL_TEXTURE_2D, curTexID ); // I'm a noob at OpenGL, investigate at a later date to make sure this works.
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, vtf.GetWidth( ), vtf.GetHeight( ), 0, GL_RGBA8, GL_UNSIGNED_BYTE, allocMemData.get( ) ); // Figure out if uploading like this is okay.
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
- strcpy( pTexture -> szName, szFileName );
- pTexture -> iWidth = vtf.GetWidth( ); // Texture information so I can recall it. Expand upon this.
- pTexture -> iHeight = vtf.GetHeight( );
- pTexture -> iFormat = vtf.GetFormat( ); // Strange reason, but it doesn't output the new format I converted it to, but the original.
- pTexture -> iIndex = curTexID;
- gLS.Log( 1, "iWidth: %d\niHeight: %d\niFormat: %d\niIndex: %d\nm_iNumTextures: %d\ncurTexID: %d\nszFileName: %s\nszPath: %s\nszFinalPath %s\nszName: %s\n\n", pTexture -> iWidth, pTexture -> iHeight, pTexture -> iFormat, pTexture -> iIndex, m_iNumTextures, curTexID, szFileName, szPath, szFinalPath, pTexture -> szName );
- m_iNumTextures++;
- curTexID++;
- return pTexture; // Good?
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement