OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshMaterialTextureUnit Class Reference

#include <StdMeshMaterial.h>

Collaboration diagram for StdMeshMaterialTextureUnit:
[legend]

Classes

class  Tex
 
class  TexPtr
 
struct  Transformation
 
union  Transformation.__unnamed__
 
struct  Transformation.__unnamed__.Rotate
 
struct  Transformation.__unnamed__.RotateAnim
 
struct  Transformation.__unnamed__.Scale
 
struct  Transformation.__unnamed__.Scroll
 
struct  Transformation.__unnamed__.ScrollAnim
 
struct  Transformation.__unnamed__.Transform
 
struct  Transformation.__unnamed__.WaveXForm
 

Public Types

enum  TexAddressModeType { AM_Wrap, AM_Clamp, AM_Mirror, AM_Border }
 
enum  FilteringType { F_None, F_Point, F_Linear, F_Anisotropic }
 
enum  BlendOpType { BO_Replace, BO_Add, BO_Modulate, BO_AlphaBlend }
 
enum  BlendOpExType {
  BOX_Source1, BOX_Source2, BOX_Modulate, BOX_ModulateX2,
  BOX_ModulateX4, BOX_Add, BOX_AddSigned, BOX_AddSmooth,
  BOX_Subtract, BOX_BlendDiffuseAlpha, BOX_BlendTextureAlpha, BOX_BlendCurrentAlpha,
  BOX_BlendManual, BOX_Dotproduct, BOX_BlendDiffuseColor
}
 
enum  BlendOpSourceType {
  BOS_Current, BOS_Texture, BOS_Diffuse, BOS_Specular,
  BOS_PlayerColor, BOS_Manual
}
 

Public Member Functions

 StdMeshMaterialTextureUnit ()
 
void LoadTexture (StdMeshMaterialParserCtx &ctx, const char *texname)
 
void Load (StdMeshMaterialParserCtx &ctx)
 
bool HasTexture () const
 
size_t GetNumTextures () const
 
const C4TexRefGetTexture (unsigned int i) const
 
bool HasFrameAnimation () const
 
bool HasTexCoordAnimation () const
 

Public Attributes

StdCopyStrBuf Name
 
float Duration
 
TexAddressModeType TexAddressMode
 
float TexBorderColor [4]
 
FilteringType Filtering [3]
 
BlendOpExType ColorOpEx
 
BlendOpSourceType ColorOpSources [2]
 
float ColorOpManualFactor
 
float ColorOpManualColor1 [3]
 
float ColorOpManualColor2 [3]
 
BlendOpExType AlphaOpEx
 
BlendOpSourceType AlphaOpSources [2]
 
float AlphaOpManualFactor
 
float AlphaOpManualAlpha1
 
float AlphaOpManualAlpha2
 
std::vector< TransformationTransformations
 

Detailed Description

Definition at line 195 of file StdMeshMaterial.h.


Class Documentation

union StdMeshMaterialTextureUnit::Transformation.__unnamed__

Definition at line 284 of file StdMeshMaterial.h.

Class Members
__unnamed__ Rotate
__unnamed__ RotateAnim
__unnamed__ Scale
__unnamed__ Scroll
__unnamed__ ScrollAnim
__unnamed__ Transform
__unnamed__ WaveXForm
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Rotate

Definition at line 288 of file StdMeshMaterial.h.

Class Members
float Angle
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.RotateAnim

Definition at line 289 of file StdMeshMaterial.h.

Class Members
float RevsPerSec
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Scale

Definition at line 290 of file StdMeshMaterial.h.

Class Members
float X
float Y
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Scroll

Definition at line 286 of file StdMeshMaterial.h.

Class Members
float X
float Y
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.ScrollAnim

Definition at line 287 of file StdMeshMaterial.h.

Class Members
float XSpeed
float YSpeed
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Transform

Definition at line 291 of file StdMeshMaterial.h.

Class Members
float M[16]
struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.WaveXForm

Definition at line 292 of file StdMeshMaterial.h.

Class Members
float Amplitude
float Base
float Frequency
float Phase
WaveType Wave
XFormType XForm

Member Enumeration Documentation

Enumerator
BOX_Source1 
BOX_Source2 
BOX_Modulate 
BOX_ModulateX2 
BOX_ModulateX4 
BOX_Add 
BOX_AddSigned 
BOX_AddSmooth 
BOX_Subtract 
BOX_BlendDiffuseAlpha 
BOX_BlendTextureAlpha 
BOX_BlendCurrentAlpha 
BOX_BlendManual 
BOX_Dotproduct 
BOX_BlendDiffuseColor 

Definition at line 222 of file StdMeshMaterial.h.

223  {
224  BOX_Source1,
225  BOX_Source2,
226  BOX_Modulate,
229  BOX_Add,
232  BOX_Subtract,
239  };

Constructor & Destructor Documentation

StdMeshMaterialTextureUnit::StdMeshMaterialTextureUnit ( )

Definition at line 1013 of file StdMeshMaterial.cpp.

References AlphaOpManualAlpha1, AlphaOpManualAlpha2, AlphaOpSources, BOS_Current, BOS_Texture, ColorOpManualColor1, ColorOpManualColor2, ColorOpSources, F_Linear, F_Point, Filtering, and TexBorderColor.

1013  :
1016 {
1017  TexBorderColor[0] = TexBorderColor[1] = TexBorderColor[2] = 0.0f; TexBorderColor[3] = 1.0f;
1018  Filtering[0] = Filtering[1] = F_Linear; Filtering[2] = F_Point;
1023 }
TexAddressModeType TexAddressMode
BlendOpSourceType ColorOpSources[2]
BlendOpSourceType AlphaOpSources[2]

Member Function Documentation

size_t StdMeshMaterialTextureUnit::GetNumTextures ( ) const
inline

Definition at line 342 of file StdMeshMaterial.h.

Referenced by StdMeshInstance::ExecuteAnimation(), and CStdGL::PrepareMaterial().

342 { return Textures.size(); }

Here is the caller graph for this function:

const C4TexRef& StdMeshMaterialTextureUnit::GetTexture ( unsigned int  i) const
inline

Definition at line 343 of file StdMeshMaterial.h.

Referenced by CStdGL::PrepareMaterial().

343 { return Textures[i].pTex->Texture; }

Here is the caller graph for this function:

bool StdMeshMaterialTextureUnit::HasFrameAnimation ( ) const
inline

Definition at line 344 of file StdMeshMaterial.h.

References Duration.

Referenced by StdMeshInstance::ExecuteAnimation().

344 { return Duration > 0; }

Here is the caller graph for this function:

bool StdMeshMaterialTextureUnit::HasTexCoordAnimation ( ) const
inline

Definition at line 345 of file StdMeshMaterial.h.

References Transformations.

Referenced by StdMeshInstance::ExecuteAnimation().

345 { return !Transformations.empty(); }
std::vector< Transformation > Transformations

Here is the caller graph for this function:

bool StdMeshMaterialTextureUnit::HasTexture ( ) const
inline

Definition at line 341 of file StdMeshMaterial.h.

341 { return !Textures.empty(); }
void StdMeshMaterialTextureUnit::Load ( StdMeshMaterialParserCtx ctx)

Definition at line 1037 of file StdMeshMaterial.cpp.

References StdMeshMaterialParserCtx::AdvanceColor(), StdMeshMaterialParserCtx::AdvanceEnum(), StdMeshMaterialParserCtx::AdvanceEnums(), StdMeshMaterialParserCtx::AdvanceFloat(), StdMeshMaterialParserCtx::AdvanceFloatOptional(), StdMeshMaterialParserCtx::AdvanceIntOptional(), StdMeshMaterialParserCtx::AdvanceNonEOF(), StdMeshMaterialParserCtx::AdvanceRequired(), AlphaOpEx, AlphaOpManualAlpha1, AlphaOpManualAlpha2, AlphaOpManualFactor, AlphaOpSources, BO_Add, BO_AlphaBlend, BO_Modulate, BO_Replace, BOS_Current, BOS_Manual, BOS_Texture, BOX_Add, BOX_BlendManual, BOX_BlendTextureAlpha, BOX_Modulate, BOX_Source1, ColorOpEx, ColorOpManualColor1, ColorOpManualColor2, ColorOpManualFactor, ColorOpSources, Duration, StdMeshMaterialParserCtx::Error(), StdMeshMaterialParserCtx::ErrorUnexpectedIdentifier(), F_Anisotropic, F_None, Filtering, StdStrBuf::Format(), StdStrBuf::getData(), LoadTexture(), StdMeshMaterialTextureUnit::Transformation::T_ROTATE, StdMeshMaterialTextureUnit::Transformation::T_ROTATE_ANIM, StdMeshMaterialTextureUnit::Transformation::T_SCALE, StdMeshMaterialTextureUnit::Transformation::T_SCROLL, StdMeshMaterialTextureUnit::Transformation::T_SCROLL_ANIM, StdMeshMaterialTextureUnit::Transformation::T_TRANSFORM, StdMeshMaterialTextureUnit::Transformation::T_WAVE_XFORM, TexAddressMode, TexBorderColor, TOKEN_BRACE_CLOSE, TOKEN_IDTF, Transformations, and StdMeshMaterialTextureUnit::Transformation::TransformType.

1038 {
1039  Token token;
1040  StdCopyStrBuf token_name;
1041  while ((token = ctx.AdvanceNonEOF(token_name)) == TOKEN_IDTF)
1042  {
1043  if (token_name == "texture")
1044  {
1045  Textures.clear();
1046  ctx.AdvanceRequired(token_name, TOKEN_IDTF);
1047  LoadTexture(ctx, token_name.getData());
1048  }
1049  else if (token_name == "anim_texture")
1050  {
1051  Textures.clear();
1052 
1053  StdCopyStrBuf base_name;
1054  ctx.AdvanceRequired(base_name, TOKEN_IDTF);
1055 
1056  int num_frames;
1057  if (ctx.AdvanceIntOptional(num_frames))
1058  {
1059  const char* data = base_name.getData();
1060  const char* sep = strrchr(data, '.');
1061  for (int i = 0; i < num_frames; ++i)
1062  {
1063  StdCopyStrBuf buf;
1064  if (sep)
1065  buf.Format("%.*s_%d.%s", (int)(sep - data), data, i, sep+1);
1066  else
1067  buf.Format("%s_%d", data, i);
1068 
1069  LoadTexture(ctx, buf.getData());
1070  }
1071 
1072  Duration = ctx.AdvanceFloat();
1073  }
1074  else
1075  {
1076  LoadTexture(ctx, base_name.getData());
1077  while (!ctx.AdvanceFloatOptional(Duration))
1078  {
1079  ctx.AdvanceRequired(token_name, TOKEN_IDTF);
1080  LoadTexture(ctx, token_name.getData());
1081  }
1082  }
1083  }
1084  else if (token_name == "tex_address_mode")
1085  {
1086  TexAddressMode = ctx.AdvanceEnum(TexAddressModeEnumerators);
1087  }
1088  else if (token_name == "tex_border_colour")
1089  {
1090  ctx.AdvanceColor(true, TexBorderColor);
1091  }
1092  else if (token_name == "filtering")
1093  {
1094  ctx.AdvanceEnums<3, StdMeshMaterialTextureUnit::FilteringType>(FilteringEnumerators, FilteringShortcuts, Filtering);
1095  if (Filtering[0] == F_None || Filtering[1] == F_None)
1096  ctx.Error(StdCopyStrBuf("'none' is only valid for the mip filter"));
1097  if (Filtering[2] == F_Anisotropic)
1098  ctx.Error(StdCopyStrBuf("'anisotropic' is not a valid mip filter"));
1099  }
1100  else if (token_name == "colour_op")
1101  {
1102  BlendOpType ColorOp = ctx.AdvanceEnum(BlendOpEnumerators);
1103  switch (ColorOp)
1104  {
1105  case BO_Replace:
1107  break;
1108  case BO_Add:
1109  ColorOpEx = BOX_Add;
1110  break;
1111  case BO_Modulate:
1113  break;
1114  case BO_AlphaBlend:
1116  break;
1117  }
1118 
1121  }
1122  else if (token_name == "colour_op_ex")
1123  {
1124  ColorOpEx = ctx.AdvanceEnum(BlendOpExEnumerators);
1125  ColorOpSources[0] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1126  ColorOpSources[1] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1130  }
1131  else if (token_name == "alpha_op_ex")
1132  {
1133  AlphaOpEx = ctx.AdvanceEnum(BlendOpExEnumerators);
1134  AlphaOpSources[0] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1135  AlphaOpSources[1] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1139  }
1140  else if (token_name == "scroll")
1141  {
1142  Transformation trans;
1143  trans.TransformType = Transformation::T_SCROLL;
1144  trans.Scroll.X = ctx.AdvanceFloat();
1145  trans.Scroll.Y = ctx.AdvanceFloat();
1146  Transformations.push_back(trans);
1147  }
1148  else if (token_name == "scroll_anim")
1149  {
1150  Transformation trans;
1151  trans.TransformType = Transformation::T_SCROLL_ANIM;
1152  trans.ScrollAnim.XSpeed = ctx.AdvanceFloat();
1153  trans.ScrollAnim.YSpeed = ctx.AdvanceFloat();
1154  Transformations.push_back(trans);
1155  }
1156  else if (token_name == "rotate")
1157  {
1158  Transformation trans;
1159  trans.TransformType = Transformation::T_ROTATE;
1160  trans.Rotate.Angle = ctx.AdvanceFloat();
1161  Transformations.push_back(trans);
1162  }
1163  else if (token_name == "rotate_anim")
1164  {
1165  Transformation trans;
1166  trans.TransformType = Transformation::T_ROTATE_ANIM;
1167  trans.RotateAnim.RevsPerSec = ctx.AdvanceFloat();
1168  Transformations.push_back(trans);
1169  }
1170  else if (token_name == "scale")
1171  {
1172  Transformation trans;
1173  trans.TransformType = Transformation::T_SCALE;
1174  trans.Scale.X = ctx.AdvanceFloat();
1175  trans.Scale.Y = ctx.AdvanceFloat();
1176  Transformations.push_back(trans);
1177  }
1178  else if (token_name == "transform")
1179  {
1180  Transformation trans;
1181  trans.TransformType = Transformation::T_TRANSFORM;
1182  for (int i = 0; i < 16; ++i)
1183  trans.Transform.M[i] = ctx.AdvanceFloat();
1184  Transformations.push_back(trans);
1185  }
1186  else if (token_name == "wave_xform")
1187  {
1188  Transformation trans;
1189  trans.TransformType = Transformation::T_WAVE_XFORM;
1190  trans.WaveXForm.XForm = ctx.AdvanceEnum(XFormTypeEnumerators);
1191  trans.WaveXForm.Wave = ctx.AdvanceEnum(WaveTypeEnumerators);
1192  trans.WaveXForm.Base = ctx.AdvanceFloat();
1193  trans.WaveXForm.Frequency = ctx.AdvanceFloat();
1194  trans.WaveXForm.Phase = ctx.AdvanceFloat();
1195  trans.WaveXForm.Amplitude = ctx.AdvanceFloat();
1196  Transformations.push_back(trans);
1197  }
1198  else
1199  ctx.ErrorUnexpectedIdentifier(token_name);
1200  }
1201 
1202  if (token != TOKEN_BRACE_CLOSE)
1203  ctx.Error(StdCopyStrBuf("'") + token_name.getData() + "' unexpected");
1204 }
TexAddressModeType TexAddressMode
const char * getData() const
Definition: StdBuf.h:450
void LoadTexture(StdMeshMaterialParserCtx &ctx, const char *texname)
Token AdvanceRequired(StdStrBuf &name, Token expect)
EnumType AdvanceEnum(const Enumerator< EnumType > *enumerators)
void AdvanceColor(bool with_alpha, float Color[4])
void ErrorUnexpectedIdentifier(const StdStrBuf &identifier)
BlendOpSourceType ColorOpSources[2]
void Error(const StdStrBuf &message)
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
Token AdvanceNonEOF(StdStrBuf &name)
bool AdvanceFloatOptional(float &value)
std::vector< Transformation > Transformations
void AdvanceEnums(const Enumerator< EnumType > *enumerators, EnumType enums[Num])
bool AdvanceIntOptional(int &value)
BlendOpSourceType AlphaOpSources[2]

Here is the call graph for this function:

void StdMeshMaterialTextureUnit::LoadTexture ( StdMeshMaterialParserCtx ctx,
const char *  texname 
)

Definition at line 1025 of file StdMeshMaterial.cpp.

References StdMeshMaterialParserCtx::Error(), StdMeshMaterialParserCtx::Loader, and StdMeshMaterialLoader::LoadTexture().

Referenced by Load().

1026 {
1027  std::unique_ptr<C4Surface> surface(ctx.Loader.LoadTexture(texname)); // be exception-safe
1028  if (!surface.get())
1029  ctx.Error(StdCopyStrBuf("Could not load texture '") + texname + "'");
1030 
1031  if (surface->Wdt != surface->Hgt)
1032  ctx.Error(StdCopyStrBuf("Texture '") + texname + "' is not quadratic");
1033 
1034  Textures.push_back(TexPtr(surface.release()));
1035 }
void Error(const StdStrBuf &message)
virtual C4Surface * LoadTexture(const char *filename)=0
StdMeshMaterialLoader & Loader

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

BlendOpExType StdMeshMaterialTextureUnit::AlphaOpEx

Definition at line 360 of file StdMeshMaterial.h.

Referenced by Load().

float StdMeshMaterialTextureUnit::AlphaOpManualAlpha1

Definition at line 363 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::AlphaOpManualAlpha2

Definition at line 364 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::AlphaOpManualFactor

Definition at line 362 of file StdMeshMaterial.h.

Referenced by Load().

BlendOpSourceType StdMeshMaterialTextureUnit::AlphaOpSources[2]

Definition at line 361 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

BlendOpExType StdMeshMaterialTextureUnit::ColorOpEx

Definition at line 354 of file StdMeshMaterial.h.

Referenced by Load().

float StdMeshMaterialTextureUnit::ColorOpManualColor1[3]

Definition at line 357 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::ColorOpManualColor2[3]

Definition at line 358 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::ColorOpManualFactor

Definition at line 356 of file StdMeshMaterial.h.

Referenced by Load().

BlendOpSourceType StdMeshMaterialTextureUnit::ColorOpSources[2]

Definition at line 355 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::Duration

Definition at line 348 of file StdMeshMaterial.h.

Referenced by StdMeshInstance::ExecuteAnimation(), HasFrameAnimation(), and Load().

FilteringType StdMeshMaterialTextureUnit::Filtering[3]

Definition at line 352 of file StdMeshMaterial.h.

Referenced by Load(), CStdGL::PrepareMaterial(), and StdMeshMaterialTextureUnit().

StdCopyStrBuf StdMeshMaterialTextureUnit::Name

Definition at line 347 of file StdMeshMaterial.h.

TexAddressModeType StdMeshMaterialTextureUnit::TexAddressMode

Definition at line 350 of file StdMeshMaterial.h.

Referenced by Load(), and CStdGL::PrepareMaterial().

float StdMeshMaterialTextureUnit::TexBorderColor[4]

Definition at line 351 of file StdMeshMaterial.h.

Referenced by Load(), CStdGL::PrepareMaterial(), and StdMeshMaterialTextureUnit().

std::vector<Transformation> StdMeshMaterialTextureUnit::Transformations

Definition at line 367 of file StdMeshMaterial.h.

Referenced by HasTexCoordAnimation(), and Load().


The documentation for this class was generated from the following files: