Split ogles2 shader for 2D rendering into a texture and non-texture variant.
That's otherwise hard to do from user-code because 2d rendering works a little different than 3d. This way it renders faster and also won't cause any warnings in WebGL. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5445 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
8be8f18f47
commit
b8cf4ca4bf
|
@ -0,0 +1,9 @@
|
|||
precision mediump float;
|
||||
|
||||
/* Varyings */
|
||||
varying vec4 vVertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vVertexColor;
|
||||
}
|
|
@ -35,8 +35,10 @@ namespace video
|
|||
{
|
||||
|
||||
COGLES2Driver::COGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) :
|
||||
CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(), CacheHandler(0), MaterialRenderer2D(0), CurrentRenderMode(ERM_NONE),
|
||||
ResetRenderStates(true), LockRenderStateMode(false), Transformation3DChanged(true), AntiAlias(params.AntiAlias), OGLES2ShaderPath(params.OGLES2ShaderPath),
|
||||
CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(), CacheHandler(0),
|
||||
MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0),
|
||||
CurrentRenderMode(ERM_NONE), ResetRenderStates(true), LockRenderStateMode(false), Transformation3DChanged(true), AntiAlias(params.AntiAlias),
|
||||
OGLES2ShaderPath(params.OGLES2ShaderPath),
|
||||
ColorFormat(ECF_R8G8B8), Params(params), ContextManager(contextManager)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
@ -88,6 +90,8 @@ COGLES2Driver::~COGLES2Driver()
|
|||
removeAllOcclusionQueries();
|
||||
removeAllHardwareBuffers();
|
||||
|
||||
delete MaterialRenderer2DTexture;
|
||||
delete MaterialRenderer2DNoTexture;
|
||||
delete CacheHandler;
|
||||
|
||||
if (ContextManager)
|
||||
|
@ -391,12 +395,19 @@ COGLES2Driver::~COGLES2Driver()
|
|||
ParallaxMapVertexAlphaCB->drop();
|
||||
OneTextureBlendCB->drop();
|
||||
|
||||
// Create 2D material renderer.
|
||||
// Create 2D material renderers
|
||||
|
||||
c8* vs2DData = 0;
|
||||
c8* fs2DData = 0;
|
||||
loadShaderData(io::path("COGLES2Renderer2D.vsh"), io::path("COGLES2Renderer2D.fsh"), &vs2DData, &fs2DData);
|
||||
MaterialRenderer2D = new COGLES2Renderer2D(vs2DData, fs2DData, this);
|
||||
MaterialRenderer2DTexture = new COGLES2Renderer2D(vs2DData, fs2DData, this, true);
|
||||
delete[] vs2DData;
|
||||
delete[] fs2DData;
|
||||
vs2DData = 0;
|
||||
fs2DData = 0;
|
||||
|
||||
loadShaderData(io::path("COGLES2Renderer2D.vsh"), io::path("COGLES2Renderer2D_noTex.fsh"), &vs2DData, &fs2DData);
|
||||
MaterialRenderer2DNoTexture = new COGLES2Renderer2D(vs2DData, fs2DData, this, false);
|
||||
delete[] vs2DData;
|
||||
delete[] fs2DData;
|
||||
}
|
||||
|
@ -1684,8 +1695,11 @@ COGLES2Driver::~COGLES2Driver()
|
|||
// unset old material
|
||||
|
||||
// unset last 3d material
|
||||
if (CurrentRenderMode == ERM_2D)
|
||||
MaterialRenderer2D->OnUnsetMaterial();
|
||||
if (CurrentRenderMode == ERM_2D && MaterialRenderer2DActive)
|
||||
{
|
||||
MaterialRenderer2DActive->OnUnsetMaterial();
|
||||
MaterialRenderer2DActive = 0;
|
||||
}
|
||||
else if (LastMaterial.MaterialType != Material.MaterialType &&
|
||||
static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
|
||||
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
|
||||
|
@ -1959,6 +1973,8 @@ COGLES2Driver::~COGLES2Driver()
|
|||
if ( LockRenderStateMode )
|
||||
return;
|
||||
|
||||
COGLES2Renderer2D* nextActiveRenderer = texture ? MaterialRenderer2DTexture : MaterialRenderer2DNoTexture;
|
||||
|
||||
if (CurrentRenderMode != ERM_2D)
|
||||
{
|
||||
// unset last 3d material
|
||||
|
@ -1970,8 +1986,14 @@ COGLES2Driver::~COGLES2Driver()
|
|||
|
||||
CurrentRenderMode = ERM_2D;
|
||||
}
|
||||
else if ( MaterialRenderer2DActive && MaterialRenderer2DActive != nextActiveRenderer)
|
||||
{
|
||||
MaterialRenderer2DActive->OnUnsetMaterial();
|
||||
}
|
||||
|
||||
MaterialRenderer2D->OnSetMaterial(Material, LastMaterial, true, 0);
|
||||
MaterialRenderer2DActive = nextActiveRenderer;
|
||||
|
||||
MaterialRenderer2DActive->OnSetMaterial(Material, LastMaterial, true, 0);
|
||||
LastMaterial = Material;
|
||||
|
||||
// no alphaChannel without texture
|
||||
|
@ -1996,7 +2018,7 @@ COGLES2Driver::~COGLES2Driver()
|
|||
setTextureRenderStates(InitMaterial2D, false);
|
||||
}
|
||||
|
||||
MaterialRenderer2D->OnRender(this, video::EVT_STANDARD);
|
||||
MaterialRenderer2DActive->OnRender(this, video::EVT_STANDARD);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -363,7 +363,9 @@ namespace video
|
|||
void loadShaderData(const io::path& vertexShaderName, const io::path& fragmentShaderName, c8** vertexShaderData, c8** fragmentShaderData);
|
||||
|
||||
COGLES2CacheHandler* CacheHandler;
|
||||
COGLES2Renderer2D* MaterialRenderer2D;
|
||||
COGLES2Renderer2D* MaterialRenderer2DActive;
|
||||
COGLES2Renderer2D* MaterialRenderer2DTexture;
|
||||
COGLES2Renderer2D* MaterialRenderer2DNoTexture;
|
||||
|
||||
core::stringw Name;
|
||||
core::matrix4 Matrices[ETS_COUNT];
|
||||
|
|
|
@ -20,8 +20,9 @@ namespace irr
|
|||
namespace video
|
||||
{
|
||||
|
||||
COGLES2Renderer2D::COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver) :
|
||||
COGLES2MaterialRenderer(driver, 0, EMT_SOLID)
|
||||
COGLES2Renderer2D::COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver, bool withTexture) :
|
||||
COGLES2MaterialRenderer(driver, 0, EMT_SOLID),
|
||||
WithTexture(withTexture)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("COGLES2Renderer2D");
|
||||
|
@ -38,11 +39,17 @@ COGLES2Renderer2D::COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pi
|
|||
// These states don't change later.
|
||||
|
||||
ThicknessID = getPixelShaderConstantID("uThickness");
|
||||
TextureUsageID = getPixelShaderConstantID("uTextureUsage");
|
||||
s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit");
|
||||
if ( WithTexture )
|
||||
{
|
||||
TextureUsageID = getPixelShaderConstantID("uTextureUsage");
|
||||
s32 TextureUnitID = getPixelShaderConstantID("uTextureUnit");
|
||||
|
||||
s32 TextureUnit = 0;
|
||||
setPixelShaderConstant(TextureUnitID, &TextureUnit, 1);
|
||||
s32 TextureUnit = 0;
|
||||
setPixelShaderConstant(TextureUnitID, &TextureUnit, 1);
|
||||
|
||||
s32 TextureUsage = 0;
|
||||
setPixelShaderConstant(TextureUsageID, &TextureUsage, 1);
|
||||
}
|
||||
|
||||
cacheHandler->setProgram(0);
|
||||
}
|
||||
|
@ -62,8 +69,11 @@ void COGLES2Renderer2D::OnSetMaterial(const video::SMaterial& material,
|
|||
f32 Thickness = (material.Thickness > 0.f) ? material.Thickness : 1.f;
|
||||
setPixelShaderConstant(ThicknessID, &Thickness, 1);
|
||||
|
||||
s32 TextureUsage = material.TextureLayer[0].Texture ? 1 : 0;
|
||||
setPixelShaderConstant(TextureUsageID, &TextureUsage, 1);
|
||||
if ( WithTexture )
|
||||
{
|
||||
s32 TextureUsage = material.TextureLayer[0].Texture ? 1 : 0;
|
||||
setPixelShaderConstant(TextureUsageID, &TextureUsage, 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool COGLES2Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
|
||||
|
@ -75,4 +85,3 @@ bool COGLES2Renderer2D::OnRender(IMaterialRendererServices* service, E_VERTEX_TY
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace video
|
|||
class COGLES2Renderer2D : public COGLES2MaterialRenderer
|
||||
{
|
||||
public:
|
||||
COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver);
|
||||
COGLES2Renderer2D(const c8* vertexShaderProgram, const c8* pixelShaderProgram, COGLES2Driver* driver, bool withTexture);
|
||||
~COGLES2Renderer2D();
|
||||
|
||||
virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
|
||||
|
@ -28,6 +28,7 @@ public:
|
|||
virtual bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
|
||||
|
||||
protected:
|
||||
bool WithTexture;
|
||||
s32 ThicknessID;
|
||||
s32 TextureUsageID;
|
||||
};
|
||||
|
|
|
@ -824,6 +824,7 @@
|
|||
<Unit filename="COBJMeshWriter.h" />
|
||||
<Unit filename="COCTLoader.cpp" />
|
||||
<Unit filename="COCTLoader.h" />
|
||||
<Unit filename="COGLES2Common.h" />
|
||||
<Unit filename="COGLES2Driver.cpp" />
|
||||
<Unit filename="COGLES2Driver.h" />
|
||||
<Unit filename="COGLES2ExtensionHandler.cpp" />
|
||||
|
@ -838,6 +839,7 @@
|
|||
<Unit filename="COGLES2ParallaxMapRenderer.h" />
|
||||
<Unit filename="COGLES2Renderer2D.cpp" />
|
||||
<Unit filename="COGLES2Renderer2D.h" />
|
||||
<Unit filename="COGLESCommon.h" />
|
||||
<Unit filename="COGLESDriver.cpp" />
|
||||
<Unit filename="COGLESDriver.h" />
|
||||
<Unit filename="COGLESExtensionHandler.cpp" />
|
||||
|
|
Loading…
Reference in New Issue