Home | History | Annotate | Download | only in libGLESv2
      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 gl_Device_hpp
     16 #define gl_Device_hpp
     17 
     18 #include "Renderer/Renderer.hpp"
     19 
     20 namespace egl
     21 {
     22 	class Image;
     23 }
     24 
     25 namespace es2
     26 {
     27 	class Texture;
     28 
     29 	struct Viewport
     30 	{
     31 		int x0;
     32 		int y0;
     33 		unsigned int width;
     34 		unsigned int height;
     35 		float minZ;
     36 		float maxZ;
     37 	};
     38 
     39 	class Device : public sw::Renderer
     40 	{
     41 	public:
     42 		enum : unsigned char
     43 		{
     44 			USE_FILTER = 0x01,
     45 			COLOR_BUFFER = 0x02,
     46 			DEPTH_BUFFER = 0x04,
     47 			STENCIL_BUFFER = 0x08,
     48 			ALL_BUFFERS = COLOR_BUFFER | DEPTH_BUFFER | STENCIL_BUFFER,
     49 		};
     50 
     51 		explicit Device(sw::Context *context);
     52 
     53 		virtual ~Device();
     54 
     55 		void *operator new(size_t size);
     56 		void operator delete(void * mem);
     57 
     58 		void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask);
     59 		void clearDepth(float z);
     60 		void clearStencil(unsigned int stencil, unsigned int mask);
     61 		egl::Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
     62 		egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
     63 		void drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount);
     64 		void drawPrimitive(sw::DrawType type, unsigned int primiveCount);
     65 		void setPixelShader(const sw::PixelShader *shader);
     66 		void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
     67 		void setScissorEnable(bool enable);
     68 		void setRenderTarget(int index, egl::Image *renderTarget);
     69 		void setDepthBuffer(egl::Image *depthBuffer);
     70 		void setStencilBuffer(egl::Image *stencilBuffer);
     71 		void setScissorRect(const sw::Rect &rect);
     72 		void setVertexShader(const sw::VertexShader *shader);
     73 		void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
     74 		void setViewport(const Viewport &viewport);
     75 
     76 		bool stretchRect(sw::Surface *sourceSurface, const sw::SliceRect *sourceRect, sw::Surface *destSurface, const sw::SliceRect *destRect, unsigned char flags);
     77 		bool stretchCube(sw::Surface *sourceSurface, sw::Surface *destSurface);
     78 		void finish();
     79 
     80 	private:
     81 		sw::Context *const context;
     82 
     83 		bool bindResources();
     84 		void bindShaderConstants();
     85 		bool bindViewport();   // Also adjusts for scissoring
     86 
     87 		bool validRectangle(const sw::Rect *rect, sw::Surface *surface);
     88 
     89 		void copyBuffer(sw::byte *sourceBuffer, sw::byte *destBuffer, unsigned int width, unsigned int height, unsigned int sourcePitch, unsigned int destPitch, unsigned int bytes, bool flipX, bool flipY);
     90 
     91 		Viewport viewport;
     92 		sw::Rect scissorRect;
     93 		bool scissorEnable;
     94 
     95 		const sw::PixelShader *pixelShader;
     96 		const sw::VertexShader *vertexShader;
     97 
     98 		bool pixelShaderDirty;
     99 		unsigned int pixelShaderConstantsFDirty;
    100 		bool vertexShaderDirty;
    101 		unsigned int vertexShaderConstantsFDirty;
    102 
    103 		float pixelShaderConstantF[sw::FRAGMENT_UNIFORM_VECTORS][4];
    104 		float vertexShaderConstantF[sw::VERTEX_UNIFORM_VECTORS][4];
    105 
    106 		egl::Image *renderTarget[sw::RENDERTARGETS];
    107 		egl::Image *depthBuffer;
    108 		egl::Image *stencilBuffer;
    109 	};
    110 }
    111 
    112 #endif   // gl_Device_hpp
    113