| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- //----------------------------------------------------------------------------
- //
- // Westwood Studios Pacific.
- //
- // Confidential Information
- // Copyright (C) 2001 - All Rights Reserved
- //
- //----------------------------------------------------------------------------
- //
- // Project: Generals
- //
- // Module: Video
- //
- // File name: W3DDevice/GameClient/W3DVideoBuffer.cpp
- //
- // Created: 10/23/01 TR
- //
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Includes
- //----------------------------------------------------------------------------
- #include "Common/GameMemory.h"
- #include "WW3D2/texture.h"
- #include "WW3D2/textureloader.h"
- #include "W3DDevice/GameClient/W3DVideoBuffer.h"
- //----------------------------------------------------------------------------
- // Externals
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Defines
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Types
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Data
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Public Data
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Prototypes
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Functions
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Public Functions
- //----------------------------------------------------------------------------
- //============================================================================
- // W3DVideoBuffer::W3DVideoBuffer
- //============================================================================
- W3DVideoBuffer::W3DVideoBuffer( VideoBuffer::Type format )
- : VideoBuffer(format),
- m_texture(NULL),
- m_surface(NULL)
- {
- }
- //============================================================================
- // W3DVideoBuffer::SetBuffer
- //============================================================================
- Bool W3DVideoBuffer::allocate( UnsignedInt width, UnsignedInt height )
- {
- free();
- m_width = width;
- m_height = height;
- m_textureWidth = width;;
- m_textureHeight = height;;
- unsigned int temp_depth=1;
- TextureLoader::Validate_Texture_Size( m_textureWidth, m_textureHeight, temp_depth);
- WW3DFormat w3dFormat = TypeToW3DFormat( m_format );
-
- if ( w3dFormat == WW3D_FORMAT_UNKNOWN )
- {
- return NULL;
- }
- m_texture = MSGNEW("TextureClass") TextureClass ( m_textureWidth, m_textureHeight, w3dFormat, MIP_LEVELS_1 );
- if ( m_texture == NULL )
- {
- return FALSE;
- }
- if ( lock() == NULL )
- {
- free();
- return FALSE;
- }
- unlock();
- return TRUE;
- }
- //============================================================================
- // W3DVideoBuffer::~W3DVideoBuffer
- //============================================================================
- W3DVideoBuffer::~W3DVideoBuffer()
- {
- free();
- }
- //============================================================================
- // W3DVideoBuffer::lock
- //============================================================================
- void* W3DVideoBuffer::lock( void )
- {
- void *mem = NULL;
- if ( m_surface != NULL )
- {
- unlock();
- }
- m_surface = m_texture->Get_Surface_Level();
- if ( m_surface )
- {
- mem = m_surface->Lock( (Int*) &m_pitch );
- }
- return mem;
- }
- //============================================================================
- // W3DVideoBuffer::unlock
- //============================================================================
- void W3DVideoBuffer::unlock( void )
- {
- if ( m_surface != NULL )
- {
- m_surface->Unlock();
- m_surface->Release_Ref();
- m_surface = NULL;
- }
- }
- //============================================================================
- // W3DVideoBuffer::valid
- //============================================================================
- Bool W3DVideoBuffer::valid( void )
- {
- return m_texture != NULL;
- }
- //============================================================================
- // W3DVideoBuffer::reset
- //============================================================================
- void W3DVideoBuffer::free( void )
- {
- unlock();
- if ( m_texture )
- {
- unlock();
- m_texture->Release_Ref();
- m_texture = NULL;
- }
- m_surface = NULL;
- VideoBuffer::free();
- }
- //============================================================================
- // W3DVideoBuffer::TypeToW3DFormat
- //============================================================================
- WW3DFormat W3DVideoBuffer::TypeToW3DFormat( VideoBuffer::Type format )
- {
- WW3DFormat w3dFormat = WW3D_FORMAT_UNKNOWN;
- switch ( format )
- {
- case TYPE_X8R8G8B8:
- w3dFormat = WW3D_FORMAT_X8R8G8B8;
- break;
- case TYPE_R8G8B8:
- w3dFormat = WW3D_FORMAT_R8G8B8;
- break;
- case TYPE_R5G6B5:
- w3dFormat = WW3D_FORMAT_R5G6B5;
- break;
- case TYPE_X1R5G5B5:
- w3dFormat = WW3D_FORMAT_X1R5G5B5;
- break;
- }
- return w3dFormat;
- }
- //============================================================================
- // W3DFormatToType
- //============================================================================
- VideoBuffer::Type W3DVideoBuffer::W3DFormatToType( WW3DFormat w3dFormat )
- {
- Type format = TYPE_UNKNOWN;
- switch ( w3dFormat )
- {
- case WW3D_FORMAT_X8R8G8B8:
- format = VideoBuffer::TYPE_X8R8G8B8;
- break;
- case WW3D_FORMAT_R8G8B8:
- format = VideoBuffer::TYPE_R8G8B8;
- break;
- case WW3D_FORMAT_R5G6B5:
- format = VideoBuffer::TYPE_R5G6B5;
- break;
- case WW3D_FORMAT_X1R5G5B5:
- format = VideoBuffer::TYPE_X1R5G5B5;
- break;
- }
- return format;
- }
|