/* ** Command & Conquer Generals(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 . */ //////////////////////////////////////////////////////////////////////////////// // // // (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;; TextureLoader::Validate_Texture_Size( m_textureWidth, m_textureHeight); WW3DFormat w3dFormat = TypeToW3DFormat( m_format ); if ( w3dFormat == WW3D_FORMAT_UNKNOWN ) { return NULL; } m_texture = MSGNEW("TextureClass") TextureClass ( m_textureWidth, m_textureHeight, w3dFormat, TextureClass::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; }