5#ifndef DCPP_I_Q3_LEVEL_SHADER_HPP_INCLUDED 
    6#define DCPP_I_Q3_LEVEL_SHADER_HPP_INCLUDED 
    8#include <duckcpp/core/engine/irrArray.hpp> 
    9#include <duckcpp/core/engine/fast_atof.hpp> 
   10#include <duckcpp/core/engine/IFileSystem.hpp> 
   11#include <duckcpp/core/engine/IVideoDriver.hpp> 
   12#include <duckcpp/core/engine/coreutil.hpp> 
   15namespace dcpp::scene::kqe
 
   23    E_Q3_MESH_GEOMETRY = 0,
 
   39        defaultModulate ( dcpp::video::EMFN_MODULATE_4X ),
 
   41        patchTesselation ( 8 ),
 
   43        startTime ( 0 ), endTime ( 0 ),
 
   44        mergeShaderBuffer ( 1 ),
 
   45        cleanUnResolvedMeshes ( 1 ),
 
   56        std::copy_n(
"scripts\x0", 8, scriptDir);
 
 
   84    const char * in = 
string.data() + pos;
 
   88        if (
string.size() < pos)
 
   91        if (
string.size() < pos+len)
 
   93        if ( in [len] != 0 && in [len] != 
' ' )
 
   95        if ( strncmp ( in, list[i], len ) )
 
  106    const char * in = 
string.data() + pos;
 
  118    v.
X = getAsFloat ( 
string, pos );
 
  119    v.
Z = getAsFloat ( 
string, pos );
 
  120    v.
Y = getAsFloat ( 
string, pos );
 
  137        endPos = 
string.findNext ( 
' ', startPos );
 
  141            endPos = 
string.size();
 
  144        list.push_back ( 
string.subString ( startPos, endPos - startPos ) );
 
  145        startPos = endPos + 1;
 
  176    if ( cull.
size() == 0 )
 
  180    static const dcpp::char_kt * funclist[] = { 
"none", 
"disable", 
"twosided" };
 
  183    switch ( isEqual ( cull, pos, funclist, 3 ) )
 
  200    if ( 
string.size() == 0 )
 
  203    static const dcpp::char_kt * funclist[] = { 
"lequal",
"equal" };
 
  206    switch ( isEqual ( 
string, pos, funclist, 2 ) )
 
  229inline static void getBlendFunc ( 
const dcpp::nub::string &
string, SBlendFunc &blendfunc )
 
  231    if ( 
string.size() == 0 )
 
  240        "gl_one_minus_dst_color",
 
  242        "gl_one_minus_src_color",
 
  244        "gl_one_minus_src_alpha",
 
  246        "gl_one_minus_dst_alpha",
 
  275                    blendfunc.isTransparent = 1;
 
  286                    blendfunc.isTransparent = 0;
 
  293                    blendfunc.isTransparent = 1;
 
  304                    blendfunc.param0 = 1.f/255.f;
 
  305                    blendfunc.isTransparent = 1;
 
  313            blendfunc.isTransparent = 1;
 
  320            blendfunc.isTransparent = 1;
 
  326            blendfunc.param0 = 1.f/255.f;
 
  327            blendfunc.isTransparent = 1;
 
  333            blendfunc.param0 = 0.5f;
 
  334            blendfunc.isTransparent = 1;
 
  340            blendfunc.param0 = 1.f / 255.f;
 
  341            blendfunc.isTransparent = 1;
 
  356        blendfunc.isTransparent = 1;
 
  367        RandomSeed = (RandomSeed * 3631 + 1);
 
 
  374enum eQ3ModifierFunction
 
  384    SCROLL          = FUNCTION2 + 1,
 
  385    SCALE           = FUNCTION2 + 2,
 
  386    ROTATE          = FUNCTION2 + 3,
 
  387    STRETCH         = FUNCTION2 + 4,
 
  388    TURBULENCE      = FUNCTION2 + 5,
 
  389    WAVE            = FUNCTION2 + 6,
 
  391    IDENTITY        = FUNCTION2 + 7,
 
  392    VERTEX          = FUNCTION2 + 8,
 
  393    TEXTURE         = FUNCTION2 + 9,
 
  394    LIGHTMAP        = FUNCTION2 + 10,
 
  395    ENVIRONMENT     = FUNCTION2 + 11,
 
  396    DOLLAR_LIGHTMAP     = FUNCTION2 + 12,
 
  397    BULGE           = FUNCTION2 + 13,
 
  398    AUTOSPRITE      = FUNCTION2 + 14,
 
  399    AUTOSPRITE2     = FUNCTION2 + 15,
 
  400    TRANSFORM       = FUNCTION2 + 16,
 
  401    EXACTVERTEX     = FUNCTION2 + 17,
 
  402    CONSTANT        = FUNCTION2 + 18,
 
  403    LIGHTINGSPECULAR    = FUNCTION2 + 19,
 
  404    MOVE            = FUNCTION2 + 20,
 
  405    NORMAL          = FUNCTION2 + 21,
 
  406    IDENTITYLIGHTING    = FUNCTION2 + 22,
 
  408    WAVE_MODIFIER_FUNCTION  = 0x30,
 
  409    SINUS           = WAVE_MODIFIER_FUNCTION + 1,
 
  410    COSINUS         = WAVE_MODIFIER_FUNCTION + 2,
 
  411    SQUARE          = WAVE_MODIFIER_FUNCTION + 3,
 
  412    TRIANGLE        = WAVE_MODIFIER_FUNCTION + 4,
 
  413    SAWTOOTH        = WAVE_MODIFIER_FUNCTION + 5,
 
  414    SAWTOOTH_INVERSE    = WAVE_MODIFIER_FUNCTION + 6,
 
  415    NOISE           = WAVE_MODIFIER_FUNCTION + 7,
 
  424        masterfunc0 ( UNKNOWN ), masterfunc1( UNKNOWN ), func ( SINUS ),
 
  425        tcgen( TEXTURE ), rgbgen ( IDENTITY ), alphagen ( UNKNOWN ),
 
  426        base ( 0 ), amp ( 1 ), phase ( 0 ), frequency ( 1 ),
 
  428        x ( 0 ), y ( 0 ), z( 0 ), count( 0 )
 
  433    eQ3ModifierFunction masterfunc0;
 
  435    eQ3ModifierFunction masterfunc1;
 
  437    eQ3ModifierFunction func;
 
  439    eQ3ModifierFunction tcgen;
 
  440    eQ3ModifierFunction rgbgen;
 
  441    eQ3ModifierFunction alphagen;
 
  492                y = x < 0.5f ? 1.f : -1.f;
 
  495                y = x < 0.5f ? ( 4.f * x ) - 1.f : ( -4.f * x ) + 3.f;
 
  500            case SAWTOOTH_INVERSE:
 
  510        return base + ( y * amp );
 
 
  519            sinf ( lat ) * sinf ( lng ),
 
  526    if ( 
string.size() == 0 )
 
  531        "sin",
"cos",
"square",
 
  532        "triangle", 
"sawtooth",
"inversesawtooth", 
"noise" 
  535    fill.func = (eQ3ModifierFunction) isEqual ( 
string,pos, funclist,7 );
 
  536    fill.func = fill.func == UNKNOWN ? SINUS : (eQ3ModifierFunction) ((
dcpp::uint32_kt) fill.func + WAVE_MODIFIER_FUNCTION + 1);
 
  538    fill.base = getAsFloat ( 
string, pos );
 
  539    fill.amp = getAsFloat ( 
string, pos );
 
  540    fill.phase = getAsFloat ( 
string, pos );
 
  541    fill.frequency = getAsFloat ( 
string, pos );
 
  569    bool operator == ( 
const SVariable &other )
 const 
  571        return 0 == strcmp ( name.
data(), other.name.
data() );
 
  574    bool operator < ( 
const SVariable &other )
 const 
  576        return 0 > strcmp ( name.
data(), other.name.
data() );
 
 
  584    SVarGroup () { Variable.setAllocStrategy ( dcpp::nub::ALLOC_STRATEGY_SAFE ); }
 
  594            if ( 0 == strcmp ( Variable[i].name.data(), name ) &&
 
  595                (  0 == content || strstr ( Variable[i].content.data(), content ) )
 
  611            return irrEmptyUstring;
 
  613        return Variable [ index ].content;
 
  622            Variable.push_back ( 
SVariable ( name, content ) );
 
  626            Variable [ index ].content = content;
 
 
  640        VariableGroup.setAllocStrategy ( dcpp::nub::ALLOC_STRATEGY_SAFE );
 
 
  655        : ID ( 0 ), VarGroup ( 0 )  {}
 
  658    bool operator == (
const IShader &other )
 const 
  660        return 0 == strcmp ( name.
data(), other.name.
data() );
 
  664    bool operator < (
const IShader &other )
 const 
  666        return strcmp ( name.
data(), other.name.
data() ) < 0;
 
  674        return VarGroup->VariableGroup.size ();
 
  679        if ( 0 == VarGroup || stage >= VarGroup->VariableGroup.size () )
 
  682        return &VarGroup->VariableGroup [ stage ];
 
 
  723        buf += group->Variable[g].name;
 
  725        buf += group->Variable[g].content;
 
  752        const SVarGroup * group = &shader->VarGroup->VariableGroup[ i ];
 
  772inline void getTextures(tTexArray &textures,
 
  777    static const char * 
const extension[] =
 
  788    tStringList stringList;
 
  789    getAsStringList(stringList, -1, name, startPos);
 
  801            if ( loadFile == 
"$whiteimage" )
 
  803                texture = driver->
getTexture( 
"$whiteimage" );
 
  807                    dcpp::uint32_kt image[4] = { 0xFFFFFFFF, 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF };
 
  809                    texture = driver->
addTexture( 
"$whiteimage", w );
 
  815            if ( loadFile == 
"$redimage" )
 
  821                    dcpp::uint32_kt image[4] = { 0xFFFF0000, 0xFFFF0000,0xFFFF0000,0xFFFF0000 };
 
  823                    texture = driver->
addTexture( 
"$redimage", w );
 
  828            if ( loadFile == 
"$blueimage" )
 
  834                    dcpp::uint32_kt image[4] = { 0xFF0000FF, 0xFF0000FF,0xFF0000FF,0xFF0000FF };
 
  836                    texture = driver->
addTexture( 
"$blueimage", w );
 
  841            if ( loadFile == 
"$checkerimage" )
 
  843                texture = driver->
getTexture( 
"$checkerimage" );
 
  847                    dcpp::uint32_kt image[4] = { 0xFFFFFFFF, 0xFF000000,0xFF000000,0xFFFFFFFF };
 
  849                    texture = driver->
addTexture( 
"$checkerimage", w );
 
  854            if ( loadFile == 
"$lightmap" )
 
  860                loadFile.
append ( extension[g] );
 
  867            if ( fileSystem->
existFile ( loadFile ) )
 
  876        textures.push_back(texture);
 
Base class of most objects of the Duckcpp Engine.
Definition IReferenceCounted.hpp:46
 
bool drop() const
Drops the object. Decrements the reference counter by one.
Definition IReferenceCounted.hpp:126
 
The FileSystem manages files and archives and provides access to them.
Definition IFileSystem.hpp:33
 
virtual bool existFile(const path &filename) const =0
Determines if a file exists and could be opened.
 
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
 
dcpp::uint32_kt size() const
Returns length of the string's content.
Definition irrString.hpp:513
 
self_type & append(T character)
Appends a character to this string.
Definition irrString.hpp:659
 
const T * data() const
Returns character string.
Definition irrString.hpp:537
 
3d vector template class with lots of operators and methods.
Definition vector3d.hpp:32
 
T X
X coordinate of the vector.
Definition vector3d.hpp:459
 
T Y
Y coordinate of the vector.
Definition vector3d.hpp:462
 
T Z
Z coordinate of the vector.
Definition vector3d.hpp:465
 
Manages various Quake3 Shader Styles.
Definition IQ3Shader.hpp:882
 
A Parsed Shader Holding Variables ordered in Groups.
Definition IQ3Shader.hpp:652
 
Definition IQ3Shader.hpp:362
 
Definition IQ3Shader.hpp:35
 
A blend function for a q3 shader.
Definition IQ3Shader.hpp:156
 
Definition IQ3Shader.hpp:421
 
holding a group a variable
Definition IQ3Shader.hpp:636
 
Definition IQ3Shader.hpp:582
 
Definition IQ3Shader.hpp:546
 
Interface for software image data.
Definition IImage.hpp:26
 
Interface of a Video Driver dependent Texture.
Definition ITexture.hpp:186
 
Interface to driver which is able to perform 2d and 3d graphics functions.
Definition IVideoDriver.hpp:152
 
virtual dcpp::video::ITexture * findTexture(const dcpp::io::path &filename)=0
Check if the image is already loaded.
 
virtual ITexture * addTexture(const dcpp::nub::dimension2du &size, const dcpp::io::path &name, ECOLOR_FORMAT format=ECF_A8R8G8B8)=0
Creates an empty texture of specified size.
 
virtual IImage * createImageFromData(ECOLOR_FORMAT format, const dcpp::nub::dimension2du &size, void *data, bool ownForeignMemory=false, bool deleteMemory=true)=0
Creates a software image from a byte array.
 
virtual ITexture * getTexture(const dcpp::io::path &filename)=0
Get access to a named texture.
 
const dcpp::float32_kt PI
Constant for PI.
Definition irrMath.hpp:54
 
const char * fast_atof_move(const char *in, dcpp::float32_kt &result)
Provides a fast function for converting a string into a float.
Definition fast_atof.hpp:317
 
dcpp::io::path & cutFilenameExtension(dcpp::io::path &dest, const dcpp::io::path &source)
cut the filename extension from a source file path and store it in a dest file path
Definition coreutil.hpp:48
 
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
 
vector3d< dcpp::float32_kt > vector3df
using type alias for a dcpp::float32_kt 3d vector.
Definition vector3d.hpp:19
 
E_MODULATE_FUNC
MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X.
Definition SMaterial.hpp:56
 
E_BLEND_FACTOR
Definition SMaterial.hpp:25
 
@ EBF_ONE_MINUS_SRC_ALPHA
src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
Definition SMaterial.hpp:33
 
@ EBF_SRC_ALPHA
src & dest (srcA, srcA, srcA, srcA)
Definition SMaterial.hpp:32
 
@ EBF_ZERO
src & dest (0, 0, 0, 0)
Definition SMaterial.hpp:26
 
@ EBF_DST_COLOR
src (destR, destG, destB, destA)
Definition SMaterial.hpp:28
 
@ EBF_ONE
src & dest (1, 1, 1, 1)
Definition SMaterial.hpp:27
 
@ EBF_SRC_COLOR
dest (srcR, srcG, srcB, srcA)
Definition SMaterial.hpp:30
 
E_MATERIAL_FLAG
Material flags.
Definition EMaterialFlags.hpp:15
 
@ EMF_BILINEAR_FILTER
Is bilinear filtering enabled? Default: true.
Definition EMaterialFlags.hpp:43
 
@ ECF_A8R8G8B8
Definition SColor.hpp:38
 
E_MATERIAL_TYPE
Abstracted and easy to use fixed function/programmable pipeline material modes.
Definition EMaterialTypes.hpp:15
 
@ EMT_TRANSPARENT_ALPHA_CHANNEL
Makes the material transparent based on the texture alpha channel.
Definition EMaterialTypes.hpp:101
 
@ EMT_TRANSPARENT_ADD_COLOR
A transparent material.
Definition EMaterialTypes.hpp:88
 
@ EMT_LIGHTMAP_M4
Material type with standard lightmap technique.
Definition EMaterialTypes.hpp:49
 
@ EMT_SOLID
Standard solid material.
Definition EMaterialTypes.hpp:19
 
@ EMT_ONETEXTURE_BLEND
BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )
Definition EMaterialTypes.hpp:193
 
@ ECFN_LESSEQUAL
<= test, default for e.g. depth test
Definition SMaterial.hpp:68
 
@ ECFN_EQUAL
Exact equality.
Definition SMaterial.hpp:70
 
dcpp::float32_kt pack_textureBlendFunc(const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const dcpp::uint32_kt alphaSource=EAS_TEXTURE)
Pack srcFact, dstFact, Modulate and alpha source to MaterialTypeParam or BlendFactor.
Definition SMaterial.hpp:119
 
char char_kt
8 bit character variable.
Definition irrTypes.hpp:37
 
unsigned char uint8_kt
8 bit unsigned variable.
Definition irrTypes.hpp:24
 
unsigned int uint32_kt
32 bit unsigned variable.
Definition irrTypes.hpp:64
 
float float32_kt
32 bit floating point variable.
Definition irrTypes.hpp:108
 
unsigned short uint16_kt
16 bit unsigned variable.
Definition irrTypes.hpp:46
 
signed int int32_kt
32 bit signed variable.
Definition irrTypes.hpp:72
 
signed short int16_kt
16 bit signed variable.
Definition irrTypes.hpp:54