Home | History | Annotate | Download | only in gl
      1 #ifndef _GL4CSHADERVIEWPORTLAYERARRAYTESTS_HPP
      2 #define _GL4CSHADERVIEWPORTLAYERARRAYTESTS_HPP
      3 /*-------------------------------------------------------------------------
      4  * OpenGL Conformance Test Suite
      5  * -----------------------------
      6  *
      7  * Copyright (c) 2017 The Khronos Group Inc.
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  */ /*!
     22  * \file
     23  * \brief
     24  */ /*-------------------------------------------------------------------*/
     25 
     26 /**
     27  */ /*!
     28  * \file  gl4cShaderViewportLayerArrayTests.hpp
     29  * \brief Conformance tests for the ARB_shader_viewport_layer_array functionality.
     30  */ /*-------------------------------------------------------------------*/
     31 
     32 #include "glcTestCase.hpp"
     33 #include "gluDrawUtil.hpp"
     34 #include "gluShaderProgram.hpp"
     35 #include "glwFunctions.hpp"
     36 #include "tcuVector.hpp"
     37 
     38 #include <string>
     39 
     40 namespace gl4cts
     41 {
     42 
     43 class ShaderViewportLayerArrayUtils
     44 {
     45 public:
     46 	enum ViewportOffset
     47 	{
     48 		OFFSET_VERTEX		= 1,
     49 		OFFSET_TESSELLATION = 2,
     50 		OFFSET_GEOMETRY		= 3
     51 	};
     52 
     53 	class ShaderPipeline
     54 	{
     55 	private:
     56 		glu::ShaderProgram* m_program;
     57 
     58 		bool		   m_hasTessellationShader;
     59 		bool		   m_hasGeometryShader;
     60 		ViewportOffset m_viewportLayerOffset;
     61 		std::string	m_varName;
     62 
     63 		std::string m_vs;
     64 		std::string m_tcs;
     65 		std::string m_tes;
     66 		std::string m_gs;
     67 		std::string m_fs;
     68 
     69 		void adaptShaderToPipeline(std::string& shader, const std::string& varKey, const std::string& vsVersion,
     70 								   const std::string& tesVersion, const std::string& gsVersion);
     71 		void adaptShaderToPipeline(std::string& shader, const std::string& varKey, int value);
     72 		void adaptShaderToPipeline(std::string& shader, const std::string& varKey, const std::string& value);
     73 
     74 	public:
     75 		ShaderPipeline(bool tesselletionShader, bool geometryShader, int maxViewports, const std::string& varName);
     76 		~ShaderPipeline();
     77 
     78 		void create(const glu::RenderContext& context);
     79 		void use(const glu::RenderContext& context);
     80 
     81 		inline glu::ShaderProgram* getShaderProgram() const
     82 		{
     83 			return m_program;
     84 		}
     85 		inline bool hasTessellationShader() const
     86 		{
     87 			return m_hasTessellationShader;
     88 		}
     89 		inline ViewportOffset getViewportLayerOffset() const
     90 		{
     91 			return m_viewportLayerOffset;
     92 		}
     93 		inline std::string getVarName() const
     94 		{
     95 			return m_varName;
     96 		}
     97 	};
     98 
     99 	static void renderQuad(const glu::RenderContext& context, ShaderPipeline& shaderPipeline, int viewportLayerIndex,
    100 						   tcu::Vec4 color);
    101 
    102 	static bool validateColor(tcu::Vec4 testedColor, tcu::Vec4 desiredColor);
    103 };
    104 
    105 /** Test verifies functionality of defining viewport by changing value of gl_ViewportIndex in
    106 	Vertex, Tessellation and Geometry shaders, it also verifies if final viewport is defined
    107 	by last stage in the shader's pipeline
    108 **/
    109 class ShaderViewportIndexTestCase : public deqp::TestCase
    110 {
    111 private:
    112 	/* Private methods */
    113 	glw::GLint createMaxViewports();
    114 
    115 	/* Private members*/
    116 	bool													   m_isExtensionSupported;
    117 	std::vector<tcu::Vec4>									   m_viewportData;
    118 	std::vector<ShaderViewportLayerArrayUtils::ShaderPipeline> m_shaderPipelines;
    119 	int														   m_maxViewports;
    120 	int														   m_currentViewport;
    121 
    122 	typedef std::vector<ShaderViewportLayerArrayUtils::ShaderPipeline>::iterator ShaderPipelineIter;
    123 
    124 public:
    125 	/* Public methods */
    126 	ShaderViewportIndexTestCase(deqp::Context& context);
    127 
    128 	void init();
    129 	void deinit();
    130 
    131 	tcu::TestNode::IterateResult iterate();
    132 };
    133 
    134 class ShaderLayerFramebufferTestCaseBase : public deqp::TestCase
    135 {
    136 protected:
    137 	/* Protected methods */
    138 	virtual void createFBO() = 0;
    139 	virtual void deleteFBO() = 0;
    140 
    141 	/* Protected members*/
    142 	const int m_layersNum;
    143 	const int m_fboSize;
    144 
    145 	bool													   m_isExtensionSupported;
    146 	std::vector<ShaderViewportLayerArrayUtils::ShaderPipeline> m_shaderPipelines;
    147 	deUint32												   m_texture;
    148 	std::vector<deUint32>									   m_fbos;
    149 	deUint32												   m_mainFbo;
    150 	int														   m_currentLayer;
    151 
    152 	typedef std::vector<ShaderViewportLayerArrayUtils::ShaderPipeline>::iterator ShaderPipelineIter;
    153 
    154 public:
    155 	/* Public methods */
    156 	ShaderLayerFramebufferTestCaseBase(deqp::Context& context, const char* name, const char* description, bool layered);
    157 
    158 	void init();
    159 	void deinit();
    160 
    161 	tcu::TestNode::IterateResult iterate();
    162 };
    163 
    164 /** Test verifies functionality of defining rendering layer by changing value of gl_Layer in
    165 	Vertex, Tessellation and Geometry shaders, it also verifies if final layer is defined
    166 	by last stage in the shader's pipeline
    167 **/
    168 class ShaderLayerFramebufferLayeredTestCase : public ShaderLayerFramebufferTestCaseBase
    169 {
    170 private:
    171 	/* Private methods */
    172 	void createFBO();
    173 	void deleteFBO();
    174 
    175 public:
    176 	/* Public methods */
    177 	ShaderLayerFramebufferLayeredTestCase(deqp::Context& context);
    178 };
    179 
    180 /** Test verifies that defining rendering layer by changing value of gl_Layer in
    181 	Vertex, Tessellation and Geometry shaders has no effect if framebuffer is not layered
    182 **/
    183 class ShaderLayerFramebufferNonLayeredTestCase : public ShaderLayerFramebufferTestCaseBase
    184 {
    185 private:
    186 	/* Private methods */
    187 	void createFBO();
    188 	void deleteFBO();
    189 
    190 public:
    191 	/* Public methods */
    192 	ShaderLayerFramebufferNonLayeredTestCase(deqp::Context& context);
    193 };
    194 
    195 /** Test group which encapsulates all ARB_shader_viewport_layer_array conformance tests */
    196 class ShaderViewportLayerArray : public deqp::TestCaseGroup
    197 {
    198 public:
    199 	/* Public methods */
    200 	ShaderViewportLayerArray(deqp::Context& context);
    201 
    202 	void init();
    203 
    204 private:
    205 	ShaderViewportLayerArray(const ShaderViewportLayerArray& other);
    206 	ShaderViewportLayerArray& operator=(const ShaderViewportLayerArray& other);
    207 };
    208 
    209 } /* glcts namespace */
    210 
    211 #endif // _GL4CSHADERVIEWPORTLAYERARRAYTESTS_HPP
    212