John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer
|
| 2 | //
|
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame^] | 3 | // Copyright(c) 2005-2012 TransGaming Inc.
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 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 dx_Device_hpp
|
| 13 | #define dx_Device_hpp
|
| 14 |
|
| 15 | #include "Unknown.hpp"
|
| 16 | #include "Renderer/Renderer.hpp"
|
| 17 |
|
| 18 | namespace gl
|
| 19 | {
|
| 20 | class Texture;
|
| 21 | }
|
| 22 |
|
| 23 | namespace gl
|
| 24 | {
|
| 25 | class Image;
|
| 26 |
|
| 27 | enum PrimitiveType
|
| 28 | {
|
| 29 | DRAW_POINTLIST,
|
| 30 | DRAW_LINELIST,
|
| 31 | DRAW_LINESTRIP,
|
| 32 | DRAW_LINELOOP,
|
| 33 | DRAW_TRIANGLELIST,
|
| 34 | DRAW_TRIANGLESTRIP,
|
| 35 | DRAW_TRIANGLEFAN
|
| 36 | };
|
| 37 |
|
| 38 | struct Viewport
|
| 39 | {
|
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame^] | 40 | int x0;
|
| 41 | int y0;
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 42 | unsigned int width;
|
| 43 | unsigned int height;
|
| 44 | float minZ;
|
| 45 | float maxZ;
|
| 46 | };
|
| 47 |
|
| 48 | class Device : public Unknown, public sw::Renderer
|
| 49 | {
|
| 50 | public:
|
| 51 | explicit Device(sw::Context *context);
|
| 52 |
|
| 53 | virtual ~Device();
|
| 54 |
|
| 55 | virtual void clearColor(unsigned int color, unsigned int rgbaMask);
|
| 56 | virtual void clearDepth(float z);
|
| 57 | virtual void clearStencil(unsigned int stencil, unsigned int mask);
|
| 58 | virtual Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
|
| 59 | virtual Image *createOffscreenPlainSurface(unsigned int width, unsigned int height, sw::Format format);
|
| 60 | virtual Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
|
| 61 | virtual void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize);
|
| 62 | virtual void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount);
|
| 63 | virtual Image *getDepthStencilSurface();
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 64 | virtual void setDepthStencilSurface(Image *newDepthStencil);
|
| 65 | virtual void setPixelShader(sw::PixelShader *shader);
|
| 66 | virtual void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
|
| 67 | virtual void setScissorEnable(bool enable);
|
| 68 | virtual void setRenderTarget(Image *renderTarget);
|
| 69 | virtual void setScissorRect(const sw::Rect &rect);
|
| 70 | virtual void setVertexShader(sw::VertexShader *shader);
|
| 71 | virtual void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
|
| 72 | virtual void setViewport(const Viewport &viewport);
|
| 73 |
|
| 74 | virtual bool stretchRect(Image *sourceSurface, const sw::Rect *sourceRect, Image *destSurface, const sw::Rect *destRect, bool filter);
|
| 75 | virtual bool updateSurface(Image *sourceSurface, const sw::Rect *sourceRect, Image *destinationSurface, const POINT *destPoint);
|
| 76 | virtual void finish();
|
| 77 |
|
| 78 | private:
|
| 79 | sw::Context *const context;
|
| 80 |
|
| 81 | bool bindResources();
|
| 82 | void bindShaderConstants();
|
| 83 | bool bindViewport(); // Also adjusts for scissoring
|
| 84 |
|
| 85 | bool validRectangle(const sw::Rect *rect, Image *surface);
|
| 86 |
|
| 87 | Viewport viewport;
|
| 88 | sw::Rect scissorRect;
|
| 89 | bool scissorEnable;
|
| 90 |
|
| 91 | sw::PixelShader *pixelShader;
|
| 92 | sw::VertexShader *vertexShader;
|
| 93 |
|
| 94 | bool pixelShaderDirty;
|
| 95 | int pixelShaderConstantsFDirty;
|
| 96 | bool vertexShaderDirty;
|
| 97 | int vertexShaderConstantsFDirty;
|
| 98 |
|
| 99 | float pixelShaderConstantF[224][4];
|
| 100 | float vertexShaderConstantF[256][4];
|
| 101 |
|
| 102 | Image *renderTarget;
|
| 103 | Image *depthStencil;
|
| 104 | };
|
| 105 | }
|
| 106 |
|
| 107 | extern "C"
|
| 108 | {
|
| 109 | gl::Device *createDevice();
|
| 110 | }
|
| 111 |
|
| 112 | #endif // dx_Device_hpp
|