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 gl 21 { 22 class Image; 23 class Texture; 24 25 enum PrimitiveType 26 { 27 DRAW_POINTLIST, 28 DRAW_LINELIST, 29 DRAW_LINESTRIP, 30 DRAW_LINELOOP, 31 DRAW_TRIANGLELIST, 32 DRAW_TRIANGLESTRIP, 33 DRAW_TRIANGLEFAN, 34 DRAW_QUADLIST 35 }; 36 37 struct Viewport 38 { 39 int x0; 40 int y0; 41 unsigned int width; 42 unsigned int height; 43 float minZ; 44 float maxZ; 45 }; 46 47 class Device : public sw::Renderer 48 { 49 public: 50 explicit Device(sw::Context *context); 51 52 virtual ~Device(); 53 54 virtual void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask); 55 virtual void clearDepth(float z); 56 virtual void clearStencil(unsigned int stencil, unsigned int mask); 57 virtual Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); 58 virtual Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable); 59 virtual void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize); 60 virtual void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount); 61 virtual void setDepthStencilSurface(Image *newDepthStencil); 62 virtual void setPixelShader(sw::PixelShader *shader); 63 virtual void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); 64 virtual void setScissorEnable(bool enable); 65 virtual void setRenderTarget(int index, Image *renderTarget); 66 virtual void setScissorRect(const sw::Rect &rect); 67 virtual void setVertexShader(sw::VertexShader *shader); 68 virtual void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); 69 virtual void setViewport(const Viewport &viewport); 70 71 virtual bool stretchRect(Image *sourceSurface, const sw::SliceRect *sourceRect, Image *destSurface, const sw::SliceRect *destRect, bool filter); 72 virtual void finish(); 73 74 private: 75 sw::Context *const context; 76 77 bool bindResources(); 78 void bindShaderConstants(); 79 bool bindViewport(); // Also adjusts for scissoring 80 81 bool validRectangle(const sw::Rect *rect, Image *surface); 82 83 Viewport viewport; 84 sw::Rect scissorRect; 85 bool scissorEnable; 86 87 sw::PixelShader *pixelShader; 88 sw::VertexShader *vertexShader; 89 90 bool pixelShaderDirty; 91 unsigned int pixelShaderConstantsFDirty; 92 bool vertexShaderDirty; 93 unsigned int vertexShaderConstantsFDirty; 94 95 float pixelShaderConstantF[sw::FRAGMENT_UNIFORM_VECTORS][4]; 96 float vertexShaderConstantF[sw::VERTEX_UNIFORM_VECTORS][4]; 97 98 Image *renderTarget; 99 Image *depthStencil; 100 }; 101 } 102 103 #endif // gl_Device_hpp 104