Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 | explicit Device(sw::Context *context); |
| 43 | |
| 44 | virtual ~Device(); |
| 45 | |
Alexis Hetu | 81519cf | 2016-09-08 13:59:50 -0400 | [diff] [blame] | 46 | void *operator new(size_t size); |
| 47 | void operator delete(void * mem); |
| 48 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 49 | void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask); |
| 50 | void clearDepth(float z); |
| 51 | void clearStencil(unsigned int stencil, unsigned int mask); |
| 52 | egl::Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); |
| 53 | egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable); |
| 54 | void drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount); |
| 55 | void drawPrimitive(sw::DrawType type, unsigned int primiveCount); |
| 56 | void setPixelShader(sw::PixelShader *shader); |
| 57 | void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); |
| 58 | void setScissorEnable(bool enable); |
| 59 | void setRenderTarget(int index, egl::Image *renderTarget); |
| 60 | void setDepthBuffer(egl::Image *depthBuffer); |
| 61 | void setStencilBuffer(egl::Image *stencilBuffer); |
| 62 | void setScissorRect(const sw::Rect &rect); |
| 63 | void setVertexShader(sw::VertexShader *shader); |
| 64 | void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); |
| 65 | void setViewport(const Viewport &viewport); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 66 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 67 | bool stretchRect(sw::Surface *sourceSurface, const sw::SliceRect *sourceRect, sw::Surface *destSurface, const sw::SliceRect *destRect, bool filter); |
| 68 | bool stretchCube(sw::Surface *sourceSurface, sw::Surface *destSurface); |
| 69 | void finish(); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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, sw::Surface *surface); |
| 79 | |
| 80 | 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); |
| 81 | |
| 82 | Viewport viewport; |
| 83 | sw::Rect scissorRect; |
| 84 | bool scissorEnable; |
| 85 | |
| 86 | sw::PixelShader *pixelShader; |
| 87 | sw::VertexShader *vertexShader; |
| 88 | |
| 89 | bool pixelShaderDirty; |
| 90 | unsigned int pixelShaderConstantsFDirty; |
| 91 | bool vertexShaderDirty; |
| 92 | unsigned int vertexShaderConstantsFDirty; |
| 93 | |
| 94 | float pixelShaderConstantF[sw::FRAGMENT_UNIFORM_VECTORS][4]; |
| 95 | float vertexShaderConstantF[sw::VERTEX_UNIFORM_VECTORS][4]; |
| 96 | |
| 97 | egl::Image *renderTarget[sw::RENDERTARGETS]; |
| 98 | egl::Image *depthBuffer; |
| 99 | egl::Image *stencilBuffer; |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | #endif // gl_Device_hpp |