| 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 | void drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount); | 
|---|
| 62 | void drawPrimitive(sw::DrawType type, unsigned int primiveCount); | 
|---|
| 63 | void setPixelShader(const sw::PixelShader *shader); | 
|---|
| 64 | void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); | 
|---|
| 65 | void setScissorEnable(bool enable); | 
|---|
| 66 | void setRenderTarget(int index, egl::Image *renderTarget, unsigned int layer); | 
|---|
| 67 | void setDepthBuffer(egl::Image *depthBuffer, unsigned int layer); | 
|---|
| 68 | void setStencilBuffer(egl::Image *stencilBuffer, unsigned int layer); | 
|---|
| 69 | void setScissorRect(const sw::Rect &rect); | 
|---|
| 70 | void setVertexShader(const sw::VertexShader *shader); | 
|---|
| 71 | void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); | 
|---|
| 72 | void setViewport(const Viewport &viewport); | 
|---|
| 73 |  | 
|---|
| 74 | bool stretchRect(sw::Surface *sourceSurface, const sw::SliceRectF *sourceRect, sw::Surface *destSurface, const sw::SliceRect *destRect, unsigned char flags); | 
|---|
| 75 | bool stretchCube(sw::Surface *sourceSurface, sw::Surface *destSurface); | 
|---|
| 76 | void finish(); | 
|---|
| 77 |  | 
|---|
| 78 | static bool ClipDstRect(sw::RectF &srcRect, sw::Rect &dstRect, sw::Rect &clipRect, bool flipX = false, bool flipY = false); | 
|---|
| 79 | static bool ClipSrcRect(sw::RectF &srcRect, sw::Rect &dstRect, sw::Rect &clipRect, bool flipX = false, bool flipY = false); | 
|---|
| 80 |  | 
|---|
| 81 | private: | 
|---|
| 82 | sw::Context *const context; | 
|---|
| 83 |  | 
|---|
| 84 | bool bindResources(); | 
|---|
| 85 | void bindShaderConstants(); | 
|---|
| 86 | bool bindViewport();   // Also adjusts for scissoring | 
|---|
| 87 |  | 
|---|
| 88 | bool validRectangle(const sw::Rect *rect, sw::Surface *surface); | 
|---|
| 89 | bool validRectangle(const sw::RectF *rect, sw::Surface *surface); | 
|---|
| 90 |  | 
|---|
| 91 | 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); | 
|---|
| 92 |  | 
|---|
| 93 | Viewport viewport; | 
|---|
| 94 | sw::Rect scissorRect; | 
|---|
| 95 | bool scissorEnable; | 
|---|
| 96 |  | 
|---|
| 97 | const sw::PixelShader *pixelShader; | 
|---|
| 98 | const sw::VertexShader *vertexShader; | 
|---|
| 99 |  | 
|---|
| 100 | bool pixelShaderDirty; | 
|---|
| 101 | unsigned int pixelShaderConstantsFDirty; | 
|---|
| 102 | bool vertexShaderDirty; | 
|---|
| 103 | unsigned int vertexShaderConstantsFDirty; | 
|---|
| 104 |  | 
|---|
| 105 | float pixelShaderConstantF[sw::FRAGMENT_UNIFORM_VECTORS][4]; | 
|---|
| 106 | float vertexShaderConstantF[sw::VERTEX_UNIFORM_VECTORS][4]; | 
|---|
| 107 |  | 
|---|
| 108 | egl::Image *renderTarget[sw::RENDERTARGETS]; | 
|---|
| 109 | egl::Image *depthBuffer; | 
|---|
| 110 | egl::Image *stencilBuffer; | 
|---|
| 111 | }; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | #endif   // gl_Device_hpp | 
|---|
| 115 |  | 
|---|