/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef OD_SR_TRIANGLE_RENDERER_DATA_H #define OD_SR_TRIANGLE_RENDERER_DATA_H #include #include #include "data/SrDataBuffer.h" #include "SrCameraClipper.h" struct OdSrTextureTransform { int m_transparent; OdGeQuaternion m_sPlane; OdGeQuaternion m_tPlane; OdGeQuaternion m_wPlane; double m_wComponent; inline OdGePoint3d transform(const OdGeMatrix3d& transformToEye, const OdGePoint3d& vertex) const { OdGePoint3d texCoord; texCoord.x = vertex.x * m_sPlane.w + vertex.y * m_sPlane.x + vertex.z * m_sPlane.y + m_sPlane.z; texCoord.y = vertex.x * m_tPlane.w + vertex.y * m_tPlane.x + vertex.z * m_tPlane.y + m_tPlane.z; texCoord.z = (transformToEye * vertex).z; return texCoord; } }; struct OdSrTextureParams { enum RasterImageBitDepth { kRIBDMono = 1, kRIBD16Clr = 4, kRIBD256Clr = 8, kRIBD24Bpp = 24, kRIBD32Bpp = 32 }; enum RasterImage32TransparencyType { kRI32TTDef, kRI32TT1, kRI32TT8 }; OdUInt32 rasterWidth; OdUInt32 rasterHeight; OdUInt32 rasterScanLineLength; bool bRasterTransparency = false; bool bRasterRGB = false; RasterImage32TransparencyType raster32TranspMode = kRI32TTDef; RasterImageBitDepth rasterBitDepth; OdUInt8Array rasterPalette; ODCOLORREF* pRasterPalette = nullptr; OdUInt8Array rasterScanLines; const OdUInt8* pRasterScanLines = nullptr; const OdGiRasterImage* pRasterImagePtr = nullptr; }; struct ZClipPlanes; namespace TriangleRendering { // Renderer configuration parameters - all necessary buffers and dimensions class OdSrTriangleRendererData { public: // Triangle vertex with all coordinates struct TriangleVertex { OdInt32 x, y; // Screen coordinates float u, v; // Texture coordinates (0.0-1.0) float w; //1.0 for orthographic projection TriangleVertex(); TriangleVertex(OdInt32 _x, OdInt32 _y, float _u = 0.0f, float _v = 0.0f, float _w = 1.0f); TriangleVertex(OdInt32 _x, OdInt32 _y, const OdGePoint3d& pt); }; enum RenderQuality { Regular, Low // Optimize for speed (at quality cost) }; // Rendering settings with default parameters struct RenderSettings { // Texture modes bool wrapTexture = false; // Texture wrapping (true = repeat) bool skipTransform = false; // Skip texture coordinate transformation OdUInt8 alpha = 255; // Transparency (255 = fully opaque) bool isPerspectiveProjection = false; inline bool enableZTest() const { return isPerspectiveProjection; } // Rendering modes RenderQuality qualityMode = RenderQuality::Regular; // Default constructor RenderSettings() = default; // Convenient factory methods static RenderSettings Wrapped(OdUInt8 _alpha = 255); static RenderSettings FastRender(bool _wrap = false, OdUInt8 _alpha = 255); }; public: typedef OdSrDataBuffer FrameBuffer; typedef OdSrDataBuffer TextureBuffer; struct DepthBuffer { OdUInt32 width = 0; OdUInt32 height = 0; OdUInt8* scanLines = nullptr; OdUInt32 scanLineLength = 0; DepthBuffer() = default; DepthBuffer(OdUInt32 w, OdUInt32 h, OdUInt8* sl, OdUInt32 len); }; // Clipping parameters struct ClipRegion { OdGsDCRect clipRect; OdInt32 offsetX = 0; OdInt32 offsetY = 0; OdInt32 width = 0; OdInt32 height = 0; const OdUInt8* clipMask = nullptr; ClipRegion() = default; ClipRegion(const OdGsDCRect& rect); void resetMask(); }; private: FrameBuffer m_frameBuffer; TextureBuffer m_textureBuffer; DepthBuffer m_depthBuffer; RenderSettings m_renderSettings; ODCOLORREF m_triangleColorBuffer[3]; bool m_useExternalBuffer = true; const ODCOLORREF* m_externalColorBuffer; OdUInt32 m_colorBufferLength = 0; const OdSrZClipper::ZClipPlanes& m_ZClipPlanes; ClipRegion m_clipRegion; OdSrTextureTransform m_textureTransform; OdGiRasterImage::PixelFormatInfo m_pixelFormat; ODCOLORREF* m_pRasterPalette = nullptr; public: // Default constructor OdSrTriangleRendererData(const OdSrZClipper::ZClipPlanes& zClipPlanes); // Methods for setting parameters (Builder pattern) OdSrTriangleRendererData& setFrameBuffer(OdUInt32 width, OdUInt32 height, OdUInt8* scanLines, OdUInt32 scanLineLength); OdSrTriangleRendererData& setFrameFormat(TextureFormat::BitsPerPixel bpp, TextureFormat::ColorOrder order, ODCOLORREF* pColorPalette, TextureFormat::TransparencyMode transparency); OdSrTriangleRendererData& setTextureBuffer(OdUInt32 width, OdUInt32 height, OdUInt8* scanLines, OdUInt32 scanLineLength); OdSrTriangleRendererData& setTextureFormat(TextureFormat::BitsPerPixel bpp, TextureFormat::ColorOrder order, ODCOLORREF* pColorPalette, TextureFormat::TransparencyMode transparency); OdSrTriangleRendererData& setTextureParams(const OdSrTextureParams& params); OdSrTriangleRendererData& resetTextureBuffer(); OdSrTriangleRendererData& setColorBuffer(const ODCOLORREF* pColors, OdUInt32 colorsLength); OdSrTriangleRendererData& applyFadingToColorBuffer(const ODCOLORREF* pColors, OdUInt32 colorsLength, ODCOLORREF fadeColor, OdUInt8 fadingValue); OdSrTriangleRendererData& setDepthBuffer(OdUInt32 width, OdUInt32 height, OdUInt8* scanLines, OdUInt32 scanLineLength); OdSrTriangleRendererData& setTextureTransform(const OdSrTextureTransform& transform); OdSrTriangleRendererData& setPixelFormat(const OdGiRasterImage::PixelFormatInfo& pixelFormat); OdSrTriangleRendererData& setRasterPalette(ODCOLORREF* palette); OdSrTriangleRendererData& setRenderSettings(bool wrap, bool noTransform, OdUInt8 alpha); // Getters for all parameters FrameBuffer& frameBuffer(); const FrameBuffer& frameBuffer() const; const TextureBuffer& textureBuffer() const; const DepthBuffer& depthBuffer() const; const ODCOLORREF* triangleColorBuffer(OdUInt32& colorBufferLength) const; const OdSrZClipper::ZClipPlanes& zClipPlanes() const; const RenderSettings& renderSettings() const; ClipRegion& clipRegion(); const ClipRegion& clipRegion() const; const OdGiRasterImage::PixelFormatInfo& pixelFormat() const; const OdSrTextureTransform& textureTransform() const; ODCOLORREF* rasterPalette() const; }; }; #endif // OD_SR_TRIANGLE_RENDERER_DATA_H