| 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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 height)); | 1560 height)); |
| 1561 } | 1561 } |
| 1562 | 1562 |
| 1563 // Saves a png screenshot 'file_name.png'. | 1563 // Saves a png screenshot 'file_name.png'. |
| 1564 // Returns true on success and false on failure. | 1564 // Returns true on success and false on failure. |
| 1565 bool RendererGL::SaveScreen(const String& file_name) { | 1565 bool RendererGL::SaveScreen(const String& file_name) { |
| 1566 #ifdef TESTING | 1566 #ifdef TESTING |
| 1567 MakeCurrentLazy(); | 1567 MakeCurrentLazy(); |
| 1568 Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); | 1568 Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); |
| 1569 bitmap->Allocate(Texture::ARGB8, width(), height(), 1, false); | 1569 bitmap->Allocate(Texture::ARGB8, width(), height(), 1, false); |
| 1570 |
| 1571 // Note: glReadPixels caputres the alpha component of the frame buffer as well |
| 1572 // as the color components, the graphics pipeline usually ignores the alpha |
| 1573 // channel when drawing to the screen, so unless the alpha is 1, the png image |
| 1574 // generated might exhibit suprise translucency. |
| 1570 ::glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, | 1575 ::glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, |
| 1571 bitmap->image_data()); | 1576 bitmap->image_data()); |
| 1572 bool result = bitmap->SaveToPNGFile((file_name + ".png").c_str()); | 1577 bool result = bitmap->SaveToPNGFile((file_name + ".png").c_str()); |
| 1573 if (!result) { | 1578 if (!result) { |
| 1574 O3D_ERROR(service_locator()) | 1579 O3D_ERROR(service_locator()) |
| 1575 << "Failed to save screen into " << file_name; | 1580 << "Failed to save screen into " << file_name; |
| 1576 } | 1581 } |
| 1577 return result; | 1582 return result; |
| 1578 #else | 1583 #else |
| 1579 // Not a test build, always return false. | 1584 // Not a test build, always return false. |
| 1580 return false; | 1585 return false; |
| 1581 #endif | 1586 #endif |
| 1582 } | 1587 } |
| 1583 | 1588 |
| 1584 const int* RendererGL::GetRGBAUByteNSwizzleTable() { | 1589 const int* RendererGL::GetRGBAUByteNSwizzleTable() { |
| 1585 static int swizzle_table[] = { 0, 1, 2, 3, }; | 1590 static int swizzle_table[] = { 0, 1, 2, 3, }; |
| 1586 return swizzle_table; | 1591 return swizzle_table; |
| 1587 } | 1592 } |
| 1588 | 1593 |
| 1589 // This is a factory function for creating Renderer objects. Since | 1594 // This is a factory function for creating Renderer objects. Since |
| 1590 // we're implementing GL, we only ever return a GL renderer. | 1595 // we're implementing GL, we only ever return a GL renderer. |
| 1591 Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { | 1596 Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { |
| 1592 return RendererGL::CreateDefault(service_locator); | 1597 return RendererGL::CreateDefault(service_locator); |
| 1593 } | 1598 } |
| 1594 | 1599 |
| 1595 } // namespace o3d | 1600 } // namespace o3d |
| OLD | NEW |