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.

205 lines
6.8 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <commctrl.h>
  5. #include <memory.h>
  6. #include <gl/gl.h>
  7. #include "buffers.h"
  8. #include "hugetest.h"
  9. #include "resource.h"
  10. #include "ui_huge.h"
  11. #include "macros.h"
  12. void InitBD(BUFFERDATA *pbd)
  13. {
  14. bzero(pbd,sizeof(BUFFERDATA));
  15. BEGINstring(pbd, "buffer");
  16. ENDstring(pbd, "buffer");
  17. pbd->uiClear = 0;
  18. pbd->cColorBits = 8; // # of bits of color per pixel
  19. pbd->fClearColor[0] = 1.0;
  20. pbd->fClearColor[1] = 1.0;
  21. pbd->fClearColor[2] = 1.0;
  22. pbd->fClearColor[3] = 0.0;
  23. pbd->cDepthBits = 16; // # of bits in z-buffer
  24. pbd->bDepthTestEnable = FALSE;
  25. pbd->iDepthFunction = LESS;
  26. pbd->bStencilEnable = FALSE;
  27. pbd->bAccumEnable = FALSE;
  28. pbd->iShadeModel = FLAT;
  29. pbd->bNormalize = FALSE;
  30. pbd->bAutoNormal = FALSE;
  31. }
  32. void buffers_init(const BUFFERDATA bd)
  33. {
  34. switch (bd.iShadeModel) {
  35. case SMOOTH: glShadeModel(GL_SMOOTH); break; // 0
  36. case FLAT: glShadeModel(GL_FLAT); break; // 1
  37. }
  38. GL_EnableOrDisable(bd.bNormalize, GL_NORMALIZE);
  39. GL_EnableOrDisable(bd.bAutoNormal, GL_AUTO_NORMAL);
  40. if (bd.bDepthTestEnable) {
  41. glEnable(GL_DEPTH_TEST);
  42. switch (bd.iDepthFunction) {
  43. case 0: glDepthFunc(GL_NEVER); break;
  44. case 1: glDepthFunc(GL_ALWAYS); break;
  45. case 2: glDepthFunc(GL_LESS); break;
  46. case 3: glDepthFunc(GL_LEQUAL); break;
  47. case 4: glDepthFunc(GL_EQUAL); break;
  48. case 5: glDepthFunc(GL_GEQUAL); break;
  49. case 6: glDepthFunc(GL_GREATER); break;
  50. case 7: glDepthFunc(GL_NOTEQUAL); break;
  51. }
  52. } else {
  53. glDisable(GL_DEPTH_TEST);
  54. }
  55. if (bd.bStencilEnable) {
  56. glEnable(GL_STENCIL_TEST);
  57. } else {
  58. glDisable(GL_STENCIL_TEST);
  59. }
  60. }
  61. #ifndef NO_UI_IN_CNFG
  62. void buffers_SetDisplayFromData(HWND hDlg, const BUFFERDATA *pbd)
  63. {
  64. CheckDlgButton(hDlg,B_IDC_CLEAR_COLOR,
  65. (pbd->uiClear&GL_COLOR_BUFFER_BIT)?1:0);
  66. CheckDlgButton(hDlg,B_IDC_CLEAR_DEPTH,
  67. (pbd->uiClear&GL_DEPTH_BUFFER_BIT)?1:0);
  68. CheckDlgButton(hDlg,B_IDC_CLEAR_STENCIL,
  69. (pbd->uiClear&GL_STENCIL_BUFFER_BIT)?1:0);
  70. CheckDlgButton(hDlg,B_IDC_CLEAR_ACCUM,
  71. (pbd->uiClear&GL_ACCUM_BUFFER_BIT)?1:0);
  72. SetDlgItemInt(hDlg,B_IDC_COLORBITS,pbd->cColorBits,FALSE);
  73. SetDlgFloatString(hDlg, B_IDC_COLOR1, pbd->fClearColor[0]);
  74. SetDlgFloatString(hDlg, B_IDC_COLOR2, pbd->fClearColor[1]);
  75. SetDlgFloatString(hDlg, B_IDC_COLOR3, pbd->fClearColor[2]);
  76. SetDlgFloatString(hDlg, B_IDC_COLOR4, pbd->fClearColor[3]);
  77. SetDlgItemInt (hDlg, B_IDC_DEPTHBITS, pbd->cDepthBits,FALSE);
  78. CheckDlgButton (hDlg, B_IDC_ENABLE_DEPTH, pbd->bDepthTestEnable?1:0);
  79. CB_DlgSetSelect(hDlg, B_IDC_DEPTH_FUNC, pbd->iDepthFunction);
  80. CheckDlgButton(hDlg, B_IDC_ENABLE_STENCIL, pbd->bStencilEnable?1:0);
  81. CB_DlgSetSelect(hDlg, B_IDC_SHADE_MODEL, pbd->iShadeModel);
  82. CheckDlgButton(hDlg, B_IDC_NORMALIZE, pbd->bNormalize?1:0);
  83. CheckDlgButton(hDlg, B_IDC_AUTO_NORMAL, pbd->bAutoNormal?1:0);
  84. }
  85. void buffers_GetDataFromDisplay(HWND hDlg, BUFFERDATA *pbd)
  86. {
  87. pbd->uiClear = 0;
  88. pbd->uiClear |= (IsDlgButtonChecked(hDlg,B_IDC_CLEAR_COLOR)
  89. ? GL_COLOR_BUFFER_BIT : 0);
  90. pbd->uiClear |= (IsDlgButtonChecked(hDlg,B_IDC_CLEAR_DEPTH)
  91. ? GL_DEPTH_BUFFER_BIT : 0);
  92. pbd->uiClear |= (IsDlgButtonChecked(hDlg,B_IDC_CLEAR_STENCIL)
  93. ? GL_STENCIL_BUFFER_BIT : 0);
  94. pbd->uiClear |= (IsDlgButtonChecked(hDlg,B_IDC_CLEAR_ACCUM)
  95. ? GL_ACCUM_BUFFER_BIT : 0);
  96. pbd->cColorBits = GetDlgItemInt(hDlg, B_IDC_COLORBITS, NULL, FALSE);
  97. pbd->fClearColor[0] = GetDlgFloatString(hDlg, B_IDC_COLOR1);
  98. pbd->fClearColor[1] = GetDlgFloatString(hDlg, B_IDC_COLOR2);
  99. pbd->fClearColor[2] = GetDlgFloatString(hDlg, B_IDC_COLOR3);
  100. pbd->fClearColor[3] = GetDlgFloatString(hDlg, B_IDC_COLOR4);
  101. pbd->cDepthBits = GetDlgItemInt(hDlg, B_IDC_DEPTHBITS, NULL, FALSE);
  102. pbd->bDepthTestEnable = (BOOL) IsDlgButtonChecked(hDlg,B_IDC_ENABLE_DEPTH);
  103. pbd->iDepthFunction = CB_DlgGetSelect(hDlg, B_IDC_DEPTH_FUNC);
  104. pbd->bStencilEnable = (BOOL) IsDlgButtonChecked(hDlg,B_IDC_ENABLE_STENCIL);
  105. pbd->iShadeModel = CB_DlgGetSelect(hDlg, B_IDC_SHADE_MODEL);
  106. pbd->bNormalize = (BOOL) IsDlgButtonChecked(hDlg,B_IDC_NORMALIZE);
  107. pbd->bAutoNormal = (BOOL) IsDlgButtonChecked(hDlg,B_IDC_AUTO_NORMAL);
  108. }
  109. BOOL CALLBACK hugeBufferDlgProc(HWND hDlg, UINT msg,
  110. WPARAM wParam, LPARAM lParam)
  111. {
  112. static BUFFERDATA *pbd = NULL;
  113. switch (msg)
  114. {
  115. case WM_INITDIALOG:
  116. pbd = (BUFFERDATA*) (((PROPSHEETPAGE*)lParam)->lParam);
  117. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Never");
  118. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Always");
  119. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Less");
  120. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Less or Equal");
  121. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Equal");
  122. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Greater or Equal");
  123. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Greater");
  124. CB_DlgAddString(hDlg, B_IDC_DEPTH_FUNC, "Not Equal");
  125. CB_DlgAddString(hDlg, B_IDC_SHADE_MODEL, "Smooth");
  126. CB_DlgAddString(hDlg, B_IDC_SHADE_MODEL, "Flat");
  127. buffers_SetDisplayFromData(hDlg, pbd);
  128. return TRUE;
  129. case WM_COMMAND:
  130. {
  131. int iControl, iNote;
  132. iControl = LOWORD(wParam);
  133. iNote = HIWORD(wParam); // notification code for edit boxes
  134. switch (iControl)
  135. {
  136. case B_IDC_COLORBITS: // don't mess with display
  137. case B_IDC_DEPTHBITS: // while editing text
  138. case B_IDC_COLOR1:
  139. case B_IDC_COLOR2:
  140. case B_IDC_COLOR3:
  141. case B_IDC_COLOR4:
  142. if (EN_KILLFOCUS == iNote) {
  143. PropSheet_Changed(GetParent(hDlg),hDlg);
  144. VerifyEditboxFloat(hDlg,iControl);
  145. }
  146. break;
  147. default:
  148. PropSheet_Changed(GetParent(hDlg),hDlg);
  149. break;
  150. }
  151. }
  152. break;
  153. case WM_NOTIFY:
  154. {
  155. LPNMHDR pnmh = (LPNMHDR) lParam;
  156. switch (pnmh->code)
  157. {
  158. case PSN_APPLY: // user clicked on OK or Apply
  159. buffers_GetDataFromDisplay(hDlg, pbd);
  160. break;
  161. case PSN_RESET: // user clicked on Cancel
  162. break;
  163. case PSN_HELP: // user clicked help
  164. break;
  165. }
  166. }
  167. break;
  168. default:
  169. return FALSE;
  170. }
  171. return TRUE;
  172. }
  173. #else
  174. #endif // NO_UI_IN_CNFG