Home | History | Annotate | Download | only in angle_tests
      1 #include "ANGLETest.h"
      2 #include "EGLWindow.h"
      3 #include "OSWindow.h"
      4 
      5 OSWindow *ANGLETest::mOSWindow = NULL;
      6 
      7 ANGLETest::ANGLETest()
      8     : mEGLWindow(NULL)
      9 {
     10     mEGLWindow = new EGLWindow(1280, 720, 2, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE);
     11 }
     12 
     13 void ANGLETest::SetUp()
     14 {
     15     ResizeWindow(mEGLWindow->getWidth(), mEGLWindow->getHeight());
     16     if (!createEGLContext())
     17     {
     18         FAIL() << "egl context creation failed.";
     19     }
     20 }
     21 
     22 void ANGLETest::TearDown()
     23 {
     24     swapBuffers();
     25     mOSWindow->messageLoop();
     26 
     27     if (!destroyEGLContext())
     28     {
     29         FAIL() << "egl context destruction failed.";
     30     }
     31 
     32     // Check for quit message
     33     Event myEvent;
     34     while (mOSWindow->popEvent(&myEvent))
     35     {
     36         if (myEvent.Type == Event::EVENT_CLOSED)
     37         {
     38             exit(0);
     39         }
     40     }
     41 }
     42 
     43 void ANGLETest::swapBuffers()
     44 {
     45     mEGLWindow->swap();
     46 }
     47 
     48 void ANGLETest::drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth)
     49 {
     50     GLint positionLocation = glGetAttribLocation(program, positionAttribName.c_str());
     51 
     52     glUseProgram(program);
     53 
     54     const GLfloat vertices[] =
     55     {
     56         -1.0f,  1.0f, quadDepth,
     57         -1.0f, -1.0f, quadDepth,
     58          1.0f, -1.0f, quadDepth,
     59 
     60         -1.0f,  1.0f, quadDepth,
     61          1.0f, -1.0f, quadDepth,
     62          1.0f,  1.0f, quadDepth,
     63     };
     64 
     65     glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
     66     glEnableVertexAttribArray(positionLocation);
     67 
     68     glDrawArrays(GL_TRIANGLES, 0, 6);
     69 
     70     glDisableVertexAttribArray(positionLocation);
     71     glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
     72 
     73     glUseProgram(0);
     74 }
     75 
     76 GLuint ANGLETest::compileShader(GLenum type, const std::string &source)
     77 {
     78     GLuint shader = glCreateShader(type);
     79 
     80     const char *sourceArray[1] = { source.c_str() };
     81     glShaderSource(shader, 1, sourceArray, NULL);
     82     glCompileShader(shader);
     83 
     84     GLint compileResult;
     85     glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
     86 
     87     if (compileResult == 0)
     88     {
     89         GLint infoLogLength;
     90         glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
     91 
     92         std::vector<GLchar> infoLog(infoLogLength);
     93         glGetShaderInfoLog(shader, infoLog.size(), NULL, infoLog.data());
     94 
     95         std::cerr << "shader compilation failed: " << infoLog.data();
     96 
     97         glDeleteShader(shader);
     98         shader = 0;
     99     }
    100 
    101     return shader;
    102 }
    103 
    104 bool ANGLETest::extensionEnabled(const std::string &extName)
    105 {
    106     const char* extString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
    107     return strstr(extString, extName.c_str()) != NULL;
    108 }
    109 
    110 void ANGLETest::setClientVersion(int clientVersion)
    111 {
    112     mEGLWindow->setClientVersion(clientVersion);
    113 }
    114 
    115 void ANGLETest::setWindowWidth(int width)
    116 {
    117     mEGLWindow->setWidth(width);
    118 }
    119 
    120 void ANGLETest::setWindowHeight(int height)
    121 {
    122     mEGLWindow->setHeight(height);
    123 }
    124 
    125 void ANGLETest::setConfigRedBits(int bits)
    126 {
    127     mEGLWindow->setConfigRedBits(bits);
    128 }
    129 
    130 void ANGLETest::setConfigGreenBits(int bits)
    131 {
    132     mEGLWindow->setConfigGreenBits(bits);
    133 }
    134 
    135 void ANGLETest::setConfigBlueBits(int bits)
    136 {
    137     mEGLWindow->setConfigBlueBits(bits);
    138 }
    139 
    140 void ANGLETest::setConfigAlphaBits(int bits)
    141 {
    142     mEGLWindow->setConfigAlphaBits(bits);
    143 }
    144 
    145 void ANGLETest::setConfigDepthBits(int bits)
    146 {
    147     mEGLWindow->setConfigDepthBits(bits);
    148 }
    149 
    150 void ANGLETest::setConfigStencilBits(int bits)
    151 {
    152     mEGLWindow->setConfigStencilBits(bits);
    153 }
    154 
    155 void ANGLETest::setMultisampleEnabled(bool enabled)
    156 {
    157     mEGLWindow->setMultisample(enabled);
    158 }
    159 
    160 int ANGLETest::getClientVersion() const
    161 {
    162     return mEGLWindow->getClientVersion();
    163 }
    164 
    165 int ANGLETest::getWindowWidth() const
    166 {
    167     return mEGLWindow->getWidth();
    168 }
    169 
    170 int ANGLETest::getWindowHeight() const
    171 {
    172     return mEGLWindow->getHeight();
    173 }
    174 
    175 bool ANGLETest::isMultisampleEnabled() const
    176 {
    177     return mEGLWindow->isMultisample();
    178 }
    179 
    180 bool ANGLETest::createEGLContext()
    181 {
    182     return mEGLWindow->initializeGL(mOSWindow);
    183 }
    184 
    185 bool ANGLETest::destroyEGLContext()
    186 {
    187     mEGLWindow->destroyGL();
    188     return true;
    189 }
    190 
    191 bool ANGLETest::InitTestWindow()
    192 {
    193     mOSWindow = CreateOSWindow();
    194     if (!mOSWindow->initialize("ANGLE_TEST", 128, 128))
    195     {
    196         return false;
    197     }
    198 
    199     mOSWindow->setVisible(true);
    200 
    201     return true;
    202 }
    203 
    204 bool ANGLETest::DestroyTestWindow()
    205 {
    206     if (mOSWindow)
    207     {
    208         mOSWindow->destroy();
    209         delete mOSWindow;
    210         mOSWindow = NULL;
    211     }
    212 
    213     return true;
    214 }
    215 
    216 bool ANGLETest::ResizeWindow(int width, int height)
    217 {
    218     return mOSWindow->resize(width, height);
    219 }
    220 
    221 void ANGLETestEnvironment::SetUp()
    222 {
    223     if (!ANGLETest::InitTestWindow())
    224     {
    225         FAIL() << "Failed to create ANGLE test window.";
    226     }
    227 }
    228 
    229 void ANGLETestEnvironment::TearDown()
    230 {
    231     ANGLETest::DestroyTestWindow();
    232 }
    233