mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-25 05:49:34 +00:00
Special shaders
This commit is contained in:
parent
dcf1065957
commit
c68b6b9085
|
@ -300,12 +300,14 @@
|
|||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_mupenplus|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_mupenplus|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\CombinerProgram.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\Context.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLFunctions.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerInputs.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerProgramBuilder.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerProgramImpl.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerProgramUniformFactory.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_SpecialShadersFactory.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_Utils.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Attributes.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_BufferManipulationObjectFactory.cpp" />
|
||||
|
@ -314,7 +316,7 @@
|
|||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_GLInfo.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Parameters.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Utilis.cpp" />
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Utils.cpp" />
|
||||
<ClCompile Include="..\..\src\gSP.cpp" />
|
||||
<ClCompile Include="..\..\src\Keys.cpp" />
|
||||
<ClCompile Include="..\..\src\Log.cpp" />
|
||||
|
@ -342,6 +344,7 @@
|
|||
<ClCompile Include="..\..\src\NoiseTexture.cpp" />
|
||||
<ClCompile Include="..\..\src\OGL3X\GLSLCombiner_ogl3x.cpp" />
|
||||
<ClCompile Include="..\..\src\OpenGL.cpp" />
|
||||
<ClCompile Include="..\..\src\PaletteTexture.cpp" />
|
||||
<ClCompile Include="..\..\src\Performance.cpp" />
|
||||
<ClCompile Include="..\..\src\PostProcessor.cpp" />
|
||||
<ClCompile Include="..\..\src\RDP.CPP" />
|
||||
|
@ -393,6 +396,7 @@
|
|||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_mupenplus_uniformset|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_mupenplus|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ZlutTexture.cpp" />
|
||||
<ClCompile Include="..\..\src\ZSort.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -446,6 +450,8 @@
|
|||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerProgramBuilder.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerProgramImpl.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerProgramUniformFactory.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_ShaderPart.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_SpecialShadersFactory.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_Utils.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Attributes.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_BufferManipulationObjectFactory.h" />
|
||||
|
@ -453,7 +459,7 @@
|
|||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLInfo.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utilis.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utils.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\Parameter.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\Parameters.h" />
|
||||
<ClInclude Include="..\..\src\Graphics\PixelBuffer.h" />
|
||||
|
@ -470,6 +476,7 @@
|
|||
<ClInclude Include="..\..\src\NoiseTexture.h" />
|
||||
<ClInclude Include="..\..\src\OGL3X\Shaders_ogl3x.h" />
|
||||
<ClInclude Include="..\..\src\OpenGL.h" />
|
||||
<ClInclude Include="..\..\src\PaletteTexture.h" />
|
||||
<ClInclude Include="..\..\src\Performance.h" />
|
||||
<ClInclude Include="..\..\src\PluginAPI.h" />
|
||||
<ClInclude Include="..\..\src\PostProcessor.h" />
|
||||
|
@ -502,6 +509,7 @@
|
|||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_mupenplus_uniformset|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_mupenplus|Win32'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ZlutTexture.h" />
|
||||
<ClInclude Include="..\..\src\ZSort.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -290,9 +290,6 @@
|
|||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Parameters.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Utilis.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||
</ClCompile>
|
||||
|
@ -329,6 +326,21 @@
|
|||
<ClCompile Include="..\..\src\NoiseTexture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ZlutTexture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_SpecialShadersFactory.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL\GLSL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\PaletteTexture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\opengl_Utils.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Graphics\CombinerProgram.cpp">
|
||||
<Filter>Source Files\Graphics</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\3DMath.h">
|
||||
|
@ -556,9 +568,6 @@
|
|||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.h">
|
||||
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utilis.h">
|
||||
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.h">
|
||||
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||
</ClInclude>
|
||||
|
@ -607,5 +616,20 @@
|
|||
<ClInclude Include="..\..\src\Graphics\PixelBuffer.h">
|
||||
<Filter>Header Files\Graphics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ZlutTexture.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_SpecialShadersFactory.h">
|
||||
<Filter>Header Files\Graphics\OpenGL\GLSL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\PaletteTexture.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_ShaderPart.h">
|
||||
<Filter>Header Files\Graphics\OpenGL\GLSL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utils.h">
|
||||
<Filter>Header Files\Graphics\OpenGL</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -13,7 +13,6 @@
|
|||
#include "PluginAPI.h"
|
||||
#include "RSP.h"
|
||||
#include "Graphics/Context.h"
|
||||
#include "Graphics/CombinerProgram.h"
|
||||
|
||||
static int saRGBExpanded[] =
|
||||
{
|
||||
|
@ -76,7 +75,7 @@ static int aAExpanded[] =
|
|||
void Combiner_Init() {
|
||||
CombinerInfo & cmbInfo = CombinerInfo::get();
|
||||
cmbInfo.init();
|
||||
InitShaderCombiner();
|
||||
// InitShaderCombiner();
|
||||
if (cmbInfo.getCombinersNumber() == 0) {
|
||||
cmbInfo.setPolygonMode(OGLRender::rsTexRect);
|
||||
gDP.otherMode.cycleType = G_CYC_COPY;
|
||||
|
@ -88,7 +87,7 @@ void Combiner_Init() {
|
|||
}
|
||||
|
||||
void Combiner_Destroy() {
|
||||
DestroyShaderCombiner();
|
||||
// DestroyShaderCombiner();
|
||||
CombinerInfo::get().destroy();
|
||||
}
|
||||
|
||||
|
@ -117,10 +116,16 @@ void CombinerInfo::init()
|
|||
delete cur->second;
|
||||
m_combiners.clear();
|
||||
}
|
||||
|
||||
m_shadowmapProgram.reset(gfxContext.createDepthFogShader());
|
||||
m_monochromeProgram.reset(gfxContext.createMonochromeShader());
|
||||
}
|
||||
|
||||
void CombinerInfo::destroy()
|
||||
{
|
||||
m_shadowmapProgram.reset();
|
||||
m_monochromeProgram.reset();
|
||||
|
||||
m_pCurrent = nullptr;
|
||||
if (m_bShaderCacheSupported)
|
||||
_saveShadersStorage();
|
||||
|
@ -285,6 +290,18 @@ void CombinerInfo::updateParameters()
|
|||
m_pCurrent->update(false);
|
||||
}
|
||||
|
||||
void CombinerInfo::setDepthFogCombiner()
|
||||
{
|
||||
if (m_shadowmapProgram)
|
||||
m_shadowmapProgram->activate();
|
||||
}
|
||||
|
||||
void CombinerInfo::setMonochromeCombiner()
|
||||
{
|
||||
if (m_monochromeProgram)
|
||||
m_monochromeProgram->activate();
|
||||
}
|
||||
|
||||
void CombinerInfo::setPolygonMode(OGLRender::RENDER_STATE _renderState)
|
||||
{
|
||||
switch (_renderState) {
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#define COMBINER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "GLideN64.h"
|
||||
#include "OpenGL.h"
|
||||
#include "gDP.h"
|
||||
#include "CombinerKey.h"
|
||||
#include "Graphics/CombinerProgram.h"
|
||||
#include "Graphics/ShaderProgram.h"
|
||||
|
||||
/*
|
||||
* G_SETCOMBINE: color combine modes
|
||||
|
@ -114,10 +117,6 @@ struct CombineCycle
|
|||
int sa, sb, m, a;
|
||||
};
|
||||
|
||||
namespace graphics {
|
||||
class CombinerProgram;
|
||||
}
|
||||
|
||||
class CombinerInfo
|
||||
{
|
||||
public:
|
||||
|
@ -127,6 +126,9 @@ public:
|
|||
void setCombine(u64 _mux);
|
||||
void updateParameters();
|
||||
|
||||
void setDepthFogCombiner();
|
||||
void setMonochromeCombiner();
|
||||
|
||||
graphics::CombinerProgram * getCurrent() const { return m_pCurrent; }
|
||||
bool isChanged() const {return m_bChanged;}
|
||||
bool isShaderCacheSupported() const { return m_bShaderCacheSupported; }
|
||||
|
@ -161,6 +163,9 @@ private:
|
|||
graphics::CombinerProgram * m_pCurrent;
|
||||
typedef std::map<CombinerKey, graphics::CombinerProgram *> Combiners;
|
||||
Combiners m_combiners;
|
||||
|
||||
std::unique_ptr<graphics::ShaderProgram> m_shadowmapProgram;
|
||||
std::unique_ptr<graphics::ShaderProgram> m_monochromeProgram;
|
||||
};
|
||||
|
||||
inline
|
||||
|
|
|
@ -154,8 +154,8 @@ void InitShaderCombiner();
|
|||
void DestroyShaderCombiner();
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
void SetDepthFogCombiner();
|
||||
void SetMonochromeCombiner();
|
||||
//void SetDepthFogCombiner();
|
||||
//void SetMonochromeCombiner();
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
//#define USE_TOONIFY
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include "CombinerKey.h"
|
||||
|
||||
namespace graphics {
|
||||
|
@ -6,7 +7,7 @@ namespace graphics {
|
|||
class CombinerProgram
|
||||
{
|
||||
public:
|
||||
virtual ~CombinerProgram() {};
|
||||
virtual ~CombinerProgram() {}
|
||||
virtual void activate() = 0;
|
||||
virtual void update(bool _force) = 0;
|
||||
virtual CombinerKey getKey() const = 0;
|
||||
|
@ -21,6 +22,8 @@ namespace graphics {
|
|||
|
||||
friend std::ostream & operator<< (std::ostream & _os, const CombinerProgram & _combiner);
|
||||
friend std::istream & operator>> (std::istream & _os, CombinerProgram & _combiner);
|
||||
|
||||
static void getShaderCombinerOptionsSet(std::vector<u32> & _vecOptions);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -75,12 +75,22 @@ void Context::addFrameBufferRenderTarget(const FrameBufferRenderTarget & _params
|
|||
|
||||
PixelWriteBuffer * Context::createPixelWriteBuffer(size_t _sizeInBytes)
|
||||
{
|
||||
return m_impl->createPixelWriteBuffer(_sizeInBytes);
|
||||
return m_impl->createPixelWriteBuffer(_sizeInBytes);
|
||||
}
|
||||
|
||||
CombinerProgram * Context::createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key)
|
||||
{
|
||||
return m_impl->createCombinerProgram(_color, _alpha, _key);
|
||||
return m_impl->createCombinerProgram(_color, _alpha, _key);
|
||||
}
|
||||
|
||||
ShaderProgram * Context::createDepthFogShader()
|
||||
{
|
||||
return m_impl->createDepthFogShader();
|
||||
}
|
||||
|
||||
ShaderProgram * Context::createMonochromeShader()
|
||||
{
|
||||
return m_impl->createMonochromeShader();
|
||||
}
|
||||
|
||||
bool Context::isMultisamplingSupported() const
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace graphics {
|
|||
|
||||
struct InitTextureParams {
|
||||
ObjectHandle handle;
|
||||
Parameter ImageUnit;
|
||||
u32 msaaLevel = 0;
|
||||
u32 width = 0;
|
||||
u32 height = 0;
|
||||
|
@ -45,6 +46,7 @@ namespace graphics {
|
|||
|
||||
struct UpdateTextureDataParams {
|
||||
ObjectHandle handle;
|
||||
Parameter ImageUnit;
|
||||
Parameter textureUnitIndex = Parameter(0U);
|
||||
u32 x = 0;
|
||||
u32 y = 0;
|
||||
|
@ -52,6 +54,7 @@ namespace graphics {
|
|||
u32 height = 0;
|
||||
u32 mipMapLevel = 0;
|
||||
Parameter format;
|
||||
Parameter internalFormat;
|
||||
Parameter dataType;
|
||||
const void * data = nullptr;
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <Log.h>
|
||||
#include <Config.h>
|
||||
#include "glsl_Utils.h"
|
||||
#include "glsl_ShaderPart.h"
|
||||
#include "glsl_CombinerInputs.h"
|
||||
#include "glsl_CombinerProgramImpl.h"
|
||||
#include "glsl_CombinerProgramBuilder.h"
|
||||
|
@ -1134,6 +1135,24 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class ShaderFragmentMainEnd : public ShaderPart
|
||||
{
|
||||
public:
|
||||
ShaderFragmentMainEnd(const opengl::GLInfo & _glinfo)
|
||||
{
|
||||
if (_glinfo.isGLES2) {
|
||||
m_part =
|
||||
" gl_FragColor = fragColor; \n"
|
||||
"} \n\n"
|
||||
;
|
||||
} else {
|
||||
m_part =
|
||||
"} \n\n"
|
||||
;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ShaderNoise : public ShaderPart
|
||||
{
|
||||
public:
|
||||
|
@ -1797,7 +1816,7 @@ graphics::CombinerProgram * CombinerProgramBuilder::buildCombinerProgram(Combine
|
|||
m_fragmentRenderTarget->write(ssShader);
|
||||
|
||||
// End of Main() function
|
||||
ssShader << "}" << std::endl << std::endl;
|
||||
m_shaderFragmentMainEnd->write(ssShader);
|
||||
|
||||
/* Write other functions */
|
||||
if (bUseHWLight)
|
||||
|
@ -1849,6 +1868,21 @@ graphics::CombinerProgram * CombinerProgramBuilder::buildCombinerProgram(Combine
|
|||
return new CombinerProgramImpl(_key, program, combinerInputs, std::move(uniforms));
|
||||
}
|
||||
|
||||
const ShaderPart * CombinerProgramBuilder::getVertexShaderHeader() const
|
||||
{
|
||||
return m_vertexHeader.get();
|
||||
}
|
||||
|
||||
const ShaderPart * CombinerProgramBuilder::getFragmentShaderHeader() const
|
||||
{
|
||||
return m_fragmentHeader.get();
|
||||
}
|
||||
|
||||
const ShaderPart * CombinerProgramBuilder::getFragmentShaderEnd() const
|
||||
{
|
||||
return m_shaderFragmentMainEnd.get();
|
||||
}
|
||||
|
||||
static
|
||||
GLuint _createVertexShader(ShaderPart * _header, ShaderPart * _body)
|
||||
{
|
||||
|
@ -1900,6 +1934,7 @@ CombinerProgramBuilder::CombinerProgramBuilder(const opengl::GLInfo & _glinfo)
|
|||
, m_fragmentReadTexMipmap(new ShaderFragmentReadTexMipmap(_glinfo))
|
||||
, m_fragmentCallN64Depth(new ShaderFragmentCallN64Depth(_glinfo))
|
||||
, m_fragmentRenderTarget(new ShaderFragmentRenderTarget(_glinfo))
|
||||
, m_shaderFragmentMainEnd(new ShaderFragmentMainEnd(_glinfo))
|
||||
, m_shaderNoise(new ShaderNoise(_glinfo))
|
||||
, m_shaderDither(new ShaderDither(_glinfo))
|
||||
, m_shaderWriteDepth(new ShaderWriteDepth(_glinfo))
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <Combiner.h>
|
||||
#include <Graphics/OpenGLContext/opengl_GLInfo.h>
|
||||
|
||||
|
@ -11,27 +9,23 @@ namespace graphics {
|
|||
|
||||
namespace glsl {
|
||||
|
||||
class ShaderPart;
|
||||
class CombinerProgramUniformFactory;
|
||||
|
||||
class ShaderPart
|
||||
{
|
||||
public:
|
||||
void write(std::stringstream & shader)
|
||||
{
|
||||
shader << m_part;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string m_part;
|
||||
};
|
||||
|
||||
class CombinerProgramBuilder
|
||||
{
|
||||
public:
|
||||
CombinerProgramBuilder(const opengl::GLInfo & _glinfo);
|
||||
~CombinerProgramBuilder();
|
||||
|
||||
graphics::CombinerProgram * buildCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key);
|
||||
|
||||
const ShaderPart * getVertexShaderHeader() const;
|
||||
|
||||
const ShaderPart * getFragmentShaderHeader() const;
|
||||
|
||||
const ShaderPart * getFragmentShaderEnd() const;
|
||||
|
||||
private:
|
||||
int compileCombiner(const CombinerKey & _key, Combiner & _color, Combiner & _alpha, std::string & _strShader);
|
||||
|
||||
|
@ -72,6 +66,7 @@ namespace glsl {
|
|||
ShaderPartPtr m_fragmentReadTexMipmap;
|
||||
ShaderPartPtr m_fragmentCallN64Depth;
|
||||
ShaderPartPtr m_fragmentRenderTarget;
|
||||
ShaderPartPtr m_shaderFragmentMainEnd;
|
||||
|
||||
ShaderPartPtr m_shaderNoise;
|
||||
ShaderPartPtr m_shaderDither;
|
||||
|
|
19
src/Graphics/OpenGLContext/GLSL/glsl_ShaderPart.h
Normal file
19
src/Graphics/OpenGLContext/GLSL/glsl_ShaderPart.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace glsl {
|
||||
|
||||
class ShaderPart
|
||||
{
|
||||
public:
|
||||
void write(std::stringstream & shader) const
|
||||
{
|
||||
shader << m_part;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string m_part;
|
||||
};
|
||||
|
||||
}
|
198
src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp
Normal file
198
src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
#include <Types.h>
|
||||
#include <Graphics/ShaderProgram.h>
|
||||
#include <Graphics/Parameters.h>
|
||||
#include <PaletteTexture.h>
|
||||
#include <ZlutTexture.h>
|
||||
#include <gDP.h>
|
||||
#include "glsl_SpecialShadersFactory.h"
|
||||
#include "glsl_ShaderPart.h"
|
||||
#include "glsl_Utils.h"
|
||||
#include "Textures.h"
|
||||
|
||||
namespace glsl {
|
||||
|
||||
/*---------------ShadowMapShader-------------*/
|
||||
|
||||
class VertexShaderRectNocolor : public ShaderPart
|
||||
{
|
||||
public:
|
||||
VertexShaderRectNocolor()
|
||||
{
|
||||
m_part =
|
||||
"IN highp vec4 aRectPosition; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_Position = aRectPosition; \n"
|
||||
"} \n"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class ShadowMapFragmentShader : public ShaderPart
|
||||
{
|
||||
public:
|
||||
ShadowMapFragmentShader()
|
||||
{
|
||||
m_part =
|
||||
#ifndef GLESX
|
||||
"layout(binding = 0, r16ui) uniform readonly uimage2D uZlutImage;\n"
|
||||
"layout(binding = 1, r16ui) uniform readonly uimage2D uTlutImage;\n"
|
||||
#else
|
||||
"layout(binding = 0, r32ui) highp uniform readonly uimage2D uZlutImage;\n"
|
||||
"layout(binding = 1, r32ui) highp uniform readonly uimage2D uTlutImage;\n"
|
||||
#endif
|
||||
"layout(binding = 0) uniform sampler2D uDepthImage; \n"
|
||||
"uniform lowp vec4 uFogColor; \n"
|
||||
"OUT lowp vec4 fragColor; \n"
|
||||
"lowp float get_alpha() \n"
|
||||
"{ \n"
|
||||
" mediump ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" highp float bufZ = texelFetch(uDepthImage,coord, 0).r; \n"
|
||||
" highp int iZ = bufZ > 0.999 ? 262143 : int(floor(bufZ * 262143.0));\n"
|
||||
" mediump int y0 = clamp(iZ/512, 0, 511); \n"
|
||||
" mediump int x0 = iZ - 512*y0; \n"
|
||||
" highp uint iN64z = imageLoad(uZlutImage,ivec2(x0,y0)).r; \n"
|
||||
" highp float n64z = clamp(float(iN64z)/65532.0, 0.0, 1.0);\n"
|
||||
" highp int index = min(255, int(n64z*255.0)); \n"
|
||||
" highp uint iAlpha = imageLoad(uTlutImage,ivec2(index,0)).r;\n"
|
||||
" return float(iAlpha>>8)/255.0; \n"
|
||||
"} \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" fragColor = vec4(uFogColor.rgb, get_alpha()); \n"
|
||||
"} \n"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class MonochromeFragmentShader : public ShaderPart
|
||||
{
|
||||
public:
|
||||
MonochromeFragmentShader()
|
||||
{
|
||||
m_part =
|
||||
"uniform sampler2D uColorImage; \n"
|
||||
"OUT lowp vec4 fragColor; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" mediump ivec2 coord = ivec2(gl_FragCoord.xy); \n"
|
||||
" lowp vec4 tex = texelFetch(uColorImage, coord, 0); \n"
|
||||
//" lowp float c = (tex.r + tex.g + tex.b) / 3.0f; \n"
|
||||
" lowp float c = dot(vec4(0.2126, 0.7152, 0.0722, 0.0), tex);\n"
|
||||
" fragColor = vec4(c, c, c, 1.0); \n"
|
||||
"} \n"
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*---------------SpecialShader-------------*/
|
||||
|
||||
template<class FragmentBody>
|
||||
class SpecialShader : public graphics::ShaderProgram
|
||||
{
|
||||
public:
|
||||
SpecialShader(const ShaderPart * _vertexHeader,
|
||||
const ShaderPart * _fragmentHeader)
|
||||
: m_program(0)
|
||||
{
|
||||
VertexShaderRectNocolor vertexBody;
|
||||
FragmentBody fragmentBody;
|
||||
|
||||
std::stringstream ssVertexShader;
|
||||
_vertexHeader->write(ssVertexShader);
|
||||
vertexBody.write(ssVertexShader);
|
||||
|
||||
std::stringstream ssFragmentShader;
|
||||
_fragmentHeader->write(ssFragmentShader);
|
||||
fragmentBody.write(ssFragmentShader);
|
||||
|
||||
m_program = Utils::createRectShaderProgram(ssVertexShader.str().data(), ssFragmentShader.str().data());
|
||||
}
|
||||
|
||||
~SpecialShader()
|
||||
{
|
||||
glUseProgram(0);
|
||||
glDeleteProgram(m_program);
|
||||
m_program = 0;
|
||||
}
|
||||
|
||||
void SpecialShader::activate() override {
|
||||
glUseProgram(m_program);
|
||||
gDP.changed |= CHANGED_COMBINE;
|
||||
}
|
||||
|
||||
protected:
|
||||
GLuint m_program;
|
||||
};
|
||||
|
||||
/*---------------ShadowMapShader-------------*/
|
||||
|
||||
typedef SpecialShader<ShadowMapFragmentShader> ShadowMapShaderBase;
|
||||
|
||||
class ShadowMapShader : public ShadowMapShaderBase
|
||||
{
|
||||
public:
|
||||
ShadowMapShader(const ShaderPart * _vertexHeader,
|
||||
const ShaderPart * _fragmentHeader)
|
||||
: ShadowMapShaderBase(_vertexHeader, _fragmentHeader)
|
||||
, m_loc(-1)
|
||||
{
|
||||
glUseProgram(m_program);
|
||||
m_loc = glGetUniformLocation(m_program, "uFogColor");
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void activate() override {
|
||||
ShadowMapShaderBase::activate();
|
||||
glUniform4fv(m_loc, 1, &gDP.fogColor.r);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
g_paletteTexture.update();
|
||||
}
|
||||
|
||||
private:
|
||||
int m_loc;
|
||||
};
|
||||
|
||||
/*---------------MonochromeShader-------------*/
|
||||
|
||||
typedef SpecialShader<MonochromeFragmentShader> MonochromeShaderBase;
|
||||
|
||||
class MonochromeShader : public MonochromeShaderBase
|
||||
{
|
||||
public:
|
||||
MonochromeShader(const ShaderPart * _vertexHeader,
|
||||
const ShaderPart * _fragmentHeader)
|
||||
: MonochromeShaderBase(_vertexHeader, _fragmentHeader)
|
||||
{
|
||||
glUseProgram(m_program);
|
||||
const int texLoc = glGetUniformLocation(m_program, "uColorImage");
|
||||
glUniform1i(texLoc, 0);
|
||||
glUseProgram(0);
|
||||
}
|
||||
};
|
||||
|
||||
/*---------------SpecialShadersFactory-------------*/
|
||||
|
||||
SpecialShadersFactory::SpecialShadersFactory(const opengl::GLInfo & _glinfo,
|
||||
const ShaderPart * _vertexHeader,
|
||||
const ShaderPart * _fragmentHeader)
|
||||
: m_glinfo(_glinfo)
|
||||
, m_vertexHeader(_vertexHeader)
|
||||
, m_fragmentHeader(_fragmentHeader)
|
||||
{
|
||||
}
|
||||
|
||||
graphics::ShaderProgram * SpecialShadersFactory::createShadowMapShader() const
|
||||
{
|
||||
if (!m_glinfo.imageTextures)
|
||||
return nullptr;
|
||||
|
||||
return new ShadowMapShader(m_vertexHeader, m_fragmentHeader);
|
||||
}
|
||||
|
||||
graphics::ShaderProgram * SpecialShadersFactory::createMonochromeShader() const
|
||||
{
|
||||
return new MonochromeShader(m_vertexHeader, m_fragmentHeader);
|
||||
}
|
||||
}
|
29
src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.h
Normal file
29
src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include <Graphics/OpenGLContext/opengl_GLInfo.h>
|
||||
|
||||
namespace graphics {
|
||||
class ShaderProgram;
|
||||
}
|
||||
|
||||
namespace glsl {
|
||||
|
||||
class ShaderPart;
|
||||
|
||||
class SpecialShadersFactory
|
||||
{
|
||||
public:
|
||||
SpecialShadersFactory(const opengl::GLInfo & _glinfo,
|
||||
const ShaderPart * _vertexHeader,
|
||||
const ShaderPart * _fragmentHeader);
|
||||
|
||||
graphics::ShaderProgram * createShadowMapShader() const;
|
||||
|
||||
graphics::ShaderProgram * createMonochromeShader() const;
|
||||
|
||||
private:
|
||||
const opengl::GLInfo & m_glinfo;
|
||||
const ShaderPart * m_vertexHeader;
|
||||
const ShaderPart * m_fragmentHeader;
|
||||
};
|
||||
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include <Log.h>
|
||||
#include <Graphics/OpenGLContext/opengl_Attributes.h>
|
||||
#include "glsl_Utils.h"
|
||||
|
@ -74,3 +75,32 @@ void Utils::logErrorShader(GLenum _shaderType, const std::string & _strShader)
|
|||
pos += max;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint Utils::createRectShaderProgram(const char * _strVertex, const char * _strFragment)
|
||||
{
|
||||
GLuint vertex_shader_object = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader_object, 1, &_strVertex, nullptr);
|
||||
glCompileShader(vertex_shader_object);
|
||||
assert(checkShaderCompileStatus(vertex_shader_object));
|
||||
|
||||
if (!checkShaderCompileStatus(vertex_shader_object))
|
||||
logErrorShader(GL_VERTEX_SHADER, _strVertex);
|
||||
|
||||
GLuint fragment_shader_object = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader_object, 1, &_strFragment, nullptr);
|
||||
glCompileShader(fragment_shader_object);
|
||||
assert(checkShaderCompileStatus(fragment_shader_object));
|
||||
|
||||
if (!checkShaderCompileStatus(fragment_shader_object))
|
||||
logErrorShader(GL_VERTEX_SHADER, _strFragment);
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
locateAttributes(program, true, true);
|
||||
glAttachShader(program, vertex_shader_object);
|
||||
glAttachShader(program, fragment_shader_object);
|
||||
glLinkProgram(program);
|
||||
glDeleteShader(vertex_shader_object);
|
||||
glDeleteShader(fragment_shader_object);
|
||||
assert(checkProgramLinkStatus(program));
|
||||
return program;
|
||||
}
|
||||
|
|
|
@ -9,5 +9,6 @@ namespace glsl {
|
|||
static bool checkShaderCompileStatus(GLuint obj);
|
||||
static bool checkProgramLinkStatus(GLuint obj);
|
||||
static void logErrorShader(GLenum _shaderType, const std::string & _strShader);
|
||||
static GLuint createRectShaderProgram(const char * _strVertex, const char * _strFragment);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <Log.h>
|
||||
#include "opengl_ContextImpl.h"
|
||||
#include "GLSL/glsl_CombinerProgramBuilder.h"
|
||||
#include "GLSL/glsl_SpecialShadersFactory.h"
|
||||
|
||||
using namespace opengl;
|
||||
|
||||
|
@ -124,10 +125,18 @@ graphics::CombinerProgram * ContextImpl::createCombinerProgram(Combiner & _color
|
|||
|
||||
graphics::ShaderProgram * ContextImpl::createDepthFogShader()
|
||||
{
|
||||
return nullptr;
|
||||
glsl::SpecialShadersFactory shadersFactory(m_glInfo,
|
||||
m_combinerProgramBuilder->getVertexShaderHeader(),
|
||||
m_combinerProgramBuilder->getFragmentShaderHeader());
|
||||
|
||||
return shadersFactory.createShadowMapShader();
|
||||
}
|
||||
|
||||
graphics::ShaderProgram * ContextImpl::createMonochromeShader()
|
||||
{
|
||||
return nullptr;
|
||||
glsl::SpecialShadersFactory shadersFactory(m_glInfo,
|
||||
m_combinerProgramBuilder->getVertexShaderHeader(),
|
||||
m_combinerProgramBuilder->getFragmentShaderHeader());
|
||||
|
||||
return shadersFactory.createMonochromeShader();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <Log.h>
|
||||
#include <Config.h>
|
||||
#include "opengl_Utilis.h"
|
||||
#include "opengl_Utils.h"
|
||||
#include "opengl_GLInfo.h"
|
||||
|
||||
using namespace opengl;
|
||||
|
@ -21,6 +21,9 @@ void GLInfo::init() {
|
|||
LOG(LOG_VERBOSE, "%s major version: %d\n", isGLESX ? "OpenGL ES" : "OpenGL", majorVersion);
|
||||
LOG(LOG_VERBOSE, "%s minor version: %d\n", isGLESX ? "OpenGL ES" : "OpenGL", minorVersion);
|
||||
|
||||
//TODO implement
|
||||
imageTextures = true;
|
||||
|
||||
#ifdef GL_NUM_PROGRAM_BINARY_FORMATS
|
||||
GLint numBinaryFormats = 0;
|
||||
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats);
|
||||
|
|
|
@ -62,6 +62,12 @@ namespace graphics {
|
|||
Parameter MSTex[2] = { 6U, 7U };
|
||||
}
|
||||
|
||||
namespace textureImageUnits {
|
||||
Parameter Zlut(0U);
|
||||
Parameter Tlut(1U);
|
||||
Parameter Depth(2U);
|
||||
}
|
||||
|
||||
namespace textureParameters {
|
||||
Parameter FILTER_NEAREST(GL_NEAREST);
|
||||
Parameter FILTER_LINEAR(GL_LINEAR);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <Graphics/Parameters.h>
|
||||
#include "opengl_GLInfo.h"
|
||||
#include "opengl_CachedFunctions.h"
|
||||
#include "opengl_Utils.h"
|
||||
#include "opengl_TextureManipulationObjectFactory.h"
|
||||
|
||||
namespace opengl {
|
||||
|
@ -50,9 +51,11 @@ namespace opengl {
|
|||
|
||||
void init2DTexture(const graphics::Context::InitTextureParams & _params) override
|
||||
{
|
||||
|
||||
if (_params.msaaLevel == 0) {
|
||||
//glBindTexture(GL_TEXTURE_2D, GLuint(_name));
|
||||
if (_params.ImageUnit.isValid())
|
||||
glBindImageTexture(GLuint(_params.ImageUnit), 0,
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
|
||||
m_bind->bind(graphics::target::TEXTURE_2D, _params.handle);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
_params.mipMapLevel,
|
||||
|
@ -63,6 +66,10 @@ namespace opengl {
|
|||
GLenum(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
|
||||
if (_params.ImageUnit.isValid() && glBindImageTexture != nullptr)
|
||||
glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle),
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
} else {
|
||||
//glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, GLuint(_name));
|
||||
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.handle);
|
||||
|
@ -106,16 +113,23 @@ namespace opengl {
|
|||
_params.width,
|
||||
_params.height);
|
||||
}
|
||||
if (_params.data != nullptr)
|
||||
|
||||
if (_params.data != nullptr) {
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
_params.mipMapLevel,
|
||||
0, 0,
|
||||
_params.width,
|
||||
_params.height,
|
||||
GLuint(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
} else {
|
||||
_params.mipMapLevel,
|
||||
0, 0,
|
||||
_params.width,
|
||||
_params.height,
|
||||
GLuint(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
}
|
||||
|
||||
if (_params.ImageUnit.isValid() && glBindImageTexture != nullptr)
|
||||
glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle),
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
}
|
||||
else {
|
||||
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.handle);
|
||||
glTexStorage2DMultisample(
|
||||
GL_TEXTURE_2D_MULTISAMPLE,
|
||||
|
@ -161,16 +175,23 @@ namespace opengl {
|
|||
_params.width,
|
||||
_params.height);
|
||||
}
|
||||
if (_params.data != nullptr)
|
||||
|
||||
if (_params.data != nullptr) {
|
||||
glTextureSubImage2D(GLuint(_params.handle),
|
||||
_params.mipMapLevel,
|
||||
0, 0,
|
||||
_params.width,
|
||||
_params.height,
|
||||
GLuint(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
} else {
|
||||
_params.mipMapLevel,
|
||||
0, 0,
|
||||
_params.width,
|
||||
_params.height,
|
||||
GLuint(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
}
|
||||
|
||||
if (_params.ImageUnit.isValid() && glBindImageTexture != nullptr)
|
||||
glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle),
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
}
|
||||
else {
|
||||
glTexStorage2DMultisample(GLuint(_params.handle),
|
||||
_params.msaaLevel,
|
||||
GLenum(_params.internalFormat),
|
||||
|
@ -204,6 +225,7 @@ namespace opengl {
|
|||
{
|
||||
m_activeTexture->setActiveTexture(_params.textureUnitIndex);
|
||||
m_bind->bind(GL_TEXTURE_2D, _params.handle);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
_params.mipMapLevel,
|
||||
_params.x,
|
||||
|
@ -213,6 +235,10 @@ namespace opengl {
|
|||
GLuint(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
|
||||
if (_params.ImageUnit.isValid() && _params.internalFormat.isValid() && glBindImageTexture != nullptr)
|
||||
glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle),
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -242,6 +268,10 @@ namespace opengl {
|
|||
GLuint(_params.format),
|
||||
GLenum(_params.dataType),
|
||||
_params.data);
|
||||
|
||||
if (_params.ImageUnit.isValid() && _params.internalFormat.isValid() && glBindImageTexture != nullptr)
|
||||
glBindImageTexture(GLuint(_params.ImageUnit), GLuint(_params.handle),
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#include <Types.h>
|
||||
#include "opengl_Utilis.h"
|
||||
#include "GLFunctions.h"
|
||||
|
||||
using namespace opengl;
|
||||
|
||||
bool Utils::isExtensionSupported(const char *extension)
|
||||
{
|
||||
#ifdef GL_NUM_EXTENSIONS
|
||||
GLint count = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
const char* name = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||
if (name == nullptr)
|
||||
continue;
|
||||
if (strcmp(extension, name) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
GLubyte *where = (GLubyte *)strchr(extension, ' ');
|
||||
if (where || *extension == '\0')
|
||||
return false;
|
||||
|
||||
const GLubyte *extensions = glGetString(GL_EXTENSIONS);
|
||||
|
||||
const GLubyte *start = extensions;
|
||||
for (;;) {
|
||||
where = (GLubyte *)strstr((const char *)start, extension);
|
||||
if (where == nullptr)
|
||||
break;
|
||||
|
||||
GLubyte *terminator = where + strlen(extension);
|
||||
if (where == start || *(where - 1) == ' ')
|
||||
if (*terminator == ' ' || *terminator == '\0')
|
||||
return true;
|
||||
|
||||
start = terminator;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif // GL_NUM_EXTENSIONS
|
||||
}
|
99
src/Graphics/OpenGLContext/opengl_Utils.cpp
Normal file
99
src/Graphics/OpenGLContext/opengl_Utils.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include <Types.h>
|
||||
#include <Log.h>
|
||||
#include "opengl_Utils.h"
|
||||
#include "GLFunctions.h"
|
||||
|
||||
using namespace opengl;
|
||||
|
||||
bool Utils::isExtensionSupported(const char *extension)
|
||||
{
|
||||
#ifdef GL_NUM_EXTENSIONS
|
||||
GLint count = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
const char* name = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||
if (name == nullptr)
|
||||
continue;
|
||||
if (strcmp(extension, name) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
GLubyte *where = (GLubyte *)strchr(extension, ' ');
|
||||
if (where || *extension == '\0')
|
||||
return false;
|
||||
|
||||
const GLubyte *extensions = glGetString(GL_EXTENSIONS);
|
||||
|
||||
const GLubyte *start = extensions;
|
||||
for (;;) {
|
||||
where = (GLubyte *)strstr((const char *)start, extension);
|
||||
if (where == nullptr)
|
||||
break;
|
||||
|
||||
GLubyte *terminator = where + strlen(extension);
|
||||
if (where == start || *(where - 1) == ' ')
|
||||
if (*terminator == ' ' || *terminator == '\0')
|
||||
return true;
|
||||
|
||||
start = terminator;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif // GL_NUM_EXTENSIONS
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
const char* GLErrorString(GLenum errorCode)
|
||||
{
|
||||
static const struct {
|
||||
GLenum code;
|
||||
const char *string;
|
||||
} errors[] =
|
||||
{
|
||||
/* GL */
|
||||
{ GL_NO_ERROR, "no error" },
|
||||
{ GL_INVALID_ENUM, "invalid enumerant" },
|
||||
{ GL_INVALID_VALUE, "invalid value" },
|
||||
{ GL_INVALID_OPERATION, "invalid operation" },
|
||||
#ifndef GLESX
|
||||
{ GL_STACK_OVERFLOW, "stack overflow" },
|
||||
{ GL_STACK_UNDERFLOW, "stack underflow" },
|
||||
#endif
|
||||
{ GL_OUT_OF_MEMORY, "out of memory" },
|
||||
|
||||
{ 0, nullptr }
|
||||
};
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; errors[i].string; i++)
|
||||
{
|
||||
if (errors[i].code == errorCode)
|
||||
{
|
||||
return errors[i].string;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Utils::isGLError()
|
||||
{
|
||||
GLenum errCode;
|
||||
const char* errString;
|
||||
|
||||
if ((errCode = glGetError()) != GL_NO_ERROR) {
|
||||
errString = GLErrorString(errCode);
|
||||
if (errString != nullptr) {
|
||||
LOG(LOG_ERROR, "OpenGL Error: %s (%x)", errString, errCode);
|
||||
}
|
||||
else {
|
||||
LOG(LOG_ERROR, "OpenGL Error: %x", errCode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace opengl {
|
|||
struct Utils
|
||||
{
|
||||
static bool isExtensionSupported(const char * extension);
|
||||
static bool isGLError();
|
||||
};
|
||||
|
||||
}
|
|
@ -62,6 +62,12 @@ namespace graphics {
|
|||
extern Parameter MSTex[2];
|
||||
}
|
||||
|
||||
namespace textureImageUnits {
|
||||
extern Parameter Zlut;
|
||||
extern Parameter Tlut;
|
||||
extern Parameter Depth;
|
||||
}
|
||||
|
||||
namespace textureParameters {
|
||||
extern Parameter FILTER_NEAREST;
|
||||
extern Parameter FILTER_LINEAR;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace graphics {
|
|||
class ShaderProgram
|
||||
{
|
||||
public:
|
||||
virtual ~ShaderProgram() {};
|
||||
virtual ~ShaderProgram() {}
|
||||
virtual void activate() = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ void NoiseTexture::init()
|
|||
}
|
||||
|
||||
// Generate Pixel Buffer Object. Initialize it with max buffer size.
|
||||
m_pbuf.reset(gfxContext.createPixelWriteBuffer(640 * 580));
|
||||
m_pbuf.reset(gfxContext.createPixelWriteBuffer(m_pTexture->textureBytes));
|
||||
}
|
||||
|
||||
void NoiseTexture::destroy()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
@ -17,6 +18,9 @@
|
|||
#include <FBOTextureFormats.h>
|
||||
#include <Graphics/Context.h>
|
||||
#include <Graphics/Parameters.h>
|
||||
#include <Graphics/ShaderProgram.h>
|
||||
#include "ZlutTexture.h"
|
||||
#include "PaletteTexture.h"
|
||||
|
||||
#include "Shaders_ogl3x.h"
|
||||
|
||||
|
@ -36,6 +40,9 @@ static GLuint g_readtex_ms_shader_object;
|
|||
static GLuint g_dither_shader_object;
|
||||
static GLuint g_monochrome_image_program = 0;
|
||||
|
||||
static unique_ptr<graphics::ShaderProgram> g_shadowmapProgram;
|
||||
static unique_ptr<graphics::ShaderProgram> g_monochromeProgram;
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
GLuint g_draw_shadow_map_program = 0;
|
||||
static GLuint g_zlut_tex = 0;
|
||||
|
@ -151,6 +158,7 @@ void NoiseTexture::update()
|
|||
static
|
||||
void InitZlutTexture()
|
||||
{
|
||||
#if 0
|
||||
if (!video().getRender().isImageTexturesSupported())
|
||||
return;
|
||||
|
||||
|
@ -173,11 +181,15 @@ void InitZlutTexture()
|
|||
glTexStorage2D(GL_TEXTURE_2D, 1, fboFormats.lutInternalFormat, 512, 512);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, fboFormats.lutFormat, fboFormats.lutType, zLUT);
|
||||
glBindImageTexture(ZlutImageUnit, g_zlut_tex, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, fboFormats.lutInternalFormat);
|
||||
#else
|
||||
//g_zlutTexture.init();
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
void DestroyZlutTexture()
|
||||
{
|
||||
#if 0
|
||||
if (!video().getRender().isImageTexturesSupported())
|
||||
return;
|
||||
|
||||
|
@ -187,11 +199,20 @@ void DestroyZlutTexture()
|
|||
glDeleteTextures(1, &g_zlut_tex);
|
||||
g_zlut_tex = 0;
|
||||
}
|
||||
#else
|
||||
//g_zlutTexture.destroy();
|
||||
#endif
|
||||
}
|
||||
|
||||
#define USE_PALETTE_TEX
|
||||
|
||||
#define USE_NEW_SHADOWMAP
|
||||
#define USE_NEW_MONOCHROME
|
||||
|
||||
static
|
||||
void InitShadowMapShader()
|
||||
{
|
||||
#ifndef USE_PALETTE_TEX
|
||||
if (!video().getRender().isImageTexturesSupported())
|
||||
return;
|
||||
|
||||
|
@ -228,13 +249,23 @@ void InitShadowMapShader()
|
|||
gfxContext.setTextureParameters(params);
|
||||
}
|
||||
#endif // GRAPHICS_CONTEXT
|
||||
#else
|
||||
//g_paletteTexture.init();
|
||||
#endif
|
||||
|
||||
#ifndef USE_NEW_SHADOWMAP
|
||||
g_draw_shadow_map_program = createRectShaderProgram(vertex_shader_rect_nocolor, shadow_map_fragment_shader_float);
|
||||
|
||||
isGLError();
|
||||
#else
|
||||
g_shadowmapProgram.reset(gfxContext.createDepthFogShader());
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
void DestroyShadowMapShader()
|
||||
{
|
||||
#ifndef USE_PALETTE_TEX
|
||||
if (!video().getRender().isImageTexturesSupported())
|
||||
return;
|
||||
|
||||
|
@ -245,9 +276,18 @@ void DestroyShadowMapShader()
|
|||
glDeleteTextures(1, &g_tlut_tex);
|
||||
g_tlut_tex = 0;
|
||||
}
|
||||
#else
|
||||
//g_paletteTexture.destroy();
|
||||
#endif
|
||||
|
||||
#ifndef USE_NEW_SHADOWMAP
|
||||
glDeleteProgram(g_draw_shadow_map_program);
|
||||
g_draw_shadow_map_program = 0;
|
||||
#else
|
||||
g_shadowmapProgram.reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
static
|
||||
|
@ -262,6 +302,7 @@ GLuint _createShader(GLenum _type, const char * _strShader)
|
|||
|
||||
void InitShaderCombiner()
|
||||
{
|
||||
#if 1
|
||||
g_vertex_shader_object = _createShader(GL_VERTEX_SHADER, vertex_shader);
|
||||
g_vertex_shader_object_notex = _createShader(GL_VERTEX_SHADER, vertex_shader_notex);
|
||||
g_vertex_shader_object_texrect = _createShader(GL_VERTEX_SHADER, vertex_shader_texrect);
|
||||
|
@ -279,12 +320,16 @@ void InitShaderCombiner()
|
|||
#endif // GLESX
|
||||
|
||||
// noiseTex.init();
|
||||
#ifndef USE_NEW_MONOCHROME
|
||||
g_monochrome_image_program = createRectShaderProgram(vertex_shader_rect_nocolor, zelda_monochrome_fragment_shader);
|
||||
glUseProgram(g_monochrome_image_program);
|
||||
const int texLoc = glGetUniformLocation(g_monochrome_image_program, "uColorImage");
|
||||
glUniform1i(texLoc, 0);
|
||||
|
||||
glUseProgram(0);
|
||||
#else
|
||||
g_monochromeProgram.reset(gfxContext.createMonochromeShader());
|
||||
#endif
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0) {
|
||||
|
@ -295,9 +340,13 @@ void InitShaderCombiner()
|
|||
InitZlutTexture();
|
||||
InitShadowMapShader();
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void DestroyShaderCombiner() {
|
||||
#if 1
|
||||
strFragmentShader.clear();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
|
@ -328,14 +377,20 @@ void DestroyShaderCombiner() {
|
|||
g_calc_depth_shader_object = 0;
|
||||
#endif // GLESX
|
||||
|
||||
#ifndef USE_NEW_MONOCHROME
|
||||
glDeleteProgram(g_monochrome_image_program);
|
||||
g_monochrome_image_program = 0;
|
||||
// noiseTex.destroy();
|
||||
#else
|
||||
g_monochromeProgram.reset();
|
||||
#endif
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
DestroyZlutTexture();
|
||||
DestroyShadowMapShader();
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ShaderCombiner::ShaderCombiner() : m_bNeedUpdate(true)
|
||||
|
@ -940,8 +995,12 @@ void ShaderCombiner::getShaderCombinerOptionsSet(std::vector<u32> & _vecOptions)
|
|||
}
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
#ifndef USE_NEW_SHADOWMAP
|
||||
void SetDepthFogCombiner()
|
||||
{
|
||||
|
||||
#ifndef USE_PALETTE_TEX
|
||||
if (!video().getRender().isImageTexturesSupported())
|
||||
return;
|
||||
|
||||
|
@ -962,6 +1021,9 @@ void SetDepthFogCombiner()
|
|||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindImageTexture(TlutImageUnit, g_tlut_tex, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
|
||||
}
|
||||
#else
|
||||
//g_paletteTexture.update();
|
||||
#endif
|
||||
|
||||
glUseProgram(g_draw_shadow_map_program);
|
||||
int loc = glGetUniformLocation(g_draw_shadow_map_program, "uFogColor");
|
||||
|
@ -971,10 +1033,24 @@ void SetDepthFogCombiner()
|
|||
|
||||
gDP.changed |= CHANGED_COMBINE;
|
||||
}
|
||||
#else
|
||||
void SetDepthFogCombiner()
|
||||
{
|
||||
g_shadowmapProgram->activate();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
||||
#ifndef USE_NEW_MONOCHROME
|
||||
void SetMonochromeCombiner()
|
||||
{
|
||||
glUseProgram(g_monochrome_image_program);
|
||||
gDP.changed |= CHANGED_COMBINE;
|
||||
}
|
||||
#else
|
||||
void SetMonochromeCombiner()
|
||||
{
|
||||
g_monochromeProgram->activate();
|
||||
}
|
||||
#endif
|
|
@ -28,6 +28,8 @@
|
|||
#include "FBOTextureFormats.h"
|
||||
#include "TextureFilterHandler.h"
|
||||
#include "NoiseTexture.h"
|
||||
#include "ZlutTexture.h"
|
||||
#include "PaletteTexture.h"
|
||||
|
||||
#include "Graphics/Context.h"
|
||||
#include <Graphics/Parameters.h>
|
||||
|
@ -1606,7 +1608,7 @@ bool texturedRectShadowMap(const OGLRender::TexturedRectParams &)
|
|||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
if (video().getRender().isImageTexturesSupported()) {
|
||||
pCurrentBuffer->m_pDepthBuffer->activateDepthBufferTexture(pCurrentBuffer);
|
||||
SetDepthFogCombiner();
|
||||
CombinerInfo::get().setDepthFogCombiner();
|
||||
}
|
||||
else
|
||||
return true;
|
||||
|
@ -1741,7 +1743,7 @@ bool texturedRectMonochromeBackground(const OGLRender::TexturedRectParams & _par
|
|||
FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent();
|
||||
if (pCurrentBuffer != nullptr) {
|
||||
FrameBuffer_ActivateBufferTexture(0, pCurrentBuffer);
|
||||
SetMonochromeCombiner();
|
||||
CombinerInfo::get().setMonochromeCombiner();
|
||||
return false;
|
||||
} else
|
||||
#endif
|
||||
|
@ -2216,7 +2218,9 @@ void OGLRender::_initData()
|
|||
TextDrawer::get().init();
|
||||
TFH.init();
|
||||
PostProcessor::get().init();
|
||||
g_zlutTexture.init();
|
||||
g_noiseTexture.init();
|
||||
g_paletteTexture.init();
|
||||
perf.reset();
|
||||
FBInfo::fbInfo.reset();
|
||||
m_texrectDrawer.init();
|
||||
|
@ -2250,6 +2254,8 @@ void OGLRender::_destroyData()
|
|||
|
||||
m_renderState = rsNone;
|
||||
m_texrectDrawer.destroy();
|
||||
g_paletteTexture.destroy();
|
||||
g_zlutTexture.destroy();
|
||||
g_noiseTexture.destroy();
|
||||
PostProcessor::get().destroy();
|
||||
if (TFH.optionsChanged())
|
||||
|
|
106
src/PaletteTexture.cpp
Normal file
106
src/PaletteTexture.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#include "Graphics/Context.h"
|
||||
#include "Graphics/Parameters.h"
|
||||
#include "N64.h"
|
||||
#include "gDP.h"
|
||||
#include "VI.h"
|
||||
#include "Textures.h"
|
||||
#include "FBOTextureFormats.h"
|
||||
#include "PaletteTexture.h"
|
||||
#include "DepthBuffer.h"
|
||||
|
||||
|
||||
PaletteTexture g_paletteTexture;
|
||||
|
||||
PaletteTexture::PaletteTexture()
|
||||
: m_pTexture(nullptr)
|
||||
, m_paletteCRC256(0)
|
||||
{
|
||||
}
|
||||
|
||||
void PaletteTexture::init()
|
||||
{
|
||||
m_paletteCRC256 = 0;
|
||||
m_pTexture = textureCache().addFrameBufferTexture(false);
|
||||
m_pTexture->format = G_IM_FMT_IA;
|
||||
m_pTexture->clampS = 1;
|
||||
m_pTexture->clampT = 1;
|
||||
m_pTexture->frameBufferTexture = CachedTexture::fbOneSample;
|
||||
m_pTexture->maskS = 0;
|
||||
m_pTexture->maskT = 0;
|
||||
m_pTexture->mirrorS = 0;
|
||||
m_pTexture->mirrorT = 0;
|
||||
m_pTexture->realWidth = 256;
|
||||
m_pTexture->realHeight = 1;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight;
|
||||
#ifdef GLESX
|
||||
m_pTexture->textureBytes *= sizeof(u32);
|
||||
#else
|
||||
m_pTexture->textureBytes *= sizeof(u16);
|
||||
#endif
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
graphics::Context::InitTextureParams initParams;
|
||||
initParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
initParams.ImageUnit = graphics::textureImageUnits::Tlut;
|
||||
initParams.width = m_pTexture->realWidth;
|
||||
initParams.height = m_pTexture->realHeight;
|
||||
initParams.internalFormat = fboFormats.lutInternalFormat;
|
||||
initParams.format = fboFormats.lutFormat;
|
||||
initParams.dataType = fboFormats.lutType;
|
||||
gfxContext.init2DTexture(initParams);
|
||||
|
||||
graphics::Context::TexParameters setParams;
|
||||
setParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
setParams.target = graphics::target::TEXTURE_2D;
|
||||
setParams.textureUnitIndex = graphics::textureIndices::PaletteTex;
|
||||
setParams.minFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.wrapS = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
setParams.wrapT = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
gfxContext.setTextureParameters(setParams);
|
||||
|
||||
// Generate Pixel Buffer Object. Initialize it with max buffer size.
|
||||
m_pbuf.reset(gfxContext.createPixelWriteBuffer(m_pTexture->textureBytes));
|
||||
isGLError();
|
||||
}
|
||||
|
||||
void PaletteTexture::destroy()
|
||||
{
|
||||
glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
m_pTexture = nullptr;
|
||||
m_pbuf.reset();
|
||||
}
|
||||
|
||||
void PaletteTexture::update()
|
||||
{
|
||||
if (m_paletteCRC256 == gDP.paletteCRC256)
|
||||
return;
|
||||
|
||||
m_paletteCRC256 = gDP.paletteCRC256;
|
||||
|
||||
graphics::PixelBufferBinder<graphics::PixelWriteBuffer> binder(m_pbuf.get());
|
||||
GLubyte* ptr = (GLubyte*)m_pbuf->getWriteBuffer(m_pTexture->textureBytes);
|
||||
#ifdef GLESX
|
||||
u32 * palette = (u32*)ptr;
|
||||
#else
|
||||
u16 * palette = (u16*)ptr;
|
||||
#endif
|
||||
u16 *src = (u16*)&TMEM[256];
|
||||
for (int i = 0; i < 256; ++i)
|
||||
palette[i] = swapword(src[i * 4]);
|
||||
m_pbuf->closeWriteBuffer();
|
||||
|
||||
graphics::Context::UpdateTextureDataParams params;
|
||||
params.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
params.ImageUnit = graphics::textureImageUnits::Tlut;
|
||||
params.textureUnitIndex = graphics::textureIndices::PaletteTex;
|
||||
params.width = m_pTexture->realWidth;
|
||||
params.height = m_pTexture->realHeight;
|
||||
params.format = fboFormats.lutFormat;
|
||||
params.internalFormat = fboFormats.lutInternalFormat;
|
||||
params.dataType = fboFormats.lutType;
|
||||
params.data = m_pbuf->getData();
|
||||
glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, fboFormats.lutInternalFormat);
|
||||
gfxContext.update2DTexture(params);
|
||||
}
|
26
src/PaletteTexture.h
Normal file
26
src/PaletteTexture.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
namespace graphics {
|
||||
class PixelWriteBuffer;
|
||||
}
|
||||
|
||||
struct CachedTexture;
|
||||
|
||||
class PaletteTexture
|
||||
{
|
||||
public:
|
||||
PaletteTexture();
|
||||
|
||||
void init();
|
||||
void destroy();
|
||||
void update();
|
||||
|
||||
private:
|
||||
CachedTexture * m_pTexture;
|
||||
u32 m_tlut_tex;
|
||||
std::unique_ptr<graphics::PixelWriteBuffer> m_pbuf;
|
||||
u32 m_paletteCRC256;
|
||||
};
|
||||
|
||||
extern PaletteTexture g_paletteTexture;
|
70
src/ZlutTexture.cpp
Normal file
70
src/ZlutTexture.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "Graphics/Context.h"
|
||||
#include "Graphics/Parameters.h"
|
||||
#include "FBOTextureFormats.h"
|
||||
#include "DepthBuffer.h"
|
||||
#include "Config.h""
|
||||
#include "Textures.h"
|
||||
#include "ZlutTexture.h"
|
||||
|
||||
|
||||
ZlutTexture g_zlutTexture;
|
||||
|
||||
ZlutTexture::ZlutTexture()
|
||||
: m_pTexture(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void ZlutTexture::init()
|
||||
{
|
||||
// TODO make GL independent
|
||||
#ifdef GLESX
|
||||
std::vector<u32> vecZLUT(0x40000);
|
||||
const u16 * const zLUT16 = depthBufferList().getZLUT();
|
||||
for (u32 i = 0; i < 0x40000; ++i)
|
||||
vecZLUT[i] = zLUT16[i];
|
||||
const u32 * zLUT = vecZLUT.data();
|
||||
#else
|
||||
const u16 * const zLUT = depthBufferList().getZLUT();
|
||||
#endif
|
||||
|
||||
m_pTexture = textureCache().addFrameBufferTexture(false);
|
||||
m_pTexture->format = G_IM_FMT_IA;
|
||||
m_pTexture->clampS = 1;
|
||||
m_pTexture->clampT = 1;
|
||||
m_pTexture->frameBufferTexture = CachedTexture::fbOneSample;
|
||||
m_pTexture->maskS = 0;
|
||||
m_pTexture->maskT = 0;
|
||||
m_pTexture->mirrorS = 0;
|
||||
m_pTexture->mirrorT = 0;
|
||||
m_pTexture->realWidth = 512;
|
||||
m_pTexture->realHeight = 512;
|
||||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * sizeof(zLUT[0]);
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
graphics::Context::InitTextureParams initParams;
|
||||
initParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
initParams.ImageUnit = graphics::textureImageUnits::Zlut;
|
||||
initParams.width = m_pTexture->realWidth;
|
||||
initParams.height = m_pTexture->realHeight;
|
||||
initParams.internalFormat = fboFormats.lutInternalFormat;
|
||||
initParams.format = fboFormats.lutFormat;
|
||||
initParams.dataType = fboFormats.lutType;
|
||||
initParams.data = zLUT;
|
||||
gfxContext.init2DTexture(initParams);
|
||||
|
||||
graphics::Context::TexParameters setParams;
|
||||
setParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
setParams.target = graphics::target::TEXTURE_2D;
|
||||
setParams.textureUnitIndex = graphics::textureIndices::ZLUTTex;
|
||||
setParams.minFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.wrapS = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
setParams.wrapT = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
gfxContext.setTextureParameters(setParams);
|
||||
}
|
||||
|
||||
void ZlutTexture::destroy() {
|
||||
glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, fboFormats.lutInternalFormat);
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
m_pTexture = nullptr;
|
||||
}
|
17
src/ZlutTexture.h
Normal file
17
src/ZlutTexture.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
struct CachedTexture;
|
||||
|
||||
class ZlutTexture
|
||||
{
|
||||
public:
|
||||
ZlutTexture();
|
||||
|
||||
void init();
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
CachedTexture * m_pTexture;
|
||||
};
|
||||
|
||||
extern ZlutTexture g_zlutTexture;
|
Loading…
Reference in New Issue
Block a user