#include <stdlib.h>#include <memory.h>#include <Assert.h>#include "SoftDrv.h"#include "SWTHandle.h"Go to the source code of this file.
|
|
Definition at line 34 of file SWTHandle.c. |
|
|
Definition at line 38 of file SWTHandle.c. |
|
||||||||||||||||||||
|
Definition at line 144 of file SWTHandle.c. References geRDriver_THandle::BitPtr, DRIVERCC, geRDriver_PixelFormat::Flags, geRDriver_THandle::Flags, GE_ERR_INTERNAL_RESOURCE, GE_PIXELFORMAT_16BIT_4444_ARGB, GE_PIXELFORMAT_16BIT_555_RGB, GE_PIXELFORMAT_16BIT_565_RGB, GE_PIXELFORMAT_24BIT_RGB, GE_PIXELFORMAT_32BIT_XBGR, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT, geErrorLog_AddString, geRDriver_THandle::Height, int32, geRDriver_THandle::MipLevels, NULL, PixelFormat, geRDriver_THandle::PixelFormat, geRDriver_PixelFormat::PixelFormat, RDRIVER_PF_3D, RDRIVER_PF_CAN_DO_COLORKEY, RDRIVER_PF_PALETTE, SWTHandle_FindTextureHandle(), SWTHandle_SnapToPower2(), THANDLE_TRANS, U32, uint16, uint8, and geRDriver_THandle::Width.
00148 {
00149 int32 i, SWidth, SHeight; // Snapped to power of 2 width/height
00150 geRDriver_THandle *THandle;
00151
00152 assert(PixelFormat);
00153
00154 THandle = SWTHandle_FindTextureHandle();
00155
00156 if (!THandle)
00157 {
00158 geErrorLog_AddString(GE_ERR_INTERNAL_RESOURCE, "SWTHandle_CreateTexture: No more handles left.",NULL);
00159 goto ExitWithError;
00160 }
00161
00162 if(PixelFormat->Flags & RDRIVER_PF_3D)
00163 {
00164 if (Width > 256)
00165 {
00166 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_CreateTexture: Width > 256.",NULL);
00167 goto ExitWithError;
00168 }
00169
00170 if (Height > 256)
00171 {
00172 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_CreateTexture: Height > 256.",NULL);
00173 goto ExitWithError;
00174 }
00175 SWidth = SWTHandle_SnapToPower2(Width);
00176 SHeight = SWTHandle_SnapToPower2(Height);
00177
00178 if (Width != SWidth)
00179 {
00180 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_CreateTexture: Not a power of 2.",NULL);
00181 goto ExitWithError;
00182 }
00183
00184 if (Height != SHeight)
00185 {
00186 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_CreateTexture: Not a power of 2.",NULL);
00187 goto ExitWithError;
00188 }
00189 }
00190
00191 THandle->MipLevels =NumMipLevels;
00192 THandle->Width =Width;
00193 THandle->Height =Height;
00194 THandle->PixelFormat =*PixelFormat;
00195
00196 for(i=0;i < NumMipLevels;i++)
00197 {
00198 if(PixelFormat->Flags & RDRIVER_PF_PALETTE)
00199 {
00200
00201 if( PixelFormat->PixelFormat == GE_PIXELFORMAT_32BIT_XRGB ||
00202 PixelFormat->PixelFormat == GE_PIXELFORMAT_32BIT_XBGR)
00203 {
00204 THandle->BitPtr[i] =(uint16 *)malloc(sizeof(U32) * Width * Height);
00205 }
00206 else
00207 {
00208 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_CreateTexture: Bad Pal format.",NULL);
00209 goto ExitWithError;
00210 }
00211 }
00212 else
00213 {
00214 switch (PixelFormat->PixelFormat)
00215 {
00216 case GE_PIXELFORMAT_16BIT_4444_ARGB:
00217 {
00218 THandle->BitPtr[i] =(uint16 *)malloc(sizeof(uint16) * Width * Height);
00219 break;
00220 }
00221
00222 case GE_PIXELFORMAT_16BIT_565_RGB:
00223 {
00224 THandle->BitPtr[i] =(uint16 *)malloc(sizeof(uint16) * Width * Height);
00225 break;
00226 }
00227
00228 case GE_PIXELFORMAT_16BIT_555_RGB:
00229 {
00230 THandle->BitPtr[i] =(uint16 *)malloc(sizeof(uint16) * Width * Height);
00231 break;
00232 }
00233
00234 case GE_PIXELFORMAT_8BIT:
00235 {
00236 THandle->BitPtr[i] =(uint16 *)malloc(sizeof(uint8) * Width * Height);
00237 break;
00238 }
00239
00240 case GE_PIXELFORMAT_24BIT_RGB:
00241 {
00242 THandle->BitPtr[i] =(uint16 *)malloc((sizeof(uint8)*3) * Width * Height);
00243 break;
00244 }
00245
00246 default:
00247 {
00248 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SOFT_Create3DTexture: Invalid pixel format.",NULL);
00249 goto ExitWithError;
00250 }
00251 }
00252
00253 if ( PixelFormat->Flags & RDRIVER_PF_CAN_DO_COLORKEY )
00254 {
00255 THandle->Flags |= THANDLE_TRANS;
00256 }
00257
00258 }
00259 Width = Width / 2;
00260 if (Width < 1) Width = 1;
00261 Height = Height / 2;
00262 if (Height < 1) Height = 1;
00263 }
00264
00265 return THandle;
00266
00267 ExitWithError:
00268 {
00269 return NULL;
00270 }
00271 }
|
|
|
Definition at line 354 of file SWTHandle.c. References DRIVERCC, geBoolean, and SWTHandle_FreeTextureHandle().
00355 {
00356 return SWTHandle_FreeTextureHandle(THandle);
00357 }
|
|
||||||||||||
|
|
Definition at line 60 of file SWTHandle.c. References geRDriver_THandle::Active, GE_TRUE, int32, MAX_TEXTURE_HANDLES, NULL, and SWTHandle_TextureHandles. Referenced by SWTHandle_CreateTexture().
00061 {
00062 int32 i;
00063 geRDriver_THandle *THandle;
00064
00065 THandle = SWTHandle_TextureHandles;
00066
00067 for (i=0; i< MAX_TEXTURE_HANDLES; i++, THandle++)
00068 {
00069 if (!THandle->Active)
00070 {
00071 memset(THandle, 0, sizeof(geRDriver_THandle));
00072
00073 THandle->Active = GE_TRUE;
00074
00075 return THandle;
00076 }
00077 }
00078
00079 return NULL;
00080 }
|
|
|
Definition at line 124 of file SWTHandle.c. References geRDriver_THandle::Active, GE_TRUE, geBoolean, int32, MAX_TEXTURE_HANDLES, SWTHandle_FreeTextureHandle(), and SWTHandle_TextureHandles. Referenced by SoftDrv_ResetAll().
00125 {
00126 int32 i;
00127 geRDriver_THandle *pTHandle;
00128
00129 pTHandle = SWTHandle_TextureHandles;
00130
00131 for (i=0; i< MAX_TEXTURE_HANDLES; i++, pTHandle++)
00132 {
00133 if (!pTHandle->Active)
00134 {
00135 continue;
00136 }
00137
00138 SWTHandle_FreeTextureHandle(pTHandle);
00139 }
00140
00141 return GE_TRUE;
00142 }
|
|
|
Definition at line 85 of file SWTHandle.c. References geRDriver_THandle::Active, geRDriver_THandle::AlphaHandle, geRDriver_THandle::BitPtr, GE_FALSE, GE_TRUE, geBoolean, geRDriver_THandle::MipLevels, NULL, and geRDriver_THandle::PalHandle. Referenced by SWTHandle_DestroyTexture(), and SWTHandle_FreeAllTextureHandles().
00086 {
00087 int k;
00088
00089 assert(THandle);
00090 //<> assert(THandle->Active == GE_TRUE);
00091
00092 if( ! THandle->Active )
00093 {
00094 return GE_FALSE;
00095 }
00096
00097 if(THandle->PalHandle)
00098 {
00099 SWTHandle_FreeTextureHandle(THandle->PalHandle);
00100 }
00101
00102 if(THandle->AlphaHandle)
00103 {
00104 SWTHandle_FreeTextureHandle(THandle->AlphaHandle);
00105 }
00106
00107 for(k=0;k < THandle->MipLevels;k++)
00108 {
00109 if(THandle->BitPtr[k])
00110 {
00111 free(THandle->BitPtr[k]);
00112 }
00113 THandle->BitPtr[k] =NULL;
00114 }
00115
00116 memset(THandle, 0, sizeof(geRDriver_THandle));
00117
00118 return GE_TRUE;
00119 }
|
|
|
Definition at line 342 of file SWTHandle.c. References geRDriver_THandle::Active, geRDriver_THandle::AlphaHandle, DRIVERCC, GE_FALSE, geErrorLog_AddString, and NULL.
00343 {
00344 assert(THandle);
00345 if ( ! THandle->Active )
00346 {
00347 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_GetAlpha: Bad Texture Handle.",NULL);
00348 return GE_FALSE;
00349 }
00350
00351 return THandle->AlphaHandle;
00352 }
|
|
||||||||||||||||
|
Definition at line 273 of file SWTHandle.c. References geRDriver_THandle::Active, geRDriver_THandleInfo::ColorKey, DRIVERCC, geRDriver_THandleInfo::Flags, geRDriver_THandle::Flags, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, geRDriver_THandleInfo::Height, geRDriver_THandle::Height, NULL, geRDriver_THandleInfo::PixelFormat, geRDriver_THandle::PixelFormat, RDRIVER_THANDLE_HAS_COLORKEY, geRDriver_THandleInfo::Stride, THANDLE_TRANS, geRDriver_THandleInfo::Width, and geRDriver_THandle::Width.
00274 {
00275 assert(THandle);
00276 assert(Info);
00277 if ( ! THandle->Active )
00278 {
00279 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_GetInfo: Bad Texture Handle.",NULL);
00280 return GE_FALSE;
00281 }
00282
00283
00284 Info->Width = THandle->Width >> MipLevel;
00285 Info->Height = THandle->Height >> MipLevel;
00286 Info->Stride = THandle->Width >> MipLevel;
00287 Info->ColorKey = 1;
00288 Info->Flags = GE_FALSE;
00289 #pragma message ("is this right?")
00290 Info->PixelFormat = THandle->PixelFormat;
00291 if ( THandle->Flags & THANDLE_TRANS )
00292 {
00293 #pragma message ("remember this")
00294 Info->Flags = RDRIVER_THANDLE_HAS_COLORKEY;
00295 }
00296 return GE_TRUE;
00297 }
|
|
|
Definition at line 310 of file SWTHandle.c. References geRDriver_THandle::Active, DRIVERCC, GE_FALSE, geErrorLog_AddString, NULL, and geRDriver_THandle::PalHandle.
00311 {
00312 assert(THandle);
00313 if ( ! THandle->Active )
00314 {
00315 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_GetPalette: Bad Texture Handle.",NULL);
00316 return GE_FALSE;
00317 }
00318
00319 return THandle->PalHandle;
00320 }
|
|
||||||||||||||||
|
Definition at line 359 of file SWTHandle.c. References geRDriver_THandle::Active, geRDriver_THandle::BitPtr, DRIVERCC, geRDriver_THandle::Flags, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, NULL, THANDLE_LOCKED, and uint16.
00360 {
00361 assert(THandle);
00362 assert(MipLevel <= THandle->MipLevels && MipLevel >= 0);
00363 if ( ! THandle->Active )
00364 {
00365 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_LockTextureHandle: Bad Texture Handle.",NULL);
00366 return GE_FALSE;
00367 }
00368 if ( ! THandle->BitPtr[MipLevel] )
00369 {
00370 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_LockTextureHandle: Bad Texture Handle in Mip.",NULL);
00371 return GE_FALSE;
00372 }
00373
00374 THandle->Flags |=(THANDLE_LOCKED << MipLevel);
00375 *Data =(uint16*)THandle->BitPtr[MipLevel];
00376
00377 return GE_TRUE;
00378 }
|
|
||||||||||||
|
Definition at line 322 of file SWTHandle.c. References geRDriver_THandle::Active, geRDriver_THandle::AlphaHandle, DRIVERCC, geRDriver_PixelFormat::Flags, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, NULL, geRDriver_THandle::PixelFormat, RDRIVER_PF_ALPHA, and RDRIVER_PF_HAS_ALPHA.
00323 {
00324 assert(THandle);
00325 if ( ! THandle->Active )
00326 {
00327 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_SetAlpha: Bad Texture Handle.",NULL);
00328 return GE_FALSE;
00329 }
00330
00331 if(THandle->PixelFormat.Flags & RDRIVER_PF_HAS_ALPHA)
00332 {
00333 if(AHandle->PixelFormat.Flags & RDRIVER_PF_ALPHA)
00334 {
00335 THandle->AlphaHandle =AHandle;
00336 return GE_TRUE;
00337 }
00338 }
00339 return GE_FALSE;
00340 }
|
|
||||||||||||
|
Definition at line 300 of file SWTHandle.c. References DRIVERCC, GE_TRUE, geBoolean, and geRDriver_THandle::PalHandle.
|
|
|
Definition at line 42 of file SWTHandle.c. References int32. Referenced by SWTHandle_CreateTexture().
00043 {
00044 if (Width > 1 && Width <= 2) Width = 2;
00045 else if (Width > 2 && Width <= 4) Width = 4;
00046 else if (Width > 4 && Width <= 8) Width = 8;
00047 else if (Width > 8 && Width <= 16) Width =16;
00048 else if (Width > 16 && Width <= 32) Width = 32;
00049 else if (Width > 32 && Width <= 64) Width = 64;
00050 else if (Width > 64 && Width <= 128) Width = 128;
00051 else if (Width > 128 && Width <= 256) Width = 256;
00052
00053 return Width;
00054 }
|
|
||||||||||||
|
Definition at line 380 of file SWTHandle.c. References DRIVERCC, geRDriver_THandle::Flags, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, NULL, THANDLE_LOCKED, and THANDLE_UPDATE.
00381 {
00382 assert(THandle);
00383 if (!(THandle->Flags & (THANDLE_LOCKED << MipLevel)))
00384 {
00385 geErrorLog_AddString(GE_ERR_BAD_PARAMETER, "SWTHandle_UnLockTextureHandle: Texture Handle is not Locked.",NULL);
00386 return GE_FALSE;
00387 }
00388
00389
00390 THandle->Flags &=~(THANDLE_LOCKED << MipLevel); // This mip is now unlocked
00391 THandle->Flags |=THANDLE_UPDATE; // Mark it for updating...
00392
00393 return GE_TRUE;
00394 }
|
|
|
Definition at line 40 of file SWTHandle.c. Referenced by SWTHandle_FindTextureHandle(), and SWTHandle_FreeAllTextureHandles(). |
1.3.2