Device.hpp revision fe7a45ceacce06e70a0dc6005873354d1af4c54e
1// SwiftShader Software Renderer
2//
3// Copyright(c) 2005-2012 TransGaming Inc.
4//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#ifndef gl_Device_hpp
13#define gl_Device_hpp
14
15#include "Renderer/Renderer.hpp"
16
17namespace gl
18{
19	class Image;
20	class Texture;
21
22	enum PrimitiveType
23	{
24		DRAW_POINTLIST,
25		DRAW_LINELIST,
26		DRAW_LINESTRIP,
27		DRAW_LINELOOP,
28		DRAW_TRIANGLELIST,
29		DRAW_TRIANGLESTRIP,
30		DRAW_TRIANGLEFAN,
31        DRAW_QUADLIST
32	};
33
34	struct Viewport
35	{
36		int x0;
37		int y0;
38		unsigned int width;
39		unsigned int height;
40		float minZ;
41		float maxZ;
42	};
43
44	class Device : public sw::Renderer
45	{
46	public:
47		explicit Device(sw::Context *context);
48
49		virtual ~Device();
50
51		virtual void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask);
52		virtual void clearDepth(float z);
53		virtual void clearStencil(unsigned int stencil, unsigned int mask);
54		virtual Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
55		virtual Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
56		virtual void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize);
57		virtual void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount);
58		virtual void setDepthStencilSurface(Image *newDepthStencil);
59		virtual void setPixelShader(sw::PixelShader *shader);
60		virtual void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
61		virtual void setScissorEnable(bool enable);
62		virtual void setRenderTarget(int index, Image *renderTarget);
63		virtual void setScissorRect(const sw::Rect &rect);
64		virtual void setVertexShader(sw::VertexShader *shader);
65		virtual void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
66		virtual void setViewport(const Viewport &viewport);
67
68		virtual bool stretchRect(Image *sourceSurface, const sw::SliceRect *sourceRect, Image *destSurface, const sw::SliceRect *destRect, bool filter);
69		virtual void finish();
70
71	private:
72		sw::Context *const context;
73
74		bool bindResources();
75		void bindShaderConstants();
76		bool bindViewport();   // Also adjusts for scissoring
77
78		bool validRectangle(const sw::Rect *rect, Image *surface);
79
80		Viewport viewport;
81		sw::Rect scissorRect;
82		bool scissorEnable;
83
84		sw::PixelShader *pixelShader;
85		sw::VertexShader *vertexShader;
86
87		bool pixelShaderDirty;
88		unsigned int pixelShaderConstantsFDirty;
89		bool vertexShaderDirty;
90		unsigned int vertexShaderConstantsFDirty;
91
92		float pixelShaderConstantF[FRAGMENT_UNIFORM_VECTORS][4];
93		float vertexShaderConstantF[VERTEX_UNIFORM_VECTORS][4];
94
95		Image *renderTarget;
96		Image *depthStencil;
97	};
98}
99
100#endif   // gl_Device_hpp
101