This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

View File

@@ -0,0 +1,36 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef AMALGAMATEDTEXTURE_VARS_H
#define AMALGAMATEDTEXTURE_VARS_H
#ifdef _WIN32
#pragma once
#endif
#include "filesystem.h"
#include "tier0/dbg.h"
#define MAX_IMAGES_PER_FRAME 4
enum PackingMode_t
{
PCKM_INVALID,
PCKM_FLAT, // Default mode - every frame consumes entire RGBA space
PCKM_RGB_A, // Some sequences consume RGB space and some Alpha space
};
enum SeqMode_t
{
SQM_RGBA, // Sequence occupies entire RGBA space
SQM_RGB, // Sequence occupies only RGB space
SQM_ALPHA, // Sequence occupies only Alpha space
SQM_ALPHA_INVALID,
};
#endif // AMALGAMATEDTEXTURE_VARS_H

View File

@@ -0,0 +1,117 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef DMEAMALGAMATEDTEXTURE_H
#define DMEAMALGAMATEDTEXTURE_H
#ifdef _WIN32
#pragma once
#endif
#include "materialobjects/amalgtexturevars.h"
#include "bitmap/floatbitmap.h"
#include "tier2/tier2.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmehandle.h"
#include "datamodel/dmattributevar.h"
#include "resourcefile/resourcedictionary.h"
#include "materialobjects/dmeimage.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeSheetImage; // known in mksheet as a SequenceFrame
class CDmeSheetSequenceFrame; // known in mksheet as a SequenceEntry
class CDmeSheetSequence;
class CResourceStream;
class CDmeImage;
//-----------------------------------------------------------------------------
// The Amalgamated texture itself.
//-----------------------------------------------------------------------------
class CDmeAmalgamatedTexture : public CDmElement
{
DEFINE_ELEMENT( CDmeAmalgamatedTexture, CDmElement );
public:
// Called when attributes change
virtual void OnAttributeChanged( CDmAttribute *pAttribute ) {}
virtual void OnAttributeArrayElementAdded( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
virtual void OnAttributeArrayElementRemoved( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
void Init( const char *pShtFileName = NULL, bool bUseCurrentDir = false );
void *WriteFile( CResourceStream *pStream, ResourceId_t nTextureResourceId );
// old-style
void WriteFile( const char *pFileName, bool bVerbose = false );
bool DetermineBestPacking();
bool PackImages( bool bGenerateImage, int nWidth );
int GetWidth() { return m_nWidth; }
int GetHeight() { return m_nHeight; }
void GetSize( int &width, int &height )
{
width = m_nWidth;
height = m_nHeight;
}
void SetCurrentSequenceClamp( bool bState );
void SetPackingMode( int mode );
void CreateNewSequence( int mode = PCKM_FLAT );
void SetSequenceType( int eMode );
bool CurrentSequenceExists();
void CreateFrame( CUtlVector<char *> &frameNames, float ftime = 1.0f );
void AddImage( CDmeSheetSequenceFrame *pNewSequenceFrame, char *pImageName );
int GetSequenceCount(){ return m_SequenceCount; }
CDmeImage *GetPackedImage();
bool WriteTGA( const char *pFileName );
private:
CDmeSheetImage *FindImage( const char *pImageName );
int GetPackingMode();
int GetSequenceType();
void ValidateImagePacking( CDmeSheetImage *pBitmap, char *pImageName );
bool PackImagesFlat( bool bGenerateImage, int nWidth );
bool PackImagesRGBA( bool bGenerateImage, int nWidth );
float UCoord( int u )
{
float uc = u + 0.5;
return uc / (float) m_nWidth;
}
float VCoord( int v )
{
float vc = v + 0.5;
return vc / (float) m_nHeight;
}
CDmaElementArray< CDmeSheetImage > m_ImageList;
CDmaVar< int > m_ePackingMode;
CDmaElementArray< CDmeSheetSequence > m_Sequences;
CDmeSheetSequence *m_pCurSequence;
CDmaVar< int > m_nWidth;
CDmaVar< int > m_nHeight;
CDmaElement< CDmeImage > m_pPackedImage;
int m_SequenceCount;
};
inline CDmeImage *CDmeAmalgamatedTexture::GetPackedImage()
{
return m_pPackedImage;
}
#endif // DMEAMALGAMATEDTEXTURE_H

View File

@@ -0,0 +1,151 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef DMEDEMO2_H
#define DMEDEMO2_H
#ifdef _WIN32
#pragma once
#endif
#include "datamodel/dmelement.h"
#include "datamodel/dmattributevar.h"
//-----------------------------------------------------------------------------
// Demo 2: Defining editable versions of the in-game classes
//
// This is a tricky thing to get right. You want to design for several things:
// 1) Ease of data change
// 2) Separation of editable state from user interface
// 3) Ease of discoverability of data from just looking at the output file
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Dme version of a quad
// Very straightforward, this is identical to the in-game representation
// with the exception of the 'name' attribute all DmElements have.
//-----------------------------------------------------------------------------
class CDmeQuadV2 : public CDmElement
{
DEFINE_ELEMENT( CDmeQuadV2, CDmElement );
public:
CDmaVar< int > m_X0;
CDmaVar< int > m_Y0;
CDmaVar< int > m_X1;
CDmaVar< int > m_Y1;
CDmaColor m_Color;
};
//-----------------------------------------------------------------------------
// Dme version of a list of quads
// Note that we hide the list of quads here and instead provide a set of
// service functions limited to the types of editing operations we expect
// to perform on the quad list
//
// Also note when you need to edit an array of struct data,
// it often results in easier to use code if you create a dme class which
// represents the array of structs (CDmeQuadListV2 in this case) with utility
// methods as opposed to simply using CDmaElementArray< CDmeQuadV2 > in
// containing classes (CDmeQuadDocV2 in this case)
//
// You also want to avoid using parallel arrays of CDmaIntArrays<> etc
// for each field of the struct. It sucks having to add an element into
// each array every time you add a struct
//-----------------------------------------------------------------------------
class CDmeQuadListV2 : public CDmElement
{
DEFINE_ELEMENT( CDmeQuadListV2, CDmElement );
public:
// List management
void AddQuad( CDmeQuadV2 *pQuad );
CDmeQuadV2 *FindQuadByName( const char *pName );
void RemoveQuad( CDmeQuadV2 *pQuad );
void RemoveAllQuads();
// Render order management
void MoveToFront( CDmeQuadV2 *pQuad );
void MoveToBack( CDmeQuadV2 *pQuad );
private:
CDmaElementArray< CDmeQuadV2 > m_Quads;
};
//-----------------------------------------------------------------------------
// Dme version of a the editor 'document'
//
// The interface here is designed to be able to be used directly from
// python. I'm currently hiding direct access to CDmeQuadV2 to here to
// make python usage easier, but python can handle it if we pass CDmeQuadV2s
// in the interface. We may well want to start passing them around once
// we get to the VGUI-based editor.
//
// Early editors we wrote didn't clearly separate data from UI at the doc
// level which resulted in a bunch of complexity as our tools got bigger.
// Actually making a Dm element which contains a notion of selection in it
// I believe will reduce this problem in the future (this is still an untested
// theory in-house, although other 3rd party editors use this technique also).
//
// Remember that only attributes can be saved and have undo support.
// If you want to add members to a Dme element which are not saved and
// never need undo, you can either use normal non-CDma members,
// or mark attributes to not be saved. In this case, I make the
// selection state be an attribute to get undo but mark the selection
// attribute to not save it to the file.
//-----------------------------------------------------------------------------
class CDmeQuadDocV2 : public CDmElement
{
DEFINE_ELEMENT( CDmeQuadDocV2, CDmElement );
public:
// Adds quad, resets selection to new quad
void AddQuad( const char *pName, int x0, int y0, int x1, int y1 );
// Clears selection
void ClearSelection();
// Adds quad to selection
void AddQuadToSelection( const char *pName );
// Deletes selected quads
void DeleteSelectedQuads();
// Changes quad color
void SetSelectedQuadColor( int r, int g, int b, int a );
// Moves quads
void MoveSelectedQuads( int dx, int dy );
// Resizes selected quad (works only when 1 quad is selected)
void ResizeSelectedQuad( int nWidth, int nHeight );
// Moves selected quad to front/back (works only when 1 quad is selected)
void MoveSelectedToFront();
void MoveSelectedToBack();
private:
CDmaElement< CDmeQuadListV2 > m_Quads;
CDmaElementArray< CDmeQuadV2 > m_SelectedQuads;
};
//-----------------------------------------------------------------------------
// Usage in python (works from the debugger!)
//-----------------------------------------------------------------------------
// 1) Python at commandline
// 2) import vs
// 3) vs.dm.SetUndoEnabled( 0 )
// 4) doc = vs.CreateElement( DmeQuadDocV2, root, -1 )
// 5) … doc stuff, e.g. doc.AddQuad( 'quad1', 5, 5, 30, 40 )
// 6) vs.dm.SaveToFile( file name, , keyvalues2, dmx, doc )
#endif // DMEDEMO2_H

View File

@@ -0,0 +1,163 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef DMEDEMO3_H
#define DMEDEMO3_H
#ifdef _WIN32
#pragma once
#endif
#include "datamodel/dmelement.h"
#include "datamodel/dmattributevar.h"
//-----------------------------------------------------------------------------
// Demo 3: Creating an in-game editor for the editable versions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// No changes here from demo 2
//-----------------------------------------------------------------------------
class CDmeQuadV3 : public CDmElement
{
DEFINE_ELEMENT( CDmeQuadV3, CDmElement );
// NEW METHODS IN VERSION 3, needed by renderer
public:
int MinX() const { return MIN( m_X0, m_X1 ); }
int MinY() const { return MIN( m_Y0, m_Y1 ); }
int MaxX() const { return MAX( m_X0, m_X1 ); }
int MaxY() const { return MAX( m_Y0, m_Y1 ); }
// OLD METHODS FROM VERSION 3
public:
CDmaVar< int > m_X0;
CDmaVar< int > m_Y0;
CDmaVar< int > m_X1;
CDmaVar< int > m_Y1;
CDmaColor m_Color;
};
//-----------------------------------------------------------------------------
// No changes here from demo 2
//-----------------------------------------------------------------------------
class CDmeQuadListV3 : public CDmElement
{
DEFINE_ELEMENT( CDmeQuadListV3, CDmElement );
// NEW STUFF FOR DEMO 3
public:
// Iteration necessary to render
int GetQuadCount() const;
CDmeQuadV3 *GetQuad( int i );
// OLD STUFF FROM DEMO 2
public:
// List management
void AddQuad( CDmeQuadV3 *pQuad );
CDmeQuadV3 *FindQuadByName( const char *pName );
void RemoveQuad( CDmeQuadV3 *pQuad );
void RemoveAllQuads();
// Render order management
void MoveToFront( CDmeQuadV3 *pQuad );
void MoveToBack( CDmeQuadV3 *pQuad );
private:
CDmaElementArray< CDmeQuadV3 > m_Quads;
};
//-----------------------------------------------------------------------------
// Dme version of a the editor 'document'
//
// The interface here is designed to be able to be used directly from
// python. I'm currently hiding direct access to CDmeQuadV3 to here to
// make python usage easier, but python can handle it if we pass CDmeQuadV3s
// in the interface. We may well want to start passing them around once
// we get to the VGUI-based editor.
//
// Early editors we wrote didn't clearly separate data from UI at the doc
// level which resulted in a bunch of complexity as our tools got bigger.
// Actually making a Dm element which contains a notion of selection in it
// I believe will reduce this problem in the future (this is still an untested
// theory in-house, although other 3rd party editors use this technique also).
//
// Remember that only attributes can be saved and have undo support.
// If you want to add members to a Dme element which are not saved and
// never need undo, you can either use normal non-CDma members,
// or mark attributes to not be saved. In this case, I make the
// selection state be an attribute to get undo but mark the selection
// attribute to not save it to the file.
//-----------------------------------------------------------------------------
class CDmeQuadDocV3 : public CDmElement
{
DEFINE_ELEMENT( CDmeQuadDocV3, CDmElement );
// NEW STUFF FOR DEMO 3
public:
// Iteration necessary to render
int GetQuadCount() const;
CDmeQuadV3 *GetQuad( int i );
// Iteration necessary to render
int GetSelectedQuadCount() const;
CDmeQuadV3 *GetSelectedQuad( int i );
// Add quads in rect to selection
void AddQuadsInRectToSelection( int x0, int y0, int x1, int y1 );
// Is point in selected quad?
bool IsPointInSelectedQuad( int x, int y ) const;
// OLD STUFF FROM DEMO 2
public:
// Adds quad, resets selection to new quad
void AddQuad( const char *pName, int x0, int y0, int x1, int y1 );
// Clears selection
void ClearSelection();
// Adds quad to selection
void AddQuadToSelection( const char *pName );
// Deletes selected quads
void DeleteSelectedQuads();
// Changes quad color
void SetSelectedQuadColor( int r, int g, int b, int a );
// Moves quads
void MoveSelectedQuads( int dx, int dy );
// Resizes selected quad (works only when 1 quad is selected)
void ResizeSelectedQuad( int nWidth, int nHeight );
// Moves selected quad to front/back (works only when 1 quad is selected)
void MoveSelectedToFront();
void MoveSelectedToBack();
private:
CDmaElement< CDmeQuadListV3 > m_QuadList;
CDmaElementArray< CDmeQuadV3 > m_SelectedQuads;
};
//-----------------------------------------------------------------------------
// Usage in python (works from the debugger!)
//-----------------------------------------------------------------------------
// 1) Python at commandline
// 2) import vs
// 3) vs.dm.SetUndoEnabled( 0 )
// 4) doc = vs.CreateElement( DmeQuadDocV3, root, -1 )
// 5) … doc stuff, e.g. doc.AddQuad( 'quad1', 5, 5, 30, 40 )
// 6) vs.dm.SaveToFile( file name, , keyvalues2, dmx, doc )
#endif // DMEDEMO3_H

View File

@@ -0,0 +1,217 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// A class representing an image
//
//=============================================================================
#ifndef DMEIMAGE_H
#define DMEIMAGE_H
#ifdef _WIN32
#pragma once
#endif
#include "datamodel/dmelement.h"
#include "datamodel/dmattributevar.h"
#include "bitmap/imageformat.h"
#include "bitmap/floatbitmap.h"
//-----------------------------------------------------------------------------
// A class representing an image (2d or 3d bitmap)
//-----------------------------------------------------------------------------
class CDmeImage : public CDmElement
{
DEFINE_ELEMENT( CDmeImage, CDmElement );
public:
virtual void OnAttributeChanged( CDmAttribute *pAttribute );
virtual void OnElementUnserialized();
virtual void OnElementSerialized();
public:
// Initializes the buffer, but doesn't allocate space
void Init( int nWidth, int nHeight, int nDepth, ImageFormat fmt, float flGamma );
// Gets dimensions
int Width() const;
int Height() const;
int Depth() const;
// Methods related to image format
ImageFormat Format() const;
const char *FormatName() const;
// Methods related to gamma
float Gamma() const;
// returns the size of one row
int RowSizeInBytes( ) const;
// returns the size of one z slice
int ZSliceSizeInBytes( ) const;
// returns the total size of the image
int SizeInBytes( ) const;
// Sets the storage mode. False = the bits are put in the attribute.
// True = the bits are put in the float bitmap
void SetFloatBitmapStorageMode( bool bFloatBitmap, bool bDiscardContents = false );
bool IsUsingFloatBitmapStorageMode() const;
bool HasImageData() const;
// Used for computation
// void BeginComputation();
// void EndComputation();
// Copies the image from the src in whatever storage form they are currently in
// Potentially color converting
void CopyFrom( CDmeImage *pSrcImage, ImageFormat fmt = IMAGE_FORMAT_UNKNOWN );
// Color converts the image into the destination format.
// Has no immediate effect if the image is in 'float bitmap' mode.
// Instead, it will cause it to use this format when it eventually
// reconverts back to 'attribute' mode.
// NOTE: Doesn't work to convert to a compressed format.
void ConvertFormat( ImageFormat fmt );
// Reinterprets the image as a new color format; no work is done
// The old + new color formats must be the same size in bytes
void ReinterpetFormat( ImageFormat fmt );
//
// NOTE: The following methods operate on the bits attribute
//
// Used for bit modification
CUtlBinaryBlock &BeginModification( );
void EndModification( );
// returns a pointer to the image bits buffer
const void *ImageBits();
// Copies bits into the image bits buffer
void SetImageBits( const void *pBits, int nSize );
// Compresses an image into this image
void CompressImage( CDmeImage *pSrcImage, ImageFormat fmt );
//
// NOTE: The following methods operate on the float-bitmap version of the bits attribute
//
// returns a pointer to the image bits buffer as a float bitmap
const FloatBitMap_t *FloatBitmap();
// Allows you to directly manipulate the float bitmap
FloatBitMap_t &BeginFloatBitmapModification( );
void EndFloatBitmapModification( );
// Creates an image 1/4 size of the source using a box filter
void QuarterSize( CDmeImage *pSrcImage );
// Downsample using nice filter (NOTE: Dest bitmap needs to have been initialized w/ final size)
void DownsampleNiceFiltered( const DownsampleInfo_t& info, CDmeImage *pSrcImage );
// Sets the color of every pixel
void Clear( float r, float g, float b, float a );
private:
enum StorageMode_t
{
DMEIMAGE_STORAGE_NONE = 0,
DMEIMAGE_STORAGE_FLOAT_BITMAP,
DMEIMAGE_STORAGE_ATTRIBUTE,
};
CDmaVar<int> m_nWidth;
CDmaVar<int> m_nHeight;
CDmaVar<int> m_nDepth;
CDmaVar<int> m_nFormat;
CDmaVar<float> m_flGamma;
CDmaBinaryBlock m_Bits;
// Used for computation
DmAttributeModifyHandle_t m_hModify;
StorageMode_t m_Mode;
bool m_bInModification;
bool m_bInFloatBitmapModification;
bool m_bIgnoreChangedBitsAttribute;
FloatBitMap_t m_ComputeBits;
};
//-----------------------------------------------------------------------------
// Gets dimensions
//-----------------------------------------------------------------------------
inline int CDmeImage::Width() const
{
return ( m_Mode != DMEIMAGE_STORAGE_FLOAT_BITMAP ) ? m_nWidth : m_ComputeBits.NumCols();
}
inline int CDmeImage::Height() const
{
return ( m_Mode != DMEIMAGE_STORAGE_FLOAT_BITMAP ) ? m_nHeight : m_ComputeBits.NumRows();
}
inline int CDmeImage::Depth() const
{
return ( m_Mode != DMEIMAGE_STORAGE_FLOAT_BITMAP ) ? m_nDepth : m_ComputeBits.NumSlices();
}
//-----------------------------------------------------------------------------
// Methods related to gamma
//-----------------------------------------------------------------------------
inline float CDmeImage::Gamma() const
{
return m_flGamma;
}
//-----------------------------------------------------------------------------
// returns a pointer to the image bits buffer
//-----------------------------------------------------------------------------
inline const void *CDmeImage::ImageBits()
{
SetFloatBitmapStorageMode( false );
return m_Bits.Get();
}
inline bool CDmeImage::IsUsingFloatBitmapStorageMode() const
{
return ( m_Mode == DMEIMAGE_STORAGE_FLOAT_BITMAP );
}
inline bool CDmeImage::HasImageData() const
{
return ( m_Mode != DMEIMAGE_STORAGE_NONE );
}
//-----------------------------------------------------------------------------
// An array of images (used for cubemaps or texture arrays)
//-----------------------------------------------------------------------------
class CDmeImageArray : public CDmElement
{
DEFINE_ELEMENT( CDmeImageArray, CDmElement );
public:
int ImageCount() const;
CDmeImage *GetImage( int nIndex ) const;
CDmeImage *AddImage( );
void AddImage( CDmeImage *pImage );
// Gets dimensions
int Width() const;
int Height() const;
int Depth() const;
ImageFormat Format() const;
bool IsConsistent( int nWidth, int nHeight, int nDepth, ImageFormat fmt ) const;
private:
CDmaElementArray< CDmeImage > m_Images;
};
#endif // DMEIMAGE_H

View File

@@ -0,0 +1,126 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// A class representing a procedural texture
//
//=============================================================================
#ifndef DMEPRECOMPILEDTEXTURE_H
#define DMEPRECOMPILEDTEXTURE_H
#ifdef _WIN32
#pragma once
#endif
#include "datamodel/dmelement.h"
#include "materialobjects/dmetexture.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CDmeTexture;
//-----------------------------------------------------------------------------
// A Dme element that describes a texture processing operation
//-----------------------------------------------------------------------------
class CDmeTextureProcessor : public CDmElement
{
DEFINE_ELEMENT( CDmeTextureProcessor, CDmElement );
public:
virtual void ProcessTexture( CDmeTexture *pSrcTexture, CDmeTexture *pDstTexture ) = 0;
};
//-----------------------------------------------------------------------------
// A precompiled texture
//-----------------------------------------------------------------------------
class CDmePrecompiledTexture : public CDmElement
{
DEFINE_ELEMENT( CDmePrecompiledTexture, CDmElement );
public:
bool ValidateValues();
template< class T > T *AddProcessor( const char *pName );
template< class T > T *FindProcessor( const char *pName );
public:
CDmaElementArray< CDmeTextureProcessor > m_Processors;
CDmaElement< CDmeTexture > m_pSourceTexture;
CDmaString m_ImageFileName;
CDmaVar< int > m_nStartFrame;
CDmaVar< int > m_nEndFrame;
CDmaVar< int > m_nTextureArraySize;
CDmaVar< int > m_nVolumeTextureDepth;
CDmaVar< int > m_nTextureType; // 0 = normal, 1 = cubemap
CDmaVar< float > m_flBumpScale;
CDmaVar< float > m_flPFMScale;
CDmaVar< int > m_nFilterType; // See DmeTextureFilter_t
CDmaVar< bool > m_bClampS;
CDmaVar< bool > m_bClampT;
CDmaVar< bool > m_bClampU;
CDmaVar< bool > m_bLoadMipLevels;
CDmaVar< bool > m_bBorder;
CDmaVar< bool > m_bNormalMap; // FIXME: Should normal/normalga be combined?
CDmaVar< bool > m_bSSBump;
CDmaVar< bool > m_bNoMip; // FIXME: Should nomip/allmips be combined?
CDmaVar< bool > m_bAllMips;
CDmaVar< bool > m_bNoLod;
CDmaVar< bool > m_bNoDebugOverride;
CDmaVar< bool > m_bNoCompression;
CDmaVar< bool > m_bHintDxt5Compression;
};
template< class T > inline T *CDmePrecompiledTexture::AddProcessor( const char *pName )
{
T* pProcessor = CreateElement< T >( pName, GetFileId() );
m_Processors.AddToTail( pProcessor );
return pProcessor;
}
template< class T > inline T *CDmePrecompiledTexture::FindProcessor( const char *pName )
{
for ( int i = 0; i < m_Processors.Count(); ++i )
{
if ( !Q_stricmp( pName, m_Processors[i]->GetName() ) )
return CastElement< T >( m_Processors[i] );
}
return NULL;
}
//-----------------------------------------------------------------------------
// Texture processors
//-----------------------------------------------------------------------------
class CDmeTP_ComputeMipmaps : public CDmeTextureProcessor
{
DEFINE_ELEMENT( CDmeTP_ComputeMipmaps, CDmeTextureProcessor );
public:
virtual void ProcessTexture( CDmeTexture *pSrcTexture, CDmeTexture *pDstTexture );
CDmaVar< bool > m_bNoNiceFiltering;
CDmaVar< bool > m_bAlphaTestDownsampling;
CDmaVar< float > m_flAlphaTestDownsampleThreshhold;
CDmaVar< float > m_flAlphaTestDownsampleHiFreqThreshhold;
};
//-----------------------------------------------------------------------------
// Changes color channels
//-----------------------------------------------------------------------------
class CDmeTP_ChangeColorChannels : public CDmeTextureProcessor
{
DEFINE_ELEMENT( CDmeTP_ChangeColorChannels, CDmeTextureProcessor );
public:
virtual void ProcessTexture( CDmeTexture *pSrcTexture, CDmeTexture *pDstTexture );
void ProcessImage( CDmeImage *pDstImage, CDmeImage *pSrcImage );
CDmaVar< int > m_nMaxChannels;
};
#endif // DMEPRECOMPILEDTEXTURE_H

View File

@@ -0,0 +1,78 @@
//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef DMESHEETSEQUENCE_H
#define DMESHEETSEQUENCE_H
#ifdef _WIN32
#pragma once
#endif
#include "materialobjects/amalgtexturevars.h"
#include "bitmap/floatbitmap.h"
#include "datamodel/dmelement.h"
#include "datamodel/dmattributevar.h"
class CDmeSheetSequence;
class CDmeSheetImage : public CDmElement
{
DEFINE_ELEMENT( CDmeSheetImage, CDmElement );
public:
// Called when attributes change
virtual void OnAttributeChanged( CDmAttribute *pAttribute ) {}
virtual void OnAttributeArrayElementAdded( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
virtual void OnAttributeArrayElementRemoved( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
CDmeSheetSequence *FindSequence( int index );
FloatBitMap_t *m_pImage;
// where it ended up packed
CDmaVar< int > m_XCoord;
CDmaVar< int > m_YCoord;
CDmaElementArray< CDmeSheetSequence > m_mapSequences;
};
class CDmeSheetSequenceFrame : public CDmElement
{
DEFINE_ELEMENT( CDmeSheetSequenceFrame, CDmElement );
public:
// Called when attributes change
virtual void OnAttributeChanged( CDmAttribute *pAttribute ) {}
virtual void OnAttributeArrayElementAdded( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
virtual void OnAttributeArrayElementRemoved( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
// Up to 4 images can be used in a frame
CDmaElementArray< CDmeSheetImage > m_pSheetImages;
CDmaVar< float > m_fDisplayTime;
};
class CDmeSheetSequence : public CDmElement
{
DEFINE_ELEMENT( CDmeSheetSequence, CDmElement );
public:
// Called when attributes change
virtual void OnAttributeChanged( CDmAttribute *pAttribute ) {}
virtual void OnAttributeArrayElementAdded( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
virtual void OnAttributeArrayElementRemoved( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
CDmaVar< int > m_nSequenceNumber;
CDmaVar< bool > m_Clamp; // as opposed to loop
CDmaVar< int > m_eMode;
CDmaElementArray< CDmeSheetSequenceFrame > m_Frames;
};
#endif // DMESHEETSEQUENCE_H

View File

@@ -0,0 +1,418 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// A class representing a procedural texture
//
//=============================================================================
#ifndef DMETEXTURE_H
#define DMETEXTURE_H
#ifdef _WIN32
#pragma once
#endif
#include "datamodel/dmelement.h"
#include "materialsystem/materialsystemutil.h"
#include "materialobjects/dmeimage.h"
#include "tier1/functors.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
enum ImageFormat;
//-----------------------------------------------------------------------------
// Compression types
//-----------------------------------------------------------------------------
enum DmeTextureCompress_t
{
DMETEXTURE_COMPRESS_DEFAULT = 0,
DMETEXTURE_COMPRESS_NONE,
DMETEXTURE_COMPRESS_DXT1,
DMETEXTURE_COMPRESS_DXT5,
};
//-----------------------------------------------------------------------------
// Filter types
//-----------------------------------------------------------------------------
enum DmeTextureFilter_t
{
DMETEXTURE_FILTER_DEFAULT = 0,
DMETEXTURE_FILTER_ANISOTROPIC,
DMETEXTURE_FILTER_TRILINEAR,
DMETEXTURE_FILTER_BILINEAR,
DMETEXTURE_FILTER_POINT,
};
//-----------------------------------------------------------------------------
// Mipmap types
//-----------------------------------------------------------------------------
enum DmeTextureMipmap_t
{
DMETEXTURE_MIPMAP_DEFAULT = 0,
DMETEXTURE_MIPMAP_ALL_LEVELS,
DMETEXTURE_MIPMAP_NONE,
};
//-----------------------------------------------------------------------------
// Texture types
//-----------------------------------------------------------------------------
enum DmeTextureType_t
{
DMETEXTURE_TYPE_NORMAL = 0,
DMETEXTURE_TYPE_CUBEMAP,
};
//-----------------------------------------------------------------------------
// A class for textures
//-----------------------------------------------------------------------------
class CDmeTextureFrame : public CDmElement
{
DEFINE_ELEMENT( CDmeTextureFrame, CDmElement );
public:
int MipLevelCount() const;
CDmeImageArray *GetMipLevel( int nIndex ) const;
void AddMipLevel( CDmeImageArray *pImages );
CDmeImageArray *AddMipLevel( );
int ImageCount() const;
private:
// Mip levels for the texture
CDmaElementArray< CDmeImageArray > m_MipLevels;
};
//-----------------------------------------------------------------------------
// Helper functors
//-----------------------------------------------------------------------------
template< typename ObjectType_t > class CImageMemberFunctor
{
public:
CImageMemberFunctor( ObjectType_t *pObject, bool (ObjectType_t::*pMemberFunc)( CDmeImage * ) )
{
m_pObject = pObject;
m_pMemberFunc = pMemberFunc;
}
bool operator()( CDmeImage *pImage )
{
return m_pObject->*m_pMemberFunc( pImage );
}
private:
ObjectType_t *m_pObject;
bool (ObjectType_t::*m_pMemberFunc)( CDmeImage * );
};
class CImageFunctor
{
public:
CImageFunctor( bool (*pMemberFunc)( CDmeImage * ) )
{
m_pFunc = pMemberFunc;
}
bool operator()( CDmeImage *pImage )
{
return m_pFunc( pImage );
}
private:
bool (*m_pFunc)( CDmeImage * );
};
template< typename ObjectType_t > class CImageProcessorMemberFunctor
{
public:
CImageProcessorMemberFunctor( ObjectType_t *pObject, void (ObjectType_t::*pMemberFunc)( CDmeImage *, CDmeImage * ) )
{
m_pObject = pObject;
m_pMemberFunc = pMemberFunc;
}
void operator()( CDmeImage *pDstImage, CDmeImage *pSrcImage )
{
(m_pObject->*m_pMemberFunc)( pDstImage, pSrcImage );
}
private:
ObjectType_t *m_pObject;
void (ObjectType_t::*m_pMemberFunc)( CDmeImage *, CDmeImage * );
};
//-----------------------------------------------------------------------------
// A class for textures
//-----------------------------------------------------------------------------
class CDmeTexture : public CDmElement
{
DEFINE_ELEMENT( CDmeTexture, CDmElement );
public:
// Compression type
void SetCompressionType( DmeTextureCompress_t type );
DmeTextureCompress_t GetCompressionType() const;
// Filter type
void SetFilterType( DmeTextureFilter_t type );
DmeTextureFilter_t GetFilterType() const;
// Mipmap type
void SetMipmapType( DmeTextureMipmap_t type );
DmeTextureMipmap_t GetMipmapType() const;
// Texture type
void SetTextureType( DmeTextureType_t type );
DmeTextureType_t GetTextureType() const;
CDmeTextureFrame *AddFrame();
int FrameCount() const;
CDmeTextureFrame *GetFrame( int nIndex ) const;
void RemoveAllFrames();
// Gets dimensions
int Width() const;
int Height() const;
int Depth() const;
int MipLevelCount() const;
int ImageCount() const;
// Methods related to image format
ImageFormat Format() const;
// Returns all images associated with a particular frame + face (mip count amount)
void GetImages( int nFrame, int nImageIndex, CDmeImage **ppImages, int nSize );
// Iterates over all images, processes them
template< typename Functor > void ProcessTexture( CDmeTexture *pSrcTexture, Functor &func );
template< typename ObjectType_t > void ProcessTexture( CDmeTexture *pSrcTexture, ObjectType_t *pObject, void (ObjectType_t::*pMemberFunc)( CDmeImage *, CDmeImage * ) );
// Iterates over all images, runs a functor
template< typename Functor > void ForEachImage( Functor &func );
template< typename ObjectType_t > void ForEachImage( ObjectType_t *pObject, bool (ObjectType_t::*pMemberFunc)( CDmeImage * ) );
void ForEachImage( bool (*pFunc)( CDmeImage * ) );
void CompressTexture( CDmeTexture *pSrcTexture, ImageFormat fmt );
//-------------------------------------
// Ignore the macro! To use this nifty feature, use code that looks like this:
// pTexture->ForEachImage( &CDmeImage::ConvertFormat, dstFormat );
//-------------------------------------
#define DEFINE_FOR_EACH_IMAGE(N) \
template <typename FUNCTION_RETTYPE FUNC_TEMPLATE_FUNC_PARAMS_##N FUNC_TEMPLATE_ARG_PARAMS_##N> \
void ForEachImage( FUNCTION_RETTYPE ( CDmeImage::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \
{ \
int nFrameCount = FrameCount(); \
for ( int f = 0; f < nFrameCount; ++f ) \
{ \
CDmeTextureFrame *pFrame = GetFrame( f ); \
if ( !pFrame ) \
continue; \
int nMipCount = pFrame->MipLevelCount(); \
for ( int m = 0; m < nMipCount; ++m ) \
{ \
CDmeImageArray *pImageArray = pFrame->GetMipLevel( m ); \
if ( !pImageArray ) \
continue; \
int nImageCount = pImageArray->ImageCount(); \
for ( int i = 0; i < nImageCount; ++i ) \
{ \
CDmeImage *pImage = pImageArray->GetImage( i ); \
if ( !pImage ) \
continue; \
FunctorDirectCall( pImage, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ); \
} \
} \
} \
}
FUNC_GENERATE_ALL( DEFINE_FOR_EACH_IMAGE );
#undef DEFINE_FOR_EACH_IMAGE
public:
virtual void Resolve();
public:
CDmaVar<bool> m_bClampS;
CDmaVar<bool> m_bClampT;
CDmaVar<bool> m_bClampU;
CDmaVar<bool> m_bNoDebugOverride;
CDmaVar<bool> m_bNoLod;
CDmaVar<bool> m_bNiceFiltered;
CDmaVar<bool> m_bNormalMap;
CDmaVar<float> m_flBumpScale;
protected:
// Computes texture flags
int CalcTextureFlags( int nDepth ) const;
// Computes the desired texture format based on flags
ImageFormat ComputeDesiredImageFormat( ImageFormat srcFormat, int nWidth, int nHeight, int nDepth, int nFlags );
CDmaVar<int> m_nCompressType;
CDmaVar<int> m_nFilterType;
CDmaVar<int> m_nMipmapType;
CDmaVar<int> m_nTextureType;
// Array of images in an animated texture
CDmaElementArray< CDmeTextureFrame > m_Frames;
// Computed values
// CTextureReference m_Texture;
// IVTFTexture *m_pVTFTexture;
Vector m_vecReflectivity;
};
//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline void CDmeTexture::SetCompressionType( DmeTextureCompress_t type )
{
m_nCompressType = type;
}
inline DmeTextureCompress_t CDmeTexture::GetCompressionType() const
{
return (DmeTextureCompress_t)m_nCompressType.Get();
}
inline void CDmeTexture::SetFilterType( DmeTextureFilter_t type )
{
m_nFilterType = type;
}
inline DmeTextureFilter_t CDmeTexture::GetFilterType() const
{
return (DmeTextureFilter_t)m_nFilterType.Get();
}
inline void CDmeTexture::SetMipmapType( DmeTextureMipmap_t type )
{
m_nMipmapType = type;
}
inline DmeTextureMipmap_t CDmeTexture::GetMipmapType() const
{
return (DmeTextureMipmap_t)m_nMipmapType.Get();
}
inline void CDmeTexture::SetTextureType( DmeTextureType_t type )
{
m_nTextureType = type;
}
inline DmeTextureType_t CDmeTexture::GetTextureType() const
{
return (DmeTextureType_t)m_nTextureType.Get();
}
inline int CDmeTexture::FrameCount() const
{
return m_Frames.Count();
}
inline CDmeTextureFrame *CDmeTexture::GetFrame( int nIndex ) const
{
return m_Frames[nIndex];
}
//-----------------------------------------------------------------------------
// Invokes a functor on all images in the texture
//-----------------------------------------------------------------------------
template< typename Functor > inline void CDmeTexture::ForEachImage( Functor &func )
{
int nFrameCount = FrameCount();
for ( int f = 0; f < nFrameCount; ++f )
{
CDmeTextureFrame *pFrame = GetFrame( f );
if ( !pFrame )
continue;
int nMipCount = pFrame->MipLevelCount();
for ( int m = 0; m < nMipCount; ++m )
{
CDmeImageArray *pImageArray = pFrame->GetMipLevel( m );
if ( !pImageArray )
continue;
int nImageCount = pImageArray->ImageCount();
for ( int i = 0; i < nImageCount; ++i )
{
CDmeImage *pImage = pImageArray->GetImage( i );
if ( !pImage )
continue;
if ( !func( pImage ) )
break;
}
}
}
}
template< typename ObjectType_t > inline void CDmeTexture::ForEachImage( ObjectType_t *pObject, bool (ObjectType_t::*pMemberFunc)( CDmeImage * ) )
{
CImageMemberFunctor< ObjectType_t > functor( pObject, pMemberFunc );
ForEachImage( functor );
}
inline void CDmeTexture::ForEachImage( bool (*pFunc)( CDmeImage * ) )
{
CImageFunctor functor( pFunc );
ForEachImage( functor );
}
// Iterates over all images, processes them
template< typename Functor > inline void CDmeTexture::ProcessTexture( CDmeTexture *pSrcTexture, Functor &func )
{
// FIXME: This pattern should go into some templatized type thingy
pSrcTexture->CopyAttributesTo( this, TD_NONE );
// Copying will copy references to src texture frames. Remove them.
RemoveAllFrames();
int nFrameCount = pSrcTexture->FrameCount();
for ( int f = 0; f < nFrameCount; ++f )
{
CDmeTextureFrame *pSrcFrame = pSrcTexture->GetFrame( f );
CDmeTextureFrame *pDstFrame = AddFrame();
int nMipCount = pSrcFrame->MipLevelCount();
for ( int m = 0; m < nMipCount; ++m )
{
CDmeImageArray *pSrcImageArray = pSrcFrame->GetMipLevel( m );
CDmeImageArray *pDstImageArray = pDstFrame->AddMipLevel();
if ( !pSrcImageArray )
continue;
int nImageCount = pSrcImageArray->ImageCount();
for ( int i = 0; i < nImageCount; ++i )
{
CDmeImage *pSrcImage = pSrcImageArray->GetImage( i );
CDmeImage *pDstImage = pDstImageArray->AddImage( );
if ( !pSrcImage )
continue;
func( pDstImage, pSrcImage );
}
}
}
}
template< typename ObjectType_t > inline void CDmeTexture::ProcessTexture( CDmeTexture *pSrcTexture, ObjectType_t *pObject, void (ObjectType_t::*pMemberFunc)( CDmeImage *, CDmeImage * ) )
{
CImageProcessorMemberFunctor< ObjectType_t > functor( pObject, pMemberFunc );
ProcessTexture( pSrcTexture, functor );
}
#endif // DMETEXTURE_H

View File

@@ -0,0 +1,28 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose: See notes below
//
//=============================================================================
#include "materialobjects/materialobjects.h"
#include "datamodel/dmelementfactoryhelper.h"
// YOU MUST INCLUDE THIS FILE INTO ANY PROJECT WHICH USES THE materialobjects.lib FILE
// This hack causes the class factories for the element types to be imported into the compiled code...
// Material types
USING_ELEMENT_FACTORY( DmeAmalgamatedTexture );
USING_ELEMENT_FACTORY( DmeSheetSequence );
USING_ELEMENT_FACTORY( DmeSheetSequenceFrame );
USING_ELEMENT_FACTORY( DmeSheetImage );
USING_ELEMENT_FACTORY( DmeTexture );
USING_ELEMENT_FACTORY( DmeTextureFrame );
USING_ELEMENT_FACTORY( DmeImageArray );
USING_ELEMENT_FACTORY( DmeImage );
USING_ELEMENT_FACTORY( DmePrecompiledTexture );
USING_ELEMENT_FACTORY( DmeTP_ComputeMipmaps );
USING_ELEMENT_FACTORY( DmeTP_ChangeColorChannels );

View File

@@ -0,0 +1,20 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#ifndef MATERIALOBJECTS_H
#define MATERIALOBJECTS_H
#ifdef _WIN32
#pragma once
#endif
#include "materialobjects/dmeamalgtexture.h"
#include "materialobjects/dmesheetsequence.h"
#include "materialobjects/dmeimage.h"
#include "materialobjects/dmetexture.h"
#include "materialobjects/dmeprecompiledtexture.h"
#endif // MATERIALOBJECTS_H