blob: c483b96eb08e928faf58a09d0b5c038e4ad11a76 [file] [log] [blame]
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -06001// 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#ifndef XGLTESTFRAMEWORK_H
24#define XGLTESTFRAMEWORK_H
25
26#include "gtest-1.7.0/include/gtest/gtest.h"
27#include "xglimage.h"
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060028#include "ShaderLang.h"
29#include "GLSL450Lib.h"
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060030
31#include <stdlib.h>
32#include <stdio.h>
33#include <stdbool.h>
34#include <string.h>
35#include <iostream>
36#include <fstream>
37#include <list>
38using namespace std;
39
40class XglTestImageRecord
41{
42public:
43 XglTestImageRecord();
44 XglTestImageRecord(const XglTestImageRecord &);
45 ~XglTestImageRecord();
46 XglTestImageRecord &operator=(const XglTestImageRecord &rhs);
47 int operator==(const XglTestImageRecord &rhs) const;
48 int operator<(const XglTestImageRecord &rhs) const;
49
50 string m_title;
51 void *m_data;
52 unsigned m_data_size;
53 int m_width;
54 int m_height;
55};
56
57class XglTestFramework : public ::testing::Test
58{
59public:
60 XglTestFramework();
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060061 ~XglTestFramework();
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060062
63 static void InitArgs(int *argc, char *argv[]);
64 static void Finish();
65
66 void WritePPM( const char *basename, XglImage *image );
67 void Show(const char *comment, XglImage *image);
68 void RecordImage(XglImage *image);
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060069 bool GLSLtoBIL(const XGL_PIPELINE_SHADER_STAGE shader_type,
70 const char *pshader,
71 std::vector<unsigned int> &bil);
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060072
73private:
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060074 int m_compile_options;
75 int m_num_shader_strings;
76 TBuiltInResource Resources;
77 int ShInitialize();
78 void SetMessageOptions(EShMessages& messages);
79 void ProcessConfigFile();
80 char** ReadFileData(const char* fileName);
81 void FreeFileData(char** data);
82 EShLanguage FindLanguage(const std::string& name);
83 EShLanguage FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type);
84 std::string ConfigFile;
85 bool SetConfigFile(const std::string& name);
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060086 static void Reshape( int w, int h );
87 static void Display();
88 static void Key(unsigned char key, int x, int y);
89 static void SpecialKey( int key, int x, int y );
90
91 void InitGLUT(int w, int h);
92
93 static bool m_show_images;
94 static bool m_save_images;
95 static std::list<XglTestImageRecord> m_images;
96 static std::list<XglTestImageRecord>::iterator m_display_image;
97 static int m_display_image_idx;
98
99 bool m_glut_initialized;
100 static int m_window;
101 static int m_width; // Window width
102 static int m_height; // Window height
103};
104
105#endif // XGLTESTFRAMEWORK_H