CmSDLGLSupport.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "CmException.h"
  2. #include "CmStringConverter.h"
  3. #include "CmSDLGLSupport.h"
  4. #include "CmSDLWindow.h"
  5. using namespace CamelotEngine;
  6. SDLGLSupport::SDLGLSupport()
  7. {
  8. SDL_Init(SDL_INIT_VIDEO);
  9. }
  10. SDLGLSupport::~SDLGLSupport()
  11. {
  12. }
  13. void SDLGLSupport::addConfig(void)
  14. {
  15. mVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL);
  16. if (mVideoModes == (SDL_Rect **)0)
  17. {
  18. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to load video modes",
  19. "SDLRenderSystem::initConfigOptions");
  20. }
  21. ConfigOption optFullScreen;
  22. ConfigOption optVideoMode;
  23. ConfigOption optFSAA;
  24. ConfigOption optRTTMode;
  25. // FS setting possiblities
  26. optFullScreen.name = "Full Screen";
  27. optFullScreen.possibleValues.push_back("Yes");
  28. optFullScreen.possibleValues.push_back("No");
  29. optFullScreen.currentValue = "Yes";
  30. optFullScreen.immutable = false;
  31. // Video mode possiblities
  32. optVideoMode.name = "Video Mode";
  33. optVideoMode.immutable = false;
  34. for (size_t i = 0; mVideoModes[i]; i++)
  35. {
  36. char szBuf[16];
  37. snprintf(szBuf, 16, "%d x %d", mVideoModes[i]->w, mVideoModes[i]->h);
  38. optVideoMode.possibleValues.push_back(szBuf);
  39. // Make the first one default
  40. if (i == 0)
  41. {
  42. optVideoMode.currentValue = szBuf;
  43. }
  44. }
  45. //FSAA possibilities
  46. optFSAA.name = "FSAA";
  47. optFSAA.possibleValues.push_back("0");
  48. optFSAA.possibleValues.push_back("2");
  49. optFSAA.possibleValues.push_back("4");
  50. optFSAA.possibleValues.push_back("6");
  51. optFSAA.currentValue = "0";
  52. optFSAA.immutable = false;
  53. optRTTMode.name = "RTT Preferred Mode";
  54. optRTTMode.possibleValues.push_back("FBO");
  55. optRTTMode.possibleValues.push_back("PBuffer");
  56. optRTTMode.possibleValues.push_back("Copy");
  57. optRTTMode.currentValue = "FBO";
  58. optRTTMode.immutable = false;
  59. mOptions[optFullScreen.name] = optFullScreen;
  60. mOptions[optVideoMode.name] = optVideoMode;
  61. mOptions[optFSAA.name] = optFSAA;
  62. mOptions[optRTTMode.name] = optRTTMode;
  63. }
  64. String SDLGLSupport::validateConfig(void)
  65. {
  66. return String("");
  67. }
  68. RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)
  69. {
  70. if (autoCreateWindow)
  71. {
  72. ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
  73. if (opt == mOptions.end())
  74. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find full screen options!", "SDLGLSupport::createWindow");
  75. bool fullscreen = (opt->second.currentValue == "Yes");
  76. opt = mOptions.find("Video Mode");
  77. if (opt == mOptions.end())
  78. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find video mode options!", "SDLGLSupport::createWindow");
  79. String val = opt->second.currentValue;
  80. String::size_type pos = val.find('x');
  81. if (pos == String::npos)
  82. OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid Video Mode provided", "SDLGLSupport::createWindow");
  83. // Parse FSAA config
  84. NameValuePairList winOptions;
  85. winOptions["title"] = windowTitle;
  86. int fsaa_x_samples = 0;
  87. opt = mOptions.find("FSAA");
  88. if(opt != mOptions.end())
  89. {
  90. winOptions["FSAA"] = opt->second.currentValue;
  91. }
  92. unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
  93. unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
  94. const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
  95. return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions);
  96. }
  97. else
  98. {
  99. // XXX What is the else?
  100. return NULL;
  101. }
  102. }
  103. RenderWindow* SDLGLSupport::newWindow(const String &name, unsigned int width, unsigned int height,
  104. bool fullScreen, const NameValuePairList *miscParams)
  105. {
  106. SDLWindow* window = new SDLWindow();
  107. window->create(name, width, height, fullScreen, miscParams);
  108. return window;
  109. }
  110. void SDLGLSupport::start()
  111. {
  112. LogManager::getSingleton().logMessage(
  113. "******************************\n"
  114. "*** Starting SDL Subsystem ***\n"
  115. "******************************");
  116. SDL_Init(SDL_INIT_VIDEO);
  117. }
  118. void SDLGLSupport::stop()
  119. {
  120. LogManager::getSingleton().logMessage(
  121. "******************************\n"
  122. "*** Stopping SDL Subsystem ***\n"
  123. "******************************");
  124. SDL_Quit();
  125. }
  126. void* SDLGLSupport::getProcAddress(const String& procname)
  127. {
  128. return SDL_GL_GetProcAddress(procname.c_str());
  129. }