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 {0.0f}
 
TexAddressModeType TexAddressMode {AM_Wrap}
 
float TexBorderColor [4]
 
FilteringType Filtering [3]
 
BlendOpExType ColorOpEx {BOX_Modulate}
 
BlendOpSourceType ColorOpSources [2]
 
float ColorOpManualFactor {0.0f}
 
float ColorOpManualColor1 [3]
 
float ColorOpManualColor2 [3]
 
BlendOpExType AlphaOpEx {BOX_Modulate}
 
BlendOpSourceType AlphaOpSources [2]
 
float AlphaOpManualFactor {0.0f}
 
float AlphaOpManualAlpha1
 
float AlphaOpManualAlpha2
 
std::vector< TransformationTransformations
 

Detailed Description

Definition at line 192 of file StdMeshMaterial.h.


Class Documentation

union StdMeshMaterialTextureUnit::Transformation.__unnamed__

Definition at line 281 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 285 of file StdMeshMaterial.h.

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

Definition at line 286 of file StdMeshMaterial.h.

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

Definition at line 287 of file StdMeshMaterial.h.

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

Definition at line 283 of file StdMeshMaterial.h.

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

Definition at line 284 of file StdMeshMaterial.h.

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

Definition at line 288 of file StdMeshMaterial.h.

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

Definition at line 289 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 219 of file StdMeshMaterial.h.

220  {
221  BOX_Source1,
222  BOX_Source2,
223  BOX_Modulate,
226  BOX_Add,
229  BOX_Subtract,
236  };

Constructor & Destructor Documentation

StdMeshMaterialTextureUnit::StdMeshMaterialTextureUnit ( )

Definition at line 995 of file StdMeshMaterial.cpp.

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

996 {
997  TexBorderColor[0] = TexBorderColor[1] = TexBorderColor[2] = 0.0f; TexBorderColor[3] = 1.0f;
998  Filtering[0] = Filtering[1] = F_Linear; Filtering[2] = F_Point;
1003 }
BlendOpSourceType ColorOpSources[2]
BlendOpSourceType AlphaOpSources[2]

Member Function Documentation

size_t StdMeshMaterialTextureUnit::GetNumTextures ( ) const
inline

Definition at line 339 of file StdMeshMaterial.h.

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

339 { return Textures.size(); }

Here is the caller graph for this function:

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

Definition at line 340 of file StdMeshMaterial.h.

Referenced by CStdGL::PrepareMaterial().

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

Here is the caller graph for this function:

bool StdMeshMaterialTextureUnit::HasFrameAnimation ( ) const
inline

Definition at line 341 of file StdMeshMaterial.h.

References Duration.

Referenced by StdMeshInstance::ExecuteAnimation().

341 { return Duration > 0; }

Here is the caller graph for this function:

bool StdMeshMaterialTextureUnit::HasTexCoordAnimation ( ) const
inline

Definition at line 342 of file StdMeshMaterial.h.

References Transformations.

Referenced by StdMeshInstance::ExecuteAnimation().

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

Here is the caller graph for this function:

bool StdMeshMaterialTextureUnit::HasTexture ( ) const
inline

Definition at line 338 of file StdMeshMaterial.h.

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

Definition at line 1017 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.

1018 {
1019  Token token;
1020  StdCopyStrBuf token_name;
1021  while ((token = ctx.AdvanceNonEOF(token_name)) == TOKEN_IDTF)
1022  {
1023  if (token_name == "texture")
1024  {
1025  Textures.clear();
1026  ctx.AdvanceRequired(token_name, TOKEN_IDTF);
1027  LoadTexture(ctx, token_name.getData());
1028  }
1029  else if (token_name == "anim_texture")
1030  {
1031  Textures.clear();
1032 
1033  StdCopyStrBuf base_name;
1034  ctx.AdvanceRequired(base_name, TOKEN_IDTF);
1035 
1036  int num_frames;
1037  if (ctx.AdvanceIntOptional(num_frames))
1038  {
1039  const char* data = base_name.getData();
1040  const char* sep = strrchr(data, '.');
1041  for (int i = 0; i < num_frames; ++i)
1042  {
1043  StdCopyStrBuf buf;
1044  if (sep)
1045  buf.Format("%.*s_%d.%s", (int)(sep - data), data, i, sep+1);
1046  else
1047  buf.Format("%s_%d", data, i);
1048 
1049  LoadTexture(ctx, buf.getData());
1050  }
1051 
1052  Duration = ctx.AdvanceFloat();
1053  }
1054  else
1055  {
1056  LoadTexture(ctx, base_name.getData());
1057  while (!ctx.AdvanceFloatOptional(Duration))
1058  {
1059  ctx.AdvanceRequired(token_name, TOKEN_IDTF);
1060  LoadTexture(ctx, token_name.getData());
1061  }
1062  }
1063  }
1064  else if (token_name == "tex_address_mode")
1065  {
1066  TexAddressMode = ctx.AdvanceEnum(TexAddressModeEnumerators);
1067  }
1068  else if (token_name == "tex_border_colour")
1069  {
1070  ctx.AdvanceColor(true, TexBorderColor);
1071  }
1072  else if (token_name == "filtering")
1073  {
1074  ctx.AdvanceEnums<3, StdMeshMaterialTextureUnit::FilteringType>(FilteringEnumerators, FilteringShortcuts, Filtering);
1075  if (Filtering[0] == F_None || Filtering[1] == F_None)
1076  ctx.Error(StdCopyStrBuf("'none' is only valid for the mip filter"));
1077  if (Filtering[2] == F_Anisotropic)
1078  ctx.Error(StdCopyStrBuf("'anisotropic' is not a valid mip filter"));
1079  }
1080  else if (token_name == "colour_op")
1081  {
1082  BlendOpType ColorOp = ctx.AdvanceEnum(BlendOpEnumerators);
1083  switch (ColorOp)
1084  {
1085  case BO_Replace:
1087  break;
1088  case BO_Add:
1089  ColorOpEx = BOX_Add;
1090  break;
1091  case BO_Modulate:
1093  break;
1094  case BO_AlphaBlend:
1096  break;
1097  }
1098 
1101  }
1102  else if (token_name == "colour_op_ex")
1103  {
1104  ColorOpEx = ctx.AdvanceEnum(BlendOpExEnumerators);
1105  ColorOpSources[0] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1106  ColorOpSources[1] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1110  }
1111  else if (token_name == "alpha_op_ex")
1112  {
1113  AlphaOpEx = ctx.AdvanceEnum(BlendOpExEnumerators);
1114  AlphaOpSources[0] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1115  AlphaOpSources[1] = ctx.AdvanceEnum(BlendOpSourceEnumerators);
1119  }
1120  else if (token_name == "scroll")
1121  {
1122  Transformation trans;
1123  trans.TransformType = Transformation::T_SCROLL;
1124  trans.Scroll.X = ctx.AdvanceFloat();
1125  trans.Scroll.Y = ctx.AdvanceFloat();
1126  Transformations.push_back(trans);
1127  }
1128  else if (token_name == "scroll_anim")
1129  {
1130  Transformation trans;
1131  trans.TransformType = Transformation::T_SCROLL_ANIM;
1132  trans.ScrollAnim.XSpeed = ctx.AdvanceFloat();
1133  trans.ScrollAnim.YSpeed = ctx.AdvanceFloat();
1134  Transformations.push_back(trans);
1135  }
1136  else if (token_name == "rotate")
1137  {
1138  Transformation trans;
1139  trans.TransformType = Transformation::T_ROTATE;
1140  trans.Rotate.Angle = ctx.AdvanceFloat();
1141  Transformations.push_back(trans);
1142  }
1143  else if (token_name == "rotate_anim")
1144  {
1145  Transformation trans;
1146  trans.TransformType = Transformation::T_ROTATE_ANIM;
1147  trans.RotateAnim.RevsPerSec = ctx.AdvanceFloat();
1148  Transformations.push_back(trans);
1149  }
1150  else if (token_name == "scale")
1151  {
1152  Transformation trans;
1153  trans.TransformType = Transformation::T_SCALE;
1154  trans.Scale.X = ctx.AdvanceFloat();
1155  trans.Scale.Y = ctx.AdvanceFloat();
1156  Transformations.push_back(trans);
1157  }
1158  else if (token_name == "transform")
1159  {
1160  Transformation trans;
1161  trans.TransformType = Transformation::T_TRANSFORM;
1162  for (float & i : trans.Transform.M)
1163  i = ctx.AdvanceFloat();
1164  Transformations.push_back(trans);
1165  }
1166  else if (token_name == "wave_xform")
1167  {
1168  Transformation trans;
1169  trans.TransformType = Transformation::T_WAVE_XFORM;
1170  trans.WaveXForm.XForm = ctx.AdvanceEnum(XFormTypeEnumerators);
1171  trans.WaveXForm.Wave = ctx.AdvanceEnum(WaveTypeEnumerators);
1172  trans.WaveXForm.Base = ctx.AdvanceFloat();
1173  trans.WaveXForm.Frequency = ctx.AdvanceFloat();
1174  trans.WaveXForm.Phase = ctx.AdvanceFloat();
1175  trans.WaveXForm.Amplitude = ctx.AdvanceFloat();
1176  Transformations.push_back(trans);
1177  }
1178  else
1179  ctx.ErrorUnexpectedIdentifier(token_name);
1180  }
1181 
1182  if (token != TOKEN_BRACE_CLOSE)
1183  ctx.Error(StdCopyStrBuf("'") + token_name.getData() + "' unexpected");
1184 }
TexAddressModeType TexAddressMode
const char * getData() const
Definition: StdBuf.h:442
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:174
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 1005 of file StdMeshMaterial.cpp.

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

Referenced by Load().

1006 {
1007  std::unique_ptr<C4Surface> surface(ctx.Loader.LoadTexture(texname)); // be exception-safe
1008  if (!surface.get())
1009  ctx.Error(StdCopyStrBuf("Could not load texture '") + texname + "'");
1010 
1011  if (surface->Wdt != surface->Hgt)
1012  ctx.Error(StdCopyStrBuf("Texture '") + texname + "' is not quadratic");
1013 
1014  Textures.emplace_back(surface.release());
1015 }
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 {BOX_Modulate}

Definition at line 357 of file StdMeshMaterial.h.

Referenced by Load().

float StdMeshMaterialTextureUnit::AlphaOpManualAlpha1

Definition at line 360 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::AlphaOpManualAlpha2

Definition at line 361 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::AlphaOpManualFactor {0.0f}

Definition at line 359 of file StdMeshMaterial.h.

Referenced by Load().

BlendOpSourceType StdMeshMaterialTextureUnit::AlphaOpSources[2]

Definition at line 358 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

BlendOpExType StdMeshMaterialTextureUnit::ColorOpEx {BOX_Modulate}

Definition at line 351 of file StdMeshMaterial.h.

Referenced by Load().

float StdMeshMaterialTextureUnit::ColorOpManualColor1[3]

Definition at line 354 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::ColorOpManualColor2[3]

Definition at line 355 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::ColorOpManualFactor {0.0f}

Definition at line 353 of file StdMeshMaterial.h.

Referenced by Load().

BlendOpSourceType StdMeshMaterialTextureUnit::ColorOpSources[2]

Definition at line 352 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

float StdMeshMaterialTextureUnit::Duration {0.0f}

Definition at line 345 of file StdMeshMaterial.h.

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

FilteringType StdMeshMaterialTextureUnit::Filtering[3]

Definition at line 349 of file StdMeshMaterial.h.

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

StdCopyStrBuf StdMeshMaterialTextureUnit::Name

Definition at line 344 of file StdMeshMaterial.h.

TexAddressModeType StdMeshMaterialTextureUnit::TexAddressMode {AM_Wrap}

Definition at line 347 of file StdMeshMaterial.h.

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

float StdMeshMaterialTextureUnit::TexBorderColor[4]

Definition at line 348 of file StdMeshMaterial.h.

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

std::vector<Transformation> StdMeshMaterialTextureUnit::Transformations

Definition at line 364 of file StdMeshMaterial.h.

Referenced by HasTexCoordAnimation(), and Load().


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