- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-ILUT/src/ilut_states.c

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Utility Toolkit Sources
    00004 // Copyright (C) 2000-2008 by Denton Woods
    00005 // Last modified: 12/17/2008
    00006 //
    00007 // Filename: src-ILUT/src/ilut_states.c
    00008 //
    00009 // Description: The state machine
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013
    00014 #include "ilut_internal.h"
    00015 #include "ilut_states.h"
    00016 //#ifdef ILUT_USE_OPENGL
    00017         #include "ilut_opengl.h"
    00018 //#endif
    00019
    00020
    00021 ILconst_string _ilutVendor      = IL_TEXT("Abysmal Software");
    00022 //ILconst_string _ilutVersion   = IL_TEXT("Developer's Image Library Utility Toolkit (ILUT) 1.7.5 " IL_TEXT(__DATE__));
    00023 ILconst_string _ilutVersion     = IL_TEXT("Developer's Image Library Utility Toolkit (ILUT) 1.7.5 ");
    00024
    00025
    00026 // Set all states to their defaults
    00027 void ilutDefaultStates()
    00028 {
    00029         ilutStates[ilutCurrentPos].ilutUsePalettes = IL_FALSE;
    00030         ilutStates[ilutCurrentPos].ilutForceIntegerFormat = IL_FALSE;
    00031         ilutStates[ilutCurrentPos].ilutOglConv = IL_FALSE;  // IL_TRUE ?
    00032         ilutStates[ilutCurrentPos].ilutDXTCFormat = 0;
    00033         ilutStates[ilutCurrentPos].ilutUseS3TC = IL_FALSE;
    00034         ilutStates[ilutCurrentPos].ilutGenS3TC = IL_FALSE;
    00035         ilutStates[ilutCurrentPos].ilutAutodetectTextureTarget = IL_FALSE;
    00036         ilutStates[ilutCurrentPos].MaxTexW = 256;
    00037         ilutStates[ilutCurrentPos].MaxTexH = 256;
    00038         ilutStates[ilutCurrentPos].MaxTexD = 1;
    00039         ilutStates[ilutCurrentPos].D3DMipLevels = 0;
    00040         ilutStates[ilutCurrentPos].D3DPool = 0;
    00041         ilutStates[ilutCurrentPos].D3DAlphaKeyColor = -1;
    00042 }
    00043
    00044
    00045 void ILAPIENTRY ilutD3D8MipFunc(ILuint NumLevels)
    00046 {
    00047         ilutStates[ilutCurrentPos].D3DMipLevels = NumLevels;
    00048         return;
    00049 }
    00050
    00051
    00052 ILstring ILAPIENTRY ilutGetString(ILenum StringName)
    00053 {
    00054         switch (StringName)
    00055         {
    00056                 case ILUT_VENDOR:
    00057                         return (ILstring)_ilutVendor;
    00058                 //changed 2003-09-04
    00059                 case ILUT_VERSION_NUM:
    00060                         return (ILstring)_ilutVersion;
    00061                 default:
    00062                         ilSetError(ILUT_INVALID_PARAM);
    00063                         break;
    00064         }
    00065         return NULL;
    00066 }
    00067
    00068
    00069 ILboolean ILAPIENTRY ilutEnable(ILenum Mode)
    00070 {
    00071         return ilutAble(Mode, IL_TRUE);
    00072 }
    00073
    00074
    00075 ILboolean ILAPIENTRY ilutDisable(ILenum Mode)
    00076 {
    00077         return ilutAble(Mode, IL_FALSE);
    00078 }
    00079
    00080
    00081 ILboolean ilutAble(ILenum Mode, ILboolean Flag)
    00082 {
    00083         switch (Mode)
    00084         {
    00085                 case ILUT_PALETTE_MODE:
    00086                         ilutStates[ilutCurrentPos].ilutUsePalettes = Flag;
    00087                         break;
    00088
    00089                 case ILUT_FORCE_INTEGER_FORMAT:
    00090                         ilutStates[ilutCurrentPos].ilutForceIntegerFormat = Flag;
    00091                         break;
    00092
    00093                 case ILUT_OPENGL_CONV:
    00094                         ilutStates[ilutCurrentPos].ilutOglConv = Flag;
    00095                         break;
    00096
    00097                 case ILUT_GL_USE_S3TC:
    00098                         ilutStates[ilutCurrentPos].ilutUseS3TC = Flag;
    00099                         break;
    00100
    00101                 case ILUT_GL_GEN_S3TC:
    00102                         ilutStates[ilutCurrentPos].ilutGenS3TC = Flag;
    00103                         break;
    00104
    00105                 case ILUT_GL_AUTODETECT_TEXTURE_TARGET:
    00106                         ilutStates[ilutCurrentPos].ilutAutodetectTextureTarget = Flag;
    00107                         break;
    00108
    00109
    00110                 default:
    00111                         ilSetError(ILUT_INVALID_ENUM);
    00112                         return IL_FALSE;
    00113         }
    00114
    00115         return IL_TRUE;
    00116 }
    00117
    00118
    00119 ILboolean ILAPIENTRY ilutIsEnabled(ILenum Mode)
    00120 {
    00121         switch (Mode)
    00122         {
    00123                 case ILUT_PALETTE_MODE:
    00124                         return ilutStates[ilutCurrentPos].ilutUsePalettes;
    00125
    00126                 case ILUT_FORCE_INTEGER_FORMAT:
    00127                         return ilutStates[ilutCurrentPos].ilutForceIntegerFormat;
    00128
    00129                 case ILUT_OPENGL_CONV:
    00130                         return ilutStates[ilutCurrentPos].ilutOglConv;
    00131
    00132                 case ILUT_GL_USE_S3TC:
    00133                         return ilutStates[ilutCurrentPos].ilutUseS3TC;
    00134
    00135                 case ILUT_GL_GEN_S3TC:
    00136                         return ilutStates[ilutCurrentPos].ilutGenS3TC;
    00137
    00138                 case ILUT_GL_AUTODETECT_TEXTURE_TARGET:
    00139                         return ilutStates[ilutCurrentPos].ilutAutodetectTextureTarget;
    00140
    00141
    00142                 default:
    00143                         ilSetError(ILUT_INVALID_ENUM);
    00144         }
    00145
    00146         return IL_FALSE;
    00147 }
    00148
    00149
    00150 ILboolean ILAPIENTRY ilutIsDisabled(ILenum Mode)
    00151 {
    00152         return !ilutIsEnabled(Mode);
    00153 }
    00154
    00155
    00156 void ILAPIENTRY ilutGetBooleanv(ILenum Mode, ILboolean *Param)
    00157 {
    00158         switch (Mode)
    00159         {
    00160                 case ILUT_PALETTE_MODE:
    00161                         *Param = ilutStates[ilutCurrentPos].ilutUsePalettes;
    00162                         break;
    00163
    00164                 case ILUT_FORCE_INTEGER_FORMAT:
    00165                         *Param = ilutStates[ilutCurrentPos].ilutForceIntegerFormat;
    00166                         break;
    00167
    00168                 case ILUT_OPENGL_CONV:
    00169                         *Param = ilutStates[ilutCurrentPos].ilutOglConv;
    00170                         break;
    00171
    00172                 case ILUT_GL_USE_S3TC:
    00173                         *Param = ilutStates[ilutCurrentPos].ilutUseS3TC;
    00174                         break;
    00175
    00176                 case ILUT_GL_GEN_S3TC:
    00177                         *Param = ilutStates[ilutCurrentPos].ilutGenS3TC;
    00178                         break;
    00179
    00180                 case ILUT_GL_AUTODETECT_TEXTURE_TARGET:
    00181                         *Param = ilutStates[ilutCurrentPos].ilutAutodetectTextureTarget;
    00182                         break;
    00183
    00184                 default:
    00185                         ilSetError(ILUT_INVALID_ENUM);
    00186         }
    00187         return;
    00188 }
    00189
    00190
    00191 ILboolean ILAPIENTRY ilutGetBoolean(ILenum Mode)
    00192 {
    00193         ILboolean Temp = IL_FALSE;
    00194         ilutGetBooleanv(Mode, &Temp);
    00195         return Temp;
    00196 }
    00197
    00198
    00199 void ILAPIENTRY ilutGetIntegerv(ILenum Mode, ILint *Param)
    00200 {
    00201         switch (Mode)
    00202         {
    00203                 /*case IL_ORIGIN_MODE:
    00204                         *Param = ilutStates[ilutCurrentPos].ilutOriginMode;
    00205                         break;*/
    00206                 case ILUT_MAXTEX_WIDTH:
    00207                         *Param = ilutStates[ilutCurrentPos].MaxTexW;
    00208                         break;
    00209                 case ILUT_MAXTEX_HEIGHT:
    00210                         *Param = ilutStates[ilutCurrentPos].MaxTexH;
    00211                         break;
    00212                 case ILUT_MAXTEX_DEPTH:
    00213                         *Param = ilutStates[ilutCurrentPos].MaxTexD;
    00214                         break;
    00215                 case ILUT_VERSION_NUM:
    00216                         *Param = ILUT_VERSION;
    00217                         break;
    00218                 case ILUT_PALETTE_MODE:
    00219                         *Param = ilutStates[ilutCurrentPos].ilutUsePalettes;
    00220                         break;
    00221                 case ILUT_FORCE_INTEGER_FORMAT:
    00222                         *Param = ilutStates[ilutCurrentPos].ilutForceIntegerFormat;
    00223                         break;
    00224                 case ILUT_OPENGL_CONV:
    00225                         *Param = ilutStates[ilutCurrentPos].ilutOglConv;
    00226                         break;
    00227                 case ILUT_GL_USE_S3TC:
    00228                         *Param = ilutStates[ilutCurrentPos].ilutUseS3TC;
    00229                         break;
    00230                 case ILUT_GL_GEN_S3TC:
    00231                         *Param = ilutStates[ilutCurrentPos].ilutUseS3TC;
    00232                         break;
    00233                 case ILUT_S3TC_FORMAT:
    00234                         *Param = ilutStates[ilutCurrentPos].ilutDXTCFormat;
    00235                         break;
    00236                 case ILUT_GL_AUTODETECT_TEXTURE_TARGET:
    00237                         *Param = ilutStates[ilutCurrentPos].ilutAutodetectTextureTarget;
    00238                         break;
    00239                 case ILUT_D3D_MIPLEVELS:
    00240                         *Param = ilutStates[ilutCurrentPos].D3DMipLevels;
    00241                         break;
    00242                 case ILUT_D3D_ALPHA_KEY_COLOR:
    00243                         *Param = ilutStates[ilutCurrentPos].D3DAlphaKeyColor;
    00244                         break;
    00245                 case ILUT_D3D_POOL:
    00246                         *Param = ilutStates[ilutCurrentPos].D3DPool;
    00247                         break;
    00248
    00249                 default:
    00250                         ilSetError(ILUT_INVALID_ENUM);
    00251         }
    00252         return;
    00253 }
    00254
    00255
    00256 ILint ILAPIENTRY ilutGetInteger(ILenum Mode)
    00257 {
    00258         ILint Temp = 0;
    00259         ilutGetIntegerv(Mode, &Temp);
    00260         return Temp;
    00261 }
    00262
    00263
    00264 void ILAPIENTRY ilutSetInteger(ILenum Mode, ILint Param)
    00265 {
    00266         switch (Mode)
    00267         {
    00268                 case ILUT_S3TC_FORMAT:
    00269                         if (Param >= IL_DXT1 && Param <= IL_DXT5) {
    00270                                 ilutStates[ilutCurrentPos].ilutDXTCFormat = Param;
    00271                                 return;
    00272                         }
    00273
    00274 //#ifdef ILUT_USE_OPENGL
    00275                 case ILUT_MAXTEX_WIDTH:
    00276                         ilutStates[ilutCurrentPos].MaxTexW = Param;
    00277                         return;
    00278                 case ILUT_MAXTEX_HEIGHT:
    00279                         ilutStates[ilutCurrentPos].MaxTexH = Param;
    00280                         return;
    00281                 case ILUT_MAXTEX_DEPTH:
    00282                         ilutStates[ilutCurrentPos].MaxTexD = Param;
    00283                         break;
    00284                 case ILUT_GL_USE_S3TC:
    00285                         if (Param == IL_TRUE || Param == IL_FALSE) {
    00286                                 ilutStates[ilutCurrentPos].ilutUseS3TC = (ILboolean)Param;
    00287                                 return;
    00288                         }
    00289                         break;
    00290                 case ILUT_GL_GEN_S3TC:
    00291                         if (Param == IL_TRUE || Param == IL_FALSE) {
    00292                                 ilutStates[ilutCurrentPos].ilutGenS3TC = (ILboolean)Param;
    00293                                 return;
    00294                         }
    00295                         break;
    00296                 case ILUT_GL_AUTODETECT_TEXTURE_TARGET:
    00297                         if (Param == IL_TRUE || Param == IL_FALSE) {
    00298                                 ilutStates[ilutCurrentPos].ilutAutodetectTextureTarget = (ILboolean)Param;
    00299                                 return;
    00300                         }
    00301                         break;
    00302 //#endif//ILUT_USE_OPENGL
    00303
    00304 //#ifdef ILUT_USE_DIRECTX8
    00305                 case ILUT_D3D_MIPLEVELS:
    00306                         if (Param >= 0) {
    00307                                 ilutStates[ilutCurrentPos].D3DMipLevels = Param;
    00308                                 return;
    00309                         }
    00310                         break;
    00311
    00312                 case ILUT_D3D_ALPHA_KEY_COLOR:
    00313                                 ilutStates[ilutCurrentPos].D3DAlphaKeyColor = Param;
    00314                                 return;
    00315                         break;
    00316
    00317                 case ILUT_D3D_POOL:
    00318                         if (Param >= 0 && Param <= 2) {
    00319                                 ilutStates[ilutCurrentPos].D3DPool = Param;
    00320                                 return;
    00321                         }
    00322                         break;
    00323 //#endif//ILUT_USE_DIRECTX8
    00324
    00325                 default:
    00326                         ilSetError(ILUT_INVALID_ENUM);
    00327         }
    00328
    00329         ilSetError(IL_INVALID_PARAM);  // Parameter not in valid bounds.
    00330         return;
    00331 }
    00332
    00333
    00334 void ILAPIENTRY ilutPushAttrib(ILuint Bits)
    00335 {
    00336         // Should we check here to see if ilCurrentPos is negative?
    00337
    00338         if (ilutCurrentPos >= ILUT_ATTRIB_STACK_MAX - 1) {
    00339                 ilutCurrentPos = ILUT_ATTRIB_STACK_MAX - 1;
    00340                 ilSetError(ILUT_STACK_OVERFLOW);
    00341                 return;
    00342         }
    00343
    00344         ilutCurrentPos++;
    00345
    00346         //memcpy(&ilutStates[ilutCurrentPos], &ilutStates[ilutCurrentPos - 1], sizeof(ILUT_STATES));
    00347
    00348         if (Bits & ILUT_OPENGL_BIT) {
    00349                 ilutStates[ilutCurrentPos].ilutUsePalettes = ilutStates[ilutCurrentPos-1].ilutUsePalettes;
    00350                 ilutStates[ilutCurrentPos].ilutOglConv = ilutStates[ilutCurrentPos-1].ilutOglConv;
    00351         }
    00352         if (Bits & ILUT_D3D_BIT) {
    00353                 ilutStates[ilutCurrentPos].D3DMipLevels = ilutStates[ilutCurrentPos-1].D3DMipLevels;
    00354                 ilutStates[ilutCurrentPos].D3DAlphaKeyColor = ilutStates[ilutCurrentPos-1].D3DAlphaKeyColor;
    00355         }
    00356
    00357         return;
    00358 }
    00359
    00360
    00361 void ILAPIENTRY ilutPopAttrib()
    00362 {
    00363         if (ilutCurrentPos <= 0) {
    00364                 ilutCurrentPos = 0;
    00365                 ilSetError(ILUT_STACK_UNDERFLOW);
    00366                 return;
    00367         }
    00368
    00369         // Should we check here to see if ilutCurrentPos is too large?
    00370         ilutCurrentPos--;
    00371
    00372         return;
    00373 }
    00374
    00375
    00376 ILboolean ILAPIENTRY ilutRenderer(ILenum Renderer)
    00377 {
    00378         if (Renderer > ILUT_WIN32) {
    00379                 ilSetError(ILUT_INVALID_VALUE);
    00380                 return IL_FALSE;
    00381         }
    00382
    00383         switch (Renderer)
    00384         {
    00385                 #ifdef ILUT_USE_OPENGL
    00386                 case ILUT_OPENGL:
    00387                         return ilutGLInit();
    00388                 #endif
    00389
    00390                 #ifdef ILUT_USE_WIN32
    00391                 case ILUT_WIN32:
    00392                         return ilutWin32Init();
    00393                 #endif
    00394
    00395                 #ifdef ILUT_USE_DIRECTX8
    00396                 case ILUT_DIRECT3D8:
    00397                         return ilutD3D8Init();
    00398                 #endif
    00399
    00400                 #ifdef ILUT_USE_DIRECTX9
    00401         case ILUT_DIRECT3D9:
    00402                 return ilutD3D9Init();
    00403         #endif
    00404
    00405                 #ifdef ILUT_USE_DIRECTX10
    00406         case ILUT_DIRECT3D10:
    00407                 return ilutD3D10Init();
    00408         #endif
    00409
    00410                 default:
    00411                         ilSetError(ILUT_NOT_SUPPORTED);
    00412         }
    00413
    00414         return IL_FALSE;
    00415 }