Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

478 lines
13 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: sscommon.h
  3. *
  4. * Defines and externals for screen saver common shell
  5. *
  6. * Copyright (c) 1994 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #ifndef __sscommon_h__
  10. #define __sscommon_h__
  11. #include <GL\gl.h>
  12. #include <assert.h>
  13. #include "tk.h"
  14. #include "matname.h" // material names
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ssdebug.h"
  19. #define FAILURE 0
  20. #define SUCCESS 1
  21. // Maximum texture bitmap dimensions.
  22. #define TEX_WIDTH_MAX 1280
  23. #define TEX_HEIGHT_MAX 1024
  24. #define PI 3.14159265358979323846f
  25. // double version of PI
  26. #define PI_D 3.14159265358979323846264338327950288419716939937510
  27. #define ONE_OVER_PI (1.0f / PI)
  28. #define ROOT_TWO 1.414213562373f
  29. #define GEN_STRING_SIZE 64
  30. // texture quality level
  31. enum {
  32. TEXQUAL_DEFAULT = 0,
  33. TEXQUAL_HIGH
  34. };
  35. typedef struct _point2d {
  36. GLfloat x;
  37. GLfloat y;
  38. } POINT2D;
  39. typedef struct _ipoint2d {
  40. int x;
  41. int y;
  42. } IPOINT2D;
  43. typedef struct _point3d {
  44. GLfloat x;
  45. GLfloat y;
  46. GLfloat z;
  47. } POINT3D;
  48. typedef struct _ipoint3d {
  49. int x;
  50. int y;
  51. int z;
  52. } IPOINT3D;
  53. typedef struct _texpoint2d {
  54. GLfloat s;
  55. GLfloat t;
  56. } TEX_POINT2D;
  57. typedef struct _isize {
  58. int width;
  59. int height;
  60. } ISIZE;
  61. typedef struct _fsize {
  62. GLfloat width;
  63. GLfloat height;
  64. } FSIZE;
  65. typedef struct _glrect {
  66. int x, y;
  67. int width, height;
  68. } GLRECT;
  69. // texture data
  70. typedef struct {
  71. int width;
  72. int height;
  73. GLenum format;
  74. GLsizei components;
  75. float origAspectRatio; // original width/height aspect ratio
  76. unsigned char *data;
  77. GLuint texObj; // texture object
  78. int pal_size;
  79. int iPalRot; // current palette rotation (not used yet)
  80. RGBQUAD *pal;
  81. } TEXTURE, *HTEXTURE;
  82. #ifndef GL_EXT_paletted_texture
  83. #define GL_COLOR_INDEX1_EXT 0x80E2
  84. #define GL_COLOR_INDEX2_EXT 0x80E3
  85. #define GL_COLOR_INDEX4_EXT 0x80E4
  86. #define GL_COLOR_INDEX8_EXT 0x80E5
  87. #define GL_COLOR_INDEX12_EXT 0x80E6
  88. #define GL_COLOR_INDEX16_EXT 0x80E7
  89. typedef void (APIENTRY * PFNGLCOLORTABLEEXTPROC)
  90. (GLenum target, GLenum internalFormat, GLsizei width, GLenum format,
  91. GLenum type, const GLvoid *data);
  92. typedef void (APIENTRY * PFNGLCOLORSUBTABLEEXTPROC)
  93. (GLenum target, GLsizei start, GLsizei count, GLenum format,
  94. GLenum type, GLvoid *data);
  95. #endif
  96. // texture resource
  97. #define RT_RGB 99
  98. #define RT_MYBMP 100
  99. #define RT_A8 101
  100. // texture resource types
  101. enum {
  102. TEX_UNKNOWN = 0,
  103. TEX_RGB,
  104. TEX_BMP,
  105. TEX_A8
  106. };
  107. typedef struct {
  108. int type;
  109. int name;
  110. } TEX_RES;
  111. typedef struct _MATRIX {
  112. GLfloat M[4][4];
  113. } MATRIX;
  114. typedef struct strRGBA {
  115. GLfloat r;
  116. GLfloat g;
  117. GLfloat b;
  118. GLfloat a;
  119. } RGBA;
  120. typedef struct {
  121. BYTE r;
  122. BYTE g;
  123. BYTE b;
  124. } RGB8;
  125. typedef struct {
  126. BYTE r;
  127. BYTE g;
  128. BYTE b;
  129. BYTE a;
  130. } RGBA8;
  131. // DlgDraw
  132. enum {
  133. DLG_INTENSITY_LOW = 0,
  134. DLG_INTENSITY_MID,
  135. DLG_INTENSITY_HIGH,
  136. };
  137. // Callback function defines
  138. typedef void (CALLBACK* SSINITPROC)( void *);
  139. typedef void (CALLBACK* SSRESHAPEPROC)(int, int, void *);
  140. typedef void (CALLBACK* SSREPAINTPROC)( LPRECT, void *);
  141. typedef void (CALLBACK* SSUPDATEPROC)( void *);
  142. typedef void (CALLBACK* SSFINISHPROC)( void *);
  143. typedef void (CALLBACK* SSFLOATERFAILPROC)(void *);
  144. typedef void (CALLBACK* SSFLOATERBOUNCEPROC)( void *);
  145. // Defines for pixel format (internal use)
  146. #define SS_DOUBLEBUF_BIT (1 << 0)
  147. #define SS_DEPTH16_BIT (1 << 1)
  148. #define SS_DEPTH32_BIT (1 << 2)
  149. #define SS_ALPHA_BIT (1 << 3)
  150. #define SS_BITMAP_BIT (1 << 4)
  151. #define SS_NO_SYSTEM_PALETTE_BIT (1 << 5)
  152. #define SS_GENERIC_UNACCELERATED_BIT (1 << 6)
  153. #define SS_HAS_DOUBLEBUF(x) ((x) & SS_DOUBLEBUF_BIT)
  154. #define SS_HAS_DEPTH16(x) ((x) & SS_DEPTH16_BIT)
  155. #define SS_HAS_DEPTH32(x) ((x) & SS_DEPTH32_BIT)
  156. #define SS_HAS_ALPHA(x) ((x) & SS_ALPHA_BIT)
  157. #define SS_HAS_BITMAP(x) ((x) & SS_BITMAP_BIT)
  158. // Depth types
  159. enum {
  160. SS_DEPTH_NONE = 0,
  161. SS_DEPTH16,
  162. SS_DEPTH32,
  163. };
  164. // ss context structures
  165. // Note: all *_INFO structures are requests between common and client ss
  166. typedef struct {
  167. POINT2D posInc; // base position increment
  168. POINT2D posIncVary; // +/- variation for posInc on bounce
  169. } MOTION_INFO;
  170. // internal motion structure
  171. typedef struct {
  172. POINT2D pos; // position
  173. POINT2D posInc; // base position increment
  174. POINT2D posIncVary; // +/- variation for posInc on bounce
  175. POINT2D posIncCur; // Current position increment
  176. } MOTION;
  177. // Size and motion attributes of the OpenGL window that floats around.
  178. typedef struct {
  179. ISIZE size;
  180. IPOINT2D pos; // position
  181. MOTION_INFO motionInfo;
  182. } CHILD_INFO;
  183. typedef void (CALLBACK* SSCHILDSIZEPROC)( ISIZE *, CHILD_INFO * );
  184. // Size and motion attributes of the OpenGL window that floats around.
  185. typedef struct {
  186. BOOL bMotion; // if floater should move or not
  187. BOOL bSubWindow; // If floater is logical sub-window
  188. SSCHILDSIZEPROC ChildSizeFunc; // Callback to set size based on parent
  189. } FLOATER_INFO;
  190. // SS_BITMAP already defined in winuser.h
  191. #if defined( SS_BITMAP )
  192. #undef SS_BITMAP
  193. #endif
  194. typedef struct {
  195. HDC hdc;
  196. ISIZE size;
  197. HBITMAP hbm;
  198. HBITMAP hbmOld; // ? necessary ?
  199. } SS_BITMAP;
  200. // Attributes for StretchBlt mode
  201. typedef struct {
  202. BOOL bRatioMode; // use ratio or base width
  203. float widthRatio; // e.g. 2 means use base of (window width / 2)
  204. float heightRatio;
  205. int baseWidth;
  206. int baseHeight;
  207. SS_BITMAP ssbm;
  208. } STRETCH_INFO;
  209. typedef struct {
  210. BOOL bFloater;
  211. FLOATER_INFO floaterInfo;
  212. BOOL bStretch;
  213. STRETCH_INFO stretchInfo;
  214. BOOL bDoubleBuf;
  215. int depthType;
  216. } SSContext, SSC, *PSSC;
  217. typedef struct _MATERIAL {
  218. RGBA ka;
  219. RGBA kd;
  220. RGBA ks;
  221. GLfloat specExp;
  222. } MATERIAL;
  223. // texture file info
  224. typedef struct {
  225. int nOffset; // filename offset into pathname
  226. TCHAR szPathName[MAX_PATH]; // texture pathname
  227. } TEXFILE;
  228. // texture file processing messages
  229. typedef struct {
  230. TCHAR szWarningMsg[MAX_PATH];
  231. TCHAR szBitmapSizeMsg[MAX_PATH];
  232. TCHAR szBitmapInvalidMsg[MAX_PATH];
  233. TCHAR szSelectAnotherBitmapMsg[MAX_PATH];
  234. TCHAR szTextureDialogTitle[GEN_STRING_SIZE];
  235. TCHAR szTextureFilter[2*GEN_STRING_SIZE];
  236. TCHAR szBmp[GEN_STRING_SIZE];
  237. TCHAR szDotBmp[GEN_STRING_SIZE];
  238. } TEX_STRINGS;
  239. // Resource constants common to all screen savers
  240. #define IDS_COPYRIGHT 9001
  241. #define IDS_GENNAME 9003
  242. #define IDS_INIFILE 9006
  243. #define IDS_HELPFILE 9009
  244. #define IDS_WARNING 9014
  245. #define IDS_ERROR 9015
  246. #define IDS_BITMAP_SIZE 9016
  247. #define IDS_BITMAP_INVALID 9017
  248. #define IDS_SELECT_ANOTHER_BITMAP 9018
  249. #define IDS_START_FAILED 9019
  250. #define IDS_TEXTUREFILTER 9021
  251. #define IDS_TEXTUREDIALOGTITLE 9022
  252. #define IDS_BMP 9023
  253. #define IDS_DOTBMP 9024
  254. #define IDS_STARDOTBMP 9025
  255. #define IDS_RGB 9030
  256. #define IDS_DOTRGB 9031
  257. #define IDS_STARDOTRGB 9032
  258. #define IDS_TEXTURE 9126
  259. #define IDS_TEXTURE_FILE_OFFSET 9127
  260. #define IDS_SIZE 9129
  261. #define IDS_TESSELATION 9130
  262. // Useful macros
  263. #define SS_MAX( a, b ) \
  264. ( a > b ? a : b )
  265. #define SS_MIN( a, b ) \
  266. ( a < b ? a : b )
  267. // macro to round up floating values
  268. #define SS_ROUND_UP( fval ) \
  269. ( (((fval) - (FLOAT)(int)(fval)) > 0.0f) ? (int) ((fval)+1.0f) : (int) (fval) )
  270. // macros to clamp a value within a range
  271. #define SS_CLAMP_TO_RANGE( a, lo, hi ) ( (a < lo) ? lo : ((a > hi) ? hi : a) )
  272. #define SS_CLAMP_TO_RANGE2( a, lo, hi ) \
  273. ( a = (a < lo) ? lo : ((a > hi) ? hi : a) )
  274. // degree<->radian macros
  275. #define ONE_OVER_180 (1.0f / 180.0f)
  276. #define SS_DEG_TO_RAD( a ) ( (a*PI) * ONE_OVER_180 )
  277. #define SS_RAD_TO_DEG( a ) ( (a*180.0f) * ONE_OVER_PI )
  278. extern MATERIAL TeaMaterial[], TexMaterial[], ss_BlackMat;
  279. // window handling
  280. extern void ss_InitFunc(SSINITPROC);
  281. extern void ss_ReshapeFunc(SSRESHAPEPROC);
  282. extern void ss_RepaintFunc(SSREPAINTPROC);
  283. extern void ss_UpdateFunc(SSUPDATEPROC);
  284. extern void ss_FinishFunc(SSFINISHPROC);
  285. extern void ss_FloaterBounceFunc(SSFLOATERBOUNCEPROC);
  286. // This function *must* be defined by the screen saver
  287. extern SSContext* ss_Init(void);
  288. extern BOOL ss_ConfigInit( HWND hDlg );
  289. extern void ss_DataPtr( void * );
  290. extern BOOL ss_SetWindowAspectRatio( FLOAT aspect );
  291. extern void ss_RandomWindowPos( void );
  292. extern HWND ss_GetHWND();
  293. extern HWND ss_GetGLHWND();
  294. extern void ss_GetScreenSize( ISIZE *size );
  295. extern HBITMAP
  296. SSDIB_CreateCompatibleDIB(HDC hdc, HPALETTE hpal, ULONG ulWidth, ULONG ulHeight,
  297. PVOID *ppvBits);
  298. extern BOOL APIENTRY SSDIB_UpdateColorTable(HDC hdcMem, HDC hdc, HPALETTE hpal);
  299. // Palette manage procs
  300. extern LONG MainPaletteManageProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  301. extern LONG PaletteManageProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  302. extern LONG FullScreenPaletteManageProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  303. extern LONG NullPaletteManageProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  304. // material processing
  305. extern void ss_InitTeaMaterials();
  306. extern void ss_InitTexMaterials();
  307. extern void ss_InitMaterials();
  308. extern void ss_SetMaterial( MATERIAL *pMat );
  309. extern void ss_SetMaterialIndex( int index );
  310. extern MATERIAL *ss_RandomTeaMaterial( BOOL bSet );
  311. extern int ss_RandomTeaMaterialIndex( BOOL bSet );
  312. extern MATERIAL *ss_RandomTexMaterial( BOOL bSet );
  313. extern int ss_RandomTexMaterialIndex( BOOL bSet );
  314. extern void ss_CreateMaterialGradient( MATERIAL *matInc, MATERIAL *startMat,
  315. MATERIAL *endMat, int transCount );
  316. extern void ss_TransitionMaterial( MATERIAL *transMat, MATERIAL *transMatInc );
  317. // color
  318. extern void ss_HsvToRgb(float h, float s, float v, RGBA *color );
  319. // clear
  320. extern int ss_RectWipeClear( int width, int height, int repCount );
  321. extern int ss_DigitalDissolveClear( int width, int height, int size );
  322. // utility
  323. extern void ss_RandInit( void );
  324. extern int ss_iRand( int max );
  325. extern int ss_iRand2( int min, int max );
  326. extern FLOAT ss_fRand( FLOAT min, FLOAT max );
  327. extern BOOL ss_ChangeDisplaySettings( int width, int height, int bitDepth );
  328. extern void ss_QueryDisplaySettings( void );
  329. extern void ss_QueryOSVersion( void );
  330. extern void ss_QueryGLVersion( void );
  331. extern BOOL ss_fOnWin95( void );
  332. extern BOOL ss_fOnNT35( void );
  333. extern BOOL ss_fOnGL11( void );
  334. extern BOOL ss_fPreviewMode( void );
  335. extern BOOL ss_fFullScreenMode( void );
  336. extern BOOL ss_fWindowMode( void );
  337. extern BOOL ss_fConfigMode( void );
  338. extern BOOL ss_RedrawDesktop( void );
  339. // texture file processing
  340. extern int ss_LoadBMPTextureFile( LPCTSTR pszBmpfile, TEXTURE *pTex );
  341. extern int ss_LoadTextureFile( TEXFILE *texFile, TEXTURE *pTex );
  342. extern int ss_LoadTextureResource( TEX_RES *pTexRes, TEXTURE *pTex );
  343. extern BOOL ss_CopyTexture( TEXTURE *pTexDst, TEXTURE *pTexSrc );
  344. extern BOOL ss_SetTextureTransparency( TEXTURE *pTex, float alpha, BOOL bSet );
  345. extern void ss_DisableTextureErrorMsgs();
  346. extern void ss_SetTexture( TEXTURE *pTex );
  347. extern void ss_SetTexturePalette( TEXTURE *pTex, int index );
  348. extern void ss_DeleteTexture( TEXTURE *pTex );
  349. extern BOOL ss_LoadTextureResourceStrings();
  350. extern BOOL ss_DIBImageLoad(PVOID pvFile, TEXTURE *ptex);
  351. extern BOOL ss_RGBImageLoad(PVOID pvFile, TEXTURE *ptex);
  352. extern BOOL ss_A8ImageLoad(PVOID pvFile, TEXTURE *ptex);
  353. extern BOOL ss_VerifyTextureFile( TEXFILE *ptf );
  354. extern BOOL ss_SelectTextureFile( HWND hDlg, TEXFILE *ptf );
  355. extern void ss_GetDefaultBmpFile( LPTSTR pszBmpFile );
  356. extern void ss_InitAutoTexture( TEX_POINT2D *pTexRep );
  357. // texture objects
  358. extern BOOL ss_TextureObjectsEnabled( void );
  359. // Paletted texture support
  360. extern BOOL ss_PalettedTextureEnabled(void);
  361. extern BOOL ss_QueryPalettedTextureEXT(void);
  362. // math functions
  363. extern POINT3D ss_ptZero;
  364. extern void ss_xformPoint(POINT3D *ptOut, POINT3D *ptIn, MATRIX *);
  365. extern void ss_xformNorm(POINT3D *ptOut, POINT3D *ptIn, MATRIX *);
  366. extern void ss_matrixIdent(MATRIX *);
  367. extern void ss_matrixRotate(MATRIX *m, double xTheta, double yTheta, double zTheta);
  368. extern void ss_matrixTranslate(MATRIX *, double xTrans, double yTrans, double zTrans);
  369. extern void ss_matrixMult( MATRIX *m1, MATRIX *m2, MATRIX *m3 );
  370. extern void ss_calcNorm(POINT3D *norm, POINT3D *p1, POINT3D *p2, POINT3D *p3);
  371. extern void ss_normalizeNorm(POINT3D *);
  372. extern void ss_normalizeNorms(POINT3D *, ULONG);
  373. // registry functions
  374. extern BOOL ss_RegistrySetup( HINSTANCE hinst, int section, int file );
  375. extern int ss_GetRegistryInt( int name, int iDefault );
  376. extern void ss_GetRegistryString( int name, LPTSTR lpDefault, LPTSTR lpDest, int bufSize );
  377. extern void ss_WriteRegistryInt( int name, int iVal );
  378. extern void ss_WriteRegistryString( int name, LPTSTR lpString );
  379. // dialog helper functions
  380. extern int ss_GetTrackbarPos( HWND hDlg, int item );
  381. extern void ss_SetupTrackbar( HWND hDlg, int item, int lo, int hi, int lineSize, int pageSize, int pos );
  382. extern BOOL gbTextureObjects; // from texture.c
  383. #ifdef __cplusplus
  384. }
  385. #endif
  386. #endif // __sscommon_h__