| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 new BoolHandler(&separate_alpha_blend_enable_, | 644 new BoolHandler(&separate_alpha_blend_enable_, |
| 645 &alpha_blend_settings_changed_)); | 645 &alpha_blend_settings_changed_)); |
| 646 AddStateHandler(State::kSourceBlendAlphaFunctionParamName, | 646 AddStateHandler(State::kSourceBlendAlphaFunctionParamName, |
| 647 new BlendFunctionHandler(&blend_function_[SRC][ALPHA])); | 647 new BlendFunctionHandler(&blend_function_[SRC][ALPHA])); |
| 648 AddStateHandler(State::kDestinationBlendAlphaFunctionParamName, | 648 AddStateHandler(State::kDestinationBlendAlphaFunctionParamName, |
| 649 new BlendFunctionHandler(&blend_function_[DST][ALPHA])); | 649 new BlendFunctionHandler(&blend_function_[DST][ALPHA])); |
| 650 AddStateHandler(State::kBlendAlphaEquationParamName, | 650 AddStateHandler(State::kBlendAlphaEquationParamName, |
| 651 new BlendEquationHandler(&blend_equation_[ALPHA])); | 651 new BlendEquationHandler(&blend_equation_[ALPHA])); |
| 652 } | 652 } |
| 653 | 653 |
| 654 RendererGL *RendererGL::current_renderer_ = NULL; | |
| 655 | |
| 656 RendererGL::~RendererGL() { | 654 RendererGL::~RendererGL() { |
| 657 Destroy(); | 655 Destroy(); |
| 658 } | 656 } |
| 659 | 657 |
| 660 // platform neutral initialization code | 658 // platform neutral initialization code |
| 661 // | 659 // |
| 662 Renderer::InitStatus RendererGL::InitCommonGL() { | 660 Renderer::InitStatus RendererGL::InitCommonGL() { |
| 663 GLenum glew_error = glewInit(); | 661 GLenum glew_error = glewInit(); |
| 664 if (glew_error != GLEW_OK) { | 662 if (glew_error != GLEW_OK) { |
| 665 DLOG(ERROR) << "Unable to initialise GLEW : " | 663 DLOG(ERROR) << "Unable to initialise GLEW : " |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 display_ = NULL; | 1092 display_ = NULL; |
| 1095 window_ = 0; | 1093 window_ = 0; |
| 1096 } | 1094 } |
| 1097 return init_status; | 1095 return init_status; |
| 1098 } | 1096 } |
| 1099 | 1097 |
| 1100 void RendererGL::Destroy() { | 1098 void RendererGL::Destroy() { |
| 1101 DestroyCommonGL(); | 1099 DestroyCommonGL(); |
| 1102 if (display_) { | 1100 if (display_) { |
| 1103 ::glXMakeCurrent(display_, 0, 0); | 1101 ::glXMakeCurrent(display_, 0, 0); |
| 1104 current_renderer_ = NULL; | |
| 1105 if (context_) { | 1102 if (context_) { |
| 1106 ::glXDestroyContext(display_, context_); | 1103 ::glXDestroyContext(display_, context_); |
| 1107 context_ = 0; | 1104 context_ = 0; |
| 1108 } | 1105 } |
| 1109 display_ = NULL; | 1106 display_ = NULL; |
| 1110 window_ = 0; | 1107 window_ = 0; |
| 1111 } | 1108 } |
| 1112 } | 1109 } |
| 1113 | 1110 |
| 1114 #endif | 1111 #endif |
| 1115 | 1112 |
| 1116 bool RendererGL::MakeCurrent() { | 1113 bool RendererGL::MakeCurrent() { |
| 1117 #ifdef OS_WIN | 1114 #ifdef OS_WIN |
| 1118 if (!device_context_ || !gl_context_) return false; | 1115 if (!device_context_ || !gl_context_) return false; |
| 1119 bool result = ::wglMakeCurrent(device_context_, gl_context_) != 0; | 1116 bool result = ::wglMakeCurrent(device_context_, gl_context_) != 0; |
| 1120 if (result) current_renderer_ = this; | |
| 1121 return result; | 1117 return result; |
| 1122 #endif | 1118 #endif |
| 1123 #ifdef OS_MACOSX | 1119 #ifdef OS_MACOSX |
| 1124 if (mac_cgl_context_ != NULL) { | 1120 if (mac_cgl_context_ != NULL) { |
| 1125 ::CGLSetCurrentContext(mac_cgl_context_); | 1121 ::CGLSetCurrentContext(mac_cgl_context_); |
| 1126 current_renderer_ = this; | |
| 1127 return true; | 1122 return true; |
| 1128 } else if (mac_agl_context_ != NULL) { | 1123 } else if (mac_agl_context_ != NULL) { |
| 1129 ::aglSetCurrentContext(mac_agl_context_); | 1124 ::aglSetCurrentContext(mac_agl_context_); |
| 1130 current_renderer_ = this; | |
| 1131 return true; | 1125 return true; |
| 1132 } else { | 1126 } else { |
| 1133 return false; | 1127 return false; |
| 1134 } | 1128 } |
| 1135 #endif | 1129 #endif |
| 1136 #ifdef OS_LINUX | 1130 #ifdef OS_LINUX |
| 1137 if (context_ != NULL) { | 1131 if (context_ != NULL) { |
| 1138 bool result = ::glXMakeCurrent(display_, window_, context_) == True; | 1132 bool result = ::glXMakeCurrent(display_, window_, context_) == True; |
| 1139 if (result) current_renderer_ = this; | |
| 1140 return result; | 1133 return result; |
| 1141 } else { | 1134 } else { |
| 1142 return false; | 1135 return false; |
| 1143 } | 1136 } |
| 1144 #endif | 1137 #endif |
| 1145 } | 1138 } |
| 1146 | 1139 |
| 1147 void RendererGL::PlatformSpecificClear(const Float4 &color, | 1140 void RendererGL::PlatformSpecificClear(const Float4 &color, |
| 1148 bool color_flag, | 1141 bool color_flag, |
| 1149 float depth, | 1142 float depth, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 ::glDepthRange(min_z, max_z); | 1205 ::glDepthRange(min_z, max_z); |
| 1213 } | 1206 } |
| 1214 | 1207 |
| 1215 // Resizes the viewport. | 1208 // Resizes the viewport. |
| 1216 void RendererGL::Resize(int width, int height) { | 1209 void RendererGL::Resize(int width, int height) { |
| 1217 MakeCurrentLazy(); | 1210 MakeCurrentLazy(); |
| 1218 SetClientSize(width, height); | 1211 SetClientSize(width, height); |
| 1219 CHECK_GL_ERROR(); | 1212 CHECK_GL_ERROR(); |
| 1220 } | 1213 } |
| 1221 | 1214 |
| 1222 bool RendererGL::SetFullscreen(bool fullscreen, | 1215 bool RendererGL::GoFullscreen(const DisplayWindow& display, |
| 1223 const DisplayWindow& display, | 1216 int mode_id) { |
| 1224 int mode_id) { | 1217 fullscreen_ = true; |
| 1225 if (fullscreen != fullscreen_) { | 1218 return true; |
| 1226 fullscreen_ = fullscreen; | 1219 } |
| 1227 } | 1220 |
| 1221 bool RendererGL::CancelFullscreen(const DisplayWindow& display, |
| 1222 int width, int height) { |
| 1223 fullscreen_ = false; |
| 1228 return true; | 1224 return true; |
| 1229 } | 1225 } |
| 1230 | 1226 |
| 1231 bool RendererGL::PlatformSpecificStartRendering() { | 1227 bool RendererGL::PlatformSpecificStartRendering() { |
| 1232 DLOG_FIRST_N(INFO, 10) << "RendererGL StartRendering"; | 1228 DLOG_FIRST_N(INFO, 10) << "RendererGL StartRendering"; |
| 1233 MakeCurrentLazy(); | 1229 MakeCurrentLazy(); |
| 1234 | 1230 |
| 1235 // Currently always returns true. | 1231 // Currently always returns true. |
| 1236 // Should be modified if current behavior changes. | 1232 // Should be modified if current behavior changes. |
| 1237 CHECK_GL_ERROR(); | 1233 CHECK_GL_ERROR(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 return swizzle_table; | 1498 return swizzle_table; |
| 1503 } | 1499 } |
| 1504 | 1500 |
| 1505 // This is a factory function for creating Renderer objects. Since | 1501 // This is a factory function for creating Renderer objects. Since |
| 1506 // we're implementing GL, we only ever return a GL renderer. | 1502 // we're implementing GL, we only ever return a GL renderer. |
| 1507 Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { | 1503 Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { |
| 1508 return RendererGL::CreateDefault(service_locator); | 1504 return RendererGL::CreateDefault(service_locator); |
| 1509 } | 1505 } |
| 1510 | 1506 |
| 1511 } // namespace o3d | 1507 } // namespace o3d |
| OLD | NEW |