OpenClonk
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

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__

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

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.Rotate

struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Rotate

Definition at line 285 of file StdMeshMaterial.h.

Class Members
float Angle

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.RotateAnim

struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.RotateAnim

Definition at line 286 of file StdMeshMaterial.h.

Class Members
float RevsPerSec

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.Scale

struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Scale

Definition at line 287 of file StdMeshMaterial.h.

Class Members
float X
float Y

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.Scroll

struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Scroll

Definition at line 283 of file StdMeshMaterial.h.

Class Members
float X
float Y

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.ScrollAnim

struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.ScrollAnim

Definition at line 284 of file StdMeshMaterial.h.

Class Members
float XSpeed
float YSpeed

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.Transform

struct StdMeshMaterialTextureUnit::Transformation.__unnamed__.Transform

Definition at line 288 of file StdMeshMaterial.h.

Class Members
float M[16]

◆ StdMeshMaterialTextureUnit::Transformation.__unnamed__.WaveXForm

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

◆ BlendOpExType

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  };

◆ BlendOpSourceType

◆ BlendOpType

◆ FilteringType

◆ TexAddressModeType

Constructor & Destructor Documentation

◆ StdMeshMaterialTextureUnit()

StdMeshMaterialTextureUnit::StdMeshMaterialTextureUnit ( )

Definition at line 996 of file StdMeshMaterial.cpp.

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

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

Member Function Documentation

◆ GetNumTextures()

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:

◆ GetTexture()

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:

◆ HasFrameAnimation()

bool StdMeshMaterialTextureUnit::HasFrameAnimation ( ) const
inline

Definition at line 341 of file StdMeshMaterial.h.

Referenced by StdMeshInstance::ExecuteAnimation().

341 { return Duration > 0; }
Here is the caller graph for this function:

◆ HasTexCoordAnimation()

bool StdMeshMaterialTextureUnit::HasTexCoordAnimation ( ) const
inline

Definition at line 342 of file StdMeshMaterial.h.

Referenced by StdMeshInstance::ExecuteAnimation().

342 { return !Transformations.empty(); }
std::vector< Transformation > Transformations
Here is the caller graph for this function:

◆ HasTexture()

bool StdMeshMaterialTextureUnit::HasTexture ( ) const
inline

Definition at line 338 of file StdMeshMaterial.h.

338 { return !Textures.empty(); }

◆ Load()

void StdMeshMaterialTextureUnit::Load ( StdMeshMaterialParserCtx ctx)

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

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

◆ LoadTexture()

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

Definition at line 1006 of file StdMeshMaterial.cpp.

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

Referenced by Load().

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

◆ AlphaOpEx

BlendOpExType StdMeshMaterialTextureUnit::AlphaOpEx {BOX_Modulate}

Definition at line 357 of file StdMeshMaterial.h.

Referenced by Load().

◆ AlphaOpManualAlpha1

float StdMeshMaterialTextureUnit::AlphaOpManualAlpha1

Definition at line 360 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

◆ AlphaOpManualAlpha2

float StdMeshMaterialTextureUnit::AlphaOpManualAlpha2

Definition at line 361 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

◆ AlphaOpManualFactor

float StdMeshMaterialTextureUnit::AlphaOpManualFactor {0.0f}

Definition at line 359 of file StdMeshMaterial.h.

Referenced by Load().

◆ AlphaOpSources

BlendOpSourceType StdMeshMaterialTextureUnit::AlphaOpSources[2]

Definition at line 358 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

◆ ColorOpEx

BlendOpExType StdMeshMaterialTextureUnit::ColorOpEx {BOX_Modulate}

Definition at line 351 of file StdMeshMaterial.h.

Referenced by Load().

◆ ColorOpManualColor1

float StdMeshMaterialTextureUnit::ColorOpManualColor1[3]

Definition at line 354 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

◆ ColorOpManualColor2

float StdMeshMaterialTextureUnit::ColorOpManualColor2[3]

Definition at line 355 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

◆ ColorOpManualFactor

float StdMeshMaterialTextureUnit::ColorOpManualFactor {0.0f}

Definition at line 353 of file StdMeshMaterial.h.

Referenced by Load().

◆ ColorOpSources

BlendOpSourceType StdMeshMaterialTextureUnit::ColorOpSources[2]

Definition at line 352 of file StdMeshMaterial.h.

Referenced by Load(), and StdMeshMaterialTextureUnit().

◆ Duration

float StdMeshMaterialTextureUnit::Duration {0.0f}

Definition at line 345 of file StdMeshMaterial.h.

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

◆ Filtering

FilteringType StdMeshMaterialTextureUnit::Filtering[3]

Definition at line 349 of file StdMeshMaterial.h.

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

◆ Name

StdCopyStrBuf StdMeshMaterialTextureUnit::Name

Definition at line 344 of file StdMeshMaterial.h.

◆ TexAddressMode

TexAddressModeType StdMeshMaterialTextureUnit::TexAddressMode {AM_Wrap}

Definition at line 347 of file StdMeshMaterial.h.

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

◆ TexBorderColor

float StdMeshMaterialTextureUnit::TexBorderColor[4]

Definition at line 348 of file StdMeshMaterial.h.

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

◆ Transformations

std::vector<Transformation> StdMeshMaterialTextureUnit::Transformations

Definition at line 364 of file StdMeshMaterial.h.

Referenced by Load().


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