csplugincommon/rendermanager/hdrexposure_luminance.h
00001 /* 00002 Copyright (C) 2008-2009 by Frank Richter 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSPLUGINCOMMON_RENDERMANAGER_HDREXPOSURE_LUMINANCE_H__ 00020 #define __CS_CSPLUGINCOMMON_RENDERMANAGER_HDREXPOSURE_LUMINANCE_H__ 00021 00022 #include "csgfx/textureformatstrings.h" 00023 #include "csplugincommon/rendermanager/hdrhelper.h" 00024 #include "csplugincommon/rendermanager/posteffects.h" 00025 00026 namespace CS 00027 { 00028 namespace RenderManager 00029 { 00030 namespace HDR 00031 { 00032 namespace Luminance 00033 { 00034 class CS_CRYSTALSPACE_EXPORT BaseHierarchical 00035 { 00036 protected: 00037 float colorScale; 00038 00039 const char* intermediateTextureFormat; 00040 CS::StructuredTextureFormat readbackFmt; 00041 PostEffectManager::Layer* measureLayer; 00042 HDRHelper* hdr; 00043 csRef<iGraphics3D> graphics3D; 00044 csRef<iShaderVarStringSet> svNameStringSet; 00045 csRef<iShaderManager> shaderManager; 00046 00047 csRef<iShader> computeShader1; 00048 csRef<iShader> computeShaderN; 00049 struct LuminanceComputeStage 00050 { 00051 csArray<PostEffectManager::Layer*> layers; 00052 csRef<csShaderVariable> svInput; 00053 csRef<csShaderVariable> svWeightCoeff; 00054 csRef<iTextureHandle> target; 00055 int targetW, targetH; 00056 00057 LuminanceComputeStage() {} 00058 }; 00059 csArray<LuminanceComputeStage> computeStages; 00060 PostEffectManager computeFX; 00061 00062 int lastTargetW, lastTargetH; 00063 csRef<iDataBuffer> lastData; 00064 int lastW, lastH; 00065 iTextureHandle* lastMeasureTex; 00066 float lastColorScale; 00067 00068 BaseHierarchical (const char* intermediateTextureFormat, 00069 const char* outputTextureFormat) : colorScale (1.0f), 00070 intermediateTextureFormat (intermediateTextureFormat), 00071 readbackFmt (CS::TextureFormatStrings::ConvertStructured (outputTextureFormat)), 00072 measureLayer (0), hdr (0), lastMeasureTex (0) {} 00073 00075 void Initialize (iObjectRegistry* objReg, 00076 HDRHelper& hdr, 00077 const char* firstShader, const char* stepShader); 00078 00080 csPtr<iDataBuffer> GetResultData (RenderTreeBase& renderTree, 00081 iView* view, int& resultW, int& resultH, float& usedColorScale); 00082 private: 00083 bool FindBlockSize (iShader* shader, size_t pticket, 00084 const CS::Graphics::RenderMeshModes& modes, 00085 const csShaderVariableStack& stack, 00086 int maxW, int maxH, 00087 int& blockSizeX, int& blockSizeY, csRef<iShader>* usedShader); 00088 bool SetupStage (LuminanceComputeStage& stage, 00089 int inputW, int inputH, int minSize, iTextureHandle* inputTex, 00090 iShader* computeShader); 00091 void SetupStages (int targetW, int targetH, 00092 iTextureHandle* measureTex); 00093 public: 00094 float GetColorScale () const { return colorScale; } 00095 void SetColorScale (float scale) { colorScale = scale; } 00096 }; 00097 00098 class CS_CRYSTALSPACE_EXPORT Average : public BaseHierarchical 00099 { 00100 public: 00101 Average() : BaseHierarchical ("argb8", "argb8") {} 00102 00103 void Initialize (iObjectRegistry* objReg, 00104 HDRHelper& hdr); 00105 00106 bool ComputeLuminance (RenderTreeBase& renderTree, iView* view, 00107 float& averageLuminance, float& maxLuminance, 00108 float& usedColorScale); 00109 }; 00110 00111 class CS_CRYSTALSPACE_EXPORT LogAverage : public BaseHierarchical 00112 { 00113 public: 00114 LogAverage() : BaseHierarchical ("bgr16_f", 00115 "abgr32_f") // This format allows fast readback (at least on NV) 00116 {} 00117 00118 void Initialize (iObjectRegistry* objReg, 00119 HDRHelper& hdr); 00120 00121 bool ComputeLuminance (RenderTreeBase& renderTree, iView* view, 00122 float& averageLuminance, float& maxLuminance, float& maxComp, 00123 float& usedColorScale); 00124 }; 00125 } // namespace Luminance 00126 } // namespace HDR 00127 } // namespace RenderManager 00128 } // namespace CS 00129 00130 #endif // __CS_CSPLUGINCOMMON_RENDERMANAGER_HDREXPOSURE_LUMINANCE_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1