• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef sw_VertexShader_hpp
16 #define sw_VertexShader_hpp
17 
18 #include "Shader.hpp"
19 #include "Main/Config.hpp"
20 
21 namespace sw
22 {
23 	class VertexShader : public Shader
24 	{
25 	public:
26 		enum AttribType : unsigned char
27 		{
28 			ATTRIBTYPE_FLOAT,
29 			ATTRIBTYPE_INT,
30 			ATTRIBTYPE_UINT,
31 
32 			ATTRIBTYPE_LAST = ATTRIBTYPE_UINT
33 		};
34 
35 		explicit VertexShader(const VertexShader *vs = 0);
36 		explicit VertexShader(const unsigned long *token);
37 
38 		virtual ~VertexShader();
39 
40 		static int validate(const unsigned long *const token);   // Returns number of instructions if valid
41 		bool containsTextureSampling() const;
42 
43 		void setInput(int inputIdx, const Semantic& semantic, AttribType attribType = ATTRIBTYPE_FLOAT);
44 		void setOutput(int outputIdx, int nbComponents, const Semantic& semantic);
45 		void setPositionRegister(int posReg);
46 		void setPointSizeRegister(int ptSizeReg);
declareInstanceId()47 		void declareInstanceId() { instanceIdDeclared = true; }
declareVertexId()48 		void declareVertexId() { vertexIdDeclared = true; }
49 
50 		const Semantic& getInput(int inputIdx) const;
51 		const Semantic& getOutput(int outputIdx, int component) const;
52 		AttribType getAttribType(int inputIndex) const;
getPositionRegister() const53 		int getPositionRegister() const { return positionRegister; }
getPointSizeRegister() const54 		int getPointSizeRegister() const { return pointSizeRegister; }
isInstanceIdDeclared() const55 		bool isInstanceIdDeclared() const { return instanceIdDeclared; }
isVertexIdDeclared() const56 		bool isVertexIdDeclared() const { return vertexIdDeclared; }
57 
58 	private:
59 		void analyze();
60 		void analyzeInput();
61 		void analyzeOutput();
62 		void analyzeTextureSampling();
63 
64 		Semantic input[MAX_VERTEX_INPUTS];
65 		Semantic output[MAX_VERTEX_OUTPUTS][4];
66 
67 		AttribType attribType[MAX_VERTEX_INPUTS];
68 
69 		int positionRegister;
70 		int pointSizeRegister;
71 
72 		bool instanceIdDeclared;
73 		bool vertexIdDeclared;
74 		bool textureSampling;
75 	};
76 }
77 
78 #endif   // sw_VertexShader_hpp
79