Courtney Goeltzenleuchter | 1ed1d1a | 2014-09-01 13:56:09 -0600 | [diff] [blame] | 1 | // XGL tests |
| 2 | // |
| 3 | // Copyright (C) 2014 LunarG, Inc. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | // copy of this software and associated documentation files (the "Software"), |
| 7 | // to deal in the Software without restriction, including without limitation |
| 8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | // and/or sell copies of the Software, and to permit persons to whom the |
| 10 | // Software is furnished to do so, subject to the following conditions: |
| 11 | // |
| 12 | // The above copyright notice and this permission notice shall be included |
| 13 | // in all copies or substantial portions of the Software. |
| 14 | // |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | // DEALINGS IN THE SOFTWARE. |
| 22 | |
| 23 | |
| 24 | // Display image results from tests |
| 25 | |
| 26 | #include "displayengine.h" |
| 27 | #include "test_common.h" |
| 28 | |
| 29 | DisplayEngine::DisplayEngine() |
| 30 | { |
| 31 | m_enable = false; |
| 32 | } |
| 33 | |
| 34 | void DisplayEngine::Init(bool enable, int w, int h) |
| 35 | { |
| 36 | m_enable = enable; |
| 37 | m_width = w; |
| 38 | m_height = h; |
| 39 | |
| 40 | if (!m_enable) return; // Do nothing except save info if not enabled |
| 41 | |
| 42 | glutInitWindowSize(w, h); |
| 43 | |
| 44 | glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); |
| 45 | glutCreateWindow(NULL); |
| 46 | Reshape(w, h); |
| 47 | } |
| 48 | |
| 49 | void DisplayEngine::Reshape( int w, int h ) |
| 50 | { |
| 51 | m_width = w; |
| 52 | m_height = h; |
| 53 | |
| 54 | if (!m_enable) return; // Do nothing except save info if not enabled |
| 55 | |
| 56 | glutReshapeWindow(m_width, m_height); |
| 57 | |
| 58 | glViewport( 0, 0, m_width, m_height ); |
| 59 | glMatrixMode( GL_PROJECTION ); |
| 60 | glLoadIdentity(); |
| 61 | glOrtho( 0.0, m_width, 0.0, m_height, 0.0, 2.0 ); |
| 62 | glMatrixMode( GL_MODELVIEW ); |
| 63 | glLoadIdentity(); |
| 64 | |
| 65 | // glScissor(width/4, height/4, width/2, height/2); |
| 66 | } |
| 67 | |
| 68 | void DisplayEngine::Display(XGL_IMAGE image, XGL_GPU_MEMORY image_mem) |
| 69 | { |
| 70 | XGL_RESULT err; |
| 71 | |
| 72 | const XGL_IMAGE_SUBRESOURCE sr = { |
| 73 | XGL_IMAGE_ASPECT_COLOR, 0, 0 |
| 74 | }; |
| 75 | XGL_SUBRESOURCE_LAYOUT sr_layout; |
| 76 | XGL_UINT data_size; |
| 77 | |
| 78 | if (!m_enable) return; // Do nothing except save info if not enabled |
| 79 | |
| 80 | err = xglGetImageSubresourceInfo( image, &sr, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, |
| 81 | &data_size, &sr_layout); |
| 82 | ASSERT_XGL_SUCCESS( err ); |
| 83 | ASSERT_EQ(data_size, sizeof(sr_layout)); |
| 84 | |
| 85 | const char *ptr; |
| 86 | |
| 87 | err = xglMapMemory( image_mem, 0, (XGL_VOID **) &ptr ); |
| 88 | ASSERT_XGL_SUCCESS( err ); |
| 89 | |
| 90 | ptr += sr_layout.offset; |
| 91 | |
| 92 | glClearColor(0, 0, 0, 0); |
| 93 | glClear( GL_COLOR_BUFFER_BIT); |
| 94 | glRasterPos3f(0, 0, 0); |
| 95 | glBitmap(0, 0, 0, 0, 0, 0, NULL); |
| 96 | glDrawPixels(m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, ptr); |
| 97 | |
| 98 | glutSwapBuffers(); |
| 99 | |
| 100 | err = xglUnmapMemory( image_mem ); |
| 101 | ASSERT_XGL_SUCCESS( err ); |
| 102 | } |