Permalink
Browse files

opengl/d3d: add support for limited color levels (16-235)

  • Loading branch information...
1 parent 33b70b2 commit 51ac78a5094b16f8b15e3fd6265ea1a976e539be @elupus committed Feb 21, 2013
@@ -12008,3 +12008,8 @@ msgstr ""
msgctxt "#36041"
msgid "* Item folder"
msgstr ""
+
+#: xbmc/settings/GUISettings.cpp
+msgctxt "#36042"
+msgid "Use limited color range (16-235)"
+msgstr ""
@@ -3187,7 +3187,7 @@ bool CLinuxRendererGL::Supports(ERENDERFEATURE feature)
{
if(feature == RENDERFEATURE_BRIGHTNESS)
{
- if ((m_renderMethod & RENDER_VDPAU) && !g_guiSettings.GetBool("videoplayer.vdpaustudiolevel"))
+ if ((m_renderMethod & RENDER_VDPAU) && !g_guiSettings.GetBool("videoscreen.limitedrange"))
return true;
if (m_renderMethod & RENDER_VAAPI)
@@ -3200,7 +3200,7 @@ bool CLinuxRendererGL::Supports(ERENDERFEATURE feature)
if(feature == RENDERFEATURE_CONTRAST)
{
- if ((m_renderMethod & RENDER_VDPAU) && !g_guiSettings.GetBool("videoplayer.vdpaustudiolevel"))
+ if ((m_renderMethod & RENDER_VDPAU) && !g_guiSettings.GetBool("videoscreen.limitedrange"))
return true;
if (m_renderMethod & RENDER_VAAPI)
@@ -24,6 +24,7 @@
#include "YUV2RGBShader.h"
#include "settings/AdvancedSettings.h"
#include "guilib/TransformMatrix.h"
+#include "windowing/WindowingFactory.h"
#include "utils/log.h"
#if defined(HAS_GL) || defined(HAS_GLES)
#include "utils/GLUtils.h"
@@ -106,8 +107,20 @@ void CalculateYUVMatrix(TransformMatrix &matrix
coef.m[row][col] = conv[col][row];
coef.identity = false;
+
+ if(g_Windowing.UseLimitedColor())
+ {
+ matrix *= TransformMatrix::CreateTranslation(+ 16.0f / 255
+ , + 16.0f / 255
+ , + 16.0f / 255);
+ matrix *= TransformMatrix::CreateScaler((235 - 16) / 255.0f
+ , (235 - 16) / 255.0f
+ , (235 - 16) / 255.0f);
+ }
+
matrix *= coef;
matrix *= TransformMatrix::CreateTranslation(0.0, -0.5, -0.5);
+
if (!(flags & CONF_FLAGS_YUV_FULLRANGE))
{
matrix *= TransformMatrix::CreateScaler(255.0f / (235 - 16)
@@ -1571,7 +1571,10 @@ bool CProcessor::Render(CRect src, CRect dst, IDirect3DSurface9* target, REFEREN
blt.DestFormat.VideoTransferFunction = DXVA2_VideoTransFunc_sRGB;
blt.DestFormat.SampleFormat = DXVA2_SampleProgressiveFrame;
- blt.DestFormat.NominalRange = DXVA2_NominalRange_0_255;
+ if(g_Windowing.UseLimitedColor())
+ blt.DestFormat.NominalRange = DXVA2_NominalRange_16_235;
+ else
+ blt.DestFormat.NominalRange = DXVA2_NominalRange_0_255;
blt.Alpha = DXVA2_Fixed32OpaqueAlpha();
blt.ProcAmpValues.Brightness = ConvertRange( m_brightness, g_settings.m_currentVideoSettings.m_Brightness
@@ -591,7 +591,7 @@ void CVDPAU::SetColor()
vdp_st = vdp_generate_csc_matrix(&m_Procamp, VDP_COLOR_STANDARD_ITUR_BT_601, &m_CSCMatrix);
VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX };
- if (g_guiSettings.GetBool("videoplayer.vdpaustudiolevel"))
+ if (g_guiSettings.GetBool("videoscreen.limitedrange"))
{
void const * pm_CSCMatix[] = { &studioCSC };
vdp_st = vdp_video_mixer_set_attribute_values(videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
View
@@ -27,6 +27,7 @@
#include "utils/MathUtils.h"
#include "utils/log.h"
#include "windowing/WindowingFactory.h"
+#include "settings/GUISettings.h"
#include <math.h>
@@ -735,12 +736,24 @@ void CGUIFontTTFBase::RenderCharacter(float posX, float posY, const Character *c
m_color = color;
SVertex* v = m_vertex + m_vertex_count;
+ unsigned char r = GET_R(color)
+ , g = GET_G(color)
+ , b = GET_B(color)
+ , a = GET_A(color);
+
+ if(g_Windowing.UseLimitedColor())
+ {
+ r = (235 - 16) * r / 255;
+ g = (235 - 16) * g / 255;
+ b = (235 - 16) * b / 255;
+ }
+
for(int i = 0; i < 4; i++)
{
- v[i].r = GET_R(color);
- v[i].g = GET_G(color);
- v[i].b = GET_B(color);
- v[i].a = GET_A(color);
+ v[i].r = r;
+ v[i].g = g;
+ v[i].b = b;
+ v[i].a = a;
}
#if defined(HAS_GL) || defined(HAS_DX)
@@ -57,17 +57,33 @@ void CGUIFontTTFDX::Begin()
if (m_nestedBeginCount == 0)
{
+ int unit = 0;
// just have to blit from our texture.
- m_texture->BindToUnit(0);
- pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); // only use diffuse
- pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
- pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
- pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
- pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
+ m_texture->BindToUnit(unit);
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); // only use diffuse
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
+ unit++;
+
+ if(g_Windowing.UseLimitedColor())
+ {
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_ADD );
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_CURRENT) ;
+#if(1)
+ pD3DDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_RGBA(16,16,16,0) );
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_TFACTOR );
+#else
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_CONSTANT , D3DCOLOR_RGBA(16,16,16,0) );
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_CONSTANT );
+#endif
+ unit++;
+ }
// no other texture stages needed
- pD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
- pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP, D3DTOP_DISABLE);
+ pD3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
pD3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
pD3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
@@ -28,9 +28,7 @@
#include "gui3d.h"
#include "utils/log.h"
#include "utils/GLUtils.h"
-#if HAS_GLES == 2
#include "windowing/WindowingFactory.h"
-#endif
// stuff for freetype
#include <ft2build.h>
@@ -98,6 +96,26 @@ void CGUIFontTTFGL::Begin()
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
VerifyGLState();
+
+ if(g_Windowing.UseLimitedColor())
+ {
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, m_nTexture); // dummy bind
+ glEnable(GL_TEXTURE_2D);
+
+ const GLfloat rgba[4] = {16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 0.0f};
+ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE);
+ glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_ADD);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS);
+ VerifyGLState();
+ }
+
#else
g_Windowing.EnableGUIShader(SM_FONTS);
#endif
@@ -127,6 +145,9 @@ void CGUIFontTTFGL::End()
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_QUADS, 0, m_vertex_count);
glPopClientAttrib();
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glActiveTexture(GL_TEXTURE0);
#else
// GLES 2.0 version. Cannot draw quads. Convert to triangles.
GLint posLoc = g_Windowing.GUIShaderGetPos();
@@ -31,37 +31,58 @@ CGUITextureD3D::CGUITextureD3D(float posX, float posY, float width, float height
void CGUITextureD3D::Begin(color_t color)
{
+ int unit = 0;
CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
LPDIRECT3DDEVICE9 p3DDevice = g_Windowing.Get3DDevice();
texture->LoadToGPU();
if (m_diffuse.size())
m_diffuse.m_textures[0]->LoadToGPU();
// Set state to render the image
- texture->BindToUnit(0);
- p3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
- p3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
- p3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
- p3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
- p3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
- p3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
+ texture->BindToUnit(unit);
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_MODULATE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP , D3DTOP_MODULATE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
+ unit++;
+
if (m_diffuse.size())
{
m_diffuse.m_textures[0]->BindToUnit(1);
- p3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
- p3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
- p3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
- p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
- p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
- p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
- p3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
- p3DDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_CURRENT );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_MODULATE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP , D3DTOP_MODULATE );
+ unit++;
}
- else
+
+ if(g_Windowing.UseLimitedColor())
{
- p3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
- p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
+ m_col = D3DCOLOR_RGBA(GET_R(color) * (235 - 16) / 255
+ , GET_G(color) * (235 - 16) / 255
+ , GET_B(color) * (235 - 16) / 255
+ , GET_A(color));
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_ADD );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_CURRENT) ;
+#if(1)
+ p3DDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_RGBA(16,16,16, 0) );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_TFACTOR );
+#else
+ p3DDevice->SetTextureStageState( unit, D3DTSS_CONSTANT , D3DCOLOR_RGBA(16,16,16, 0) );
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_CONSTANT );
+#endif
+ unit++;
}
+ else
+ m_col = color;
+
+ p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP, D3DTOP_DISABLE);
+ p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
+
p3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
p3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
p3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
@@ -76,7 +97,6 @@ void CGUITextureD3D::Begin(color_t color)
p3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
p3DDevice->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 );
- m_col = color;
}
void CGUITextureD3D::End()
@@ -26,6 +26,7 @@
#include "utils/log.h"
#include "utils/GLUtils.h"
#include "guilib/Geometry.h"
+#include "windowing/WindowingFactory.h"
#if defined(HAS_GL)
@@ -37,17 +38,23 @@ CGUITextureGL::CGUITextureGL(float posX, float posY, float width, float height,
void CGUITextureGL::Begin(color_t color)
{
- m_col[0] = (GLubyte)GET_R(color);
- m_col[1] = (GLubyte)GET_G(color);
- m_col[2] = (GLubyte)GET_B(color);
- m_col[3] = (GLubyte)GET_A(color);
+ int range, unit = 0;
+ if(g_Windowing.UseLimitedColor())
+ range = 235 - 16;
+ else
+ range = 255 - 0;
+
+ m_col[0] = GET_R(color) * range / 255;
+ m_col[1] = GET_G(color) * range / 255;
+ m_col[2] = GET_B(color) * range / 255;
+ m_col[3] = GET_A(color);
CBaseTexture* texture = m_texture.m_textures[m_currentFrame];
texture->LoadToGPU();
if (m_diffuse.size())
m_diffuse.m_textures[0]->LoadToGPU();
- texture->BindToUnit(0);
+ texture->BindToUnit(unit++);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); // Turn Blending On
@@ -70,7 +77,7 @@ void CGUITextureGL::Begin(color_t color)
if (m_diffuse.size())
{
- m_diffuse.m_textures[0]->BindToUnit(1);
+ m_diffuse.m_textures[0]->BindToUnit(unit++);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
@@ -83,9 +90,26 @@ void CGUITextureGL::Begin(color_t color)
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
+ VerifyGLState();
+ }
+ if(g_Windowing.UseLimitedColor())
+ {
+ texture->BindToUnit(unit++); // dummy bind
+ const GLfloat rgba[4] = {16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 0.0f};
+ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE);
+ glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_ADD);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB , GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB , GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB , GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB , GL_SRC_COLOR);
+
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA , GL_REPLACE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA , GL_PREVIOUS);
VerifyGLState();
}
+
//glDisable(GL_TEXTURE_2D); // uncomment these 2 lines to switch to wireframe rendering
//glBegin(GL_LINE_LOOP);
glBegin(GL_QUADS);
@@ -95,10 +119,8 @@ void CGUITextureGL::End()
{
glEnd();
if (m_diffuse.size())
- {
glDisable(GL_TEXTURE_2D);
- glActiveTextureARB(GL_TEXTURE0_ARB);
- }
+ glActiveTexture(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
}
Oops, something went wrong.

0 comments on commit 51ac78a

Please sign in to comment.