void CGUIWindowTestPatternDX::DrawRectangle(float x, float y, float x2, float y2, DWORD color) { XMFLOAT4 float4; CD3DHelper::XMStoreColor(&float4, color); Vertex vert[] = { { XMFLOAT3( x, y, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x2, y, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x2, y2, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x2, y2, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x, y2, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3( x, y, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, }; UpdateVertexBuffer(vert, ARRAYSIZE(vert)); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pGUIShader->Draw(ARRAYSIZE(vert), 0); }
void CGUIWindowTestPatternDX::DrawHorizontalLines(int top, int left, int bottom, int right) { Vertex* vert = new Vertex[2 + (bottom - top)]; int p = 0; for (int i = top; i <= bottom; i += 2) { vert[p].pos.x = (float)left; vert[p].pos.y = (float)i; vert[p].pos.z = 0.5f; vert[p].color = XMFLOAT4(m_white, m_white, m_white, 1.0f); ++p; vert[p].pos.x = (float)right; vert[p].pos.y = (float)i; vert[p].pos.z = 0.5f; vert[p].color = XMFLOAT4(m_white, m_white, m_white, 1.0f); ++p; } UpdateVertexBuffer(vert, p); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); pGUIShader->Draw(p, 0); delete [] vert; }
void COverlayImageDX::Render(SRenderState &state) { ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); XMMATRIX world = pGUIShader->GetWorld(); XMMATRIX trans = m_pos == POSITION_RELATIVE ? XMMatrixTranslation(state.x - state.width * 0.5f, state.y - state.height * 0.5f, 0.0f) : XMMatrixTranslation(state.x, state.y, 0.0f), scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = m_vertex.GetStride(); const unsigned offset = 0; ID3D11Buffer* vertexBuffer = m_vertex.Get(); // Set the vertex buffer to active in the input assembler so it can be rendered. pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_NOBLEND); g_Windowing.SetAlphaBlendEnable(true); ID3D11ShaderResourceView* views[] = { m_texture.GetShaderResource() }; pGUIShader->SetShaderViews(1, views); pGUIShader->Draw(6, 0); // restoring transformation pGUIShader->SetWorld(world); pGUIShader->RestoreBuffers(); }
bool CGUIFontTTFDX::FirstBegin() { ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); if (!pContext) return false; CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_FONT); return true; }
void COverlayQuadsDX::Render(SRenderState &state) { if (m_count == 0) return; ID3D11Buffer* vertexBuffer = m_vertex.Get(); if (vertexBuffer == nullptr) return; ID3D11DeviceContext* pContext = DX::DeviceResources::Get()->GetD3DContext(); CGUIShaderDX* pGUIShader = DX::Windowing()->GetGUIShader(); XMMATRIX world, view, proj; pGUIShader->GetWVP(world, view, proj); if (CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode() == RENDER_STEREO_MODE_SPLIT_HORIZONTAL || CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode() == RENDER_STEREO_MODE_SPLIT_VERTICAL) { CRect rect; DX::Windowing()->GetViewPort(rect); DX::Windowing()->SetCameraPosition(CPoint(rect.Width() * 0.5f, rect.Height() * 0.5f), static_cast<int>(rect.Width()), static_cast<int>(rect.Height())); } XMMATRIX trans = XMMatrixTranslation(state.x, state.y, 0.0f); XMMATRIX scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = sizeof(Vertex); const unsigned offset = 0; // Set the vertex buffer to active in the input assembler so it can be rendered. pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); DX::Windowing()->SetAlphaBlendEnable(true); pGUIShader->Begin(SHADER_METHOD_RENDER_FONT); pGUIShader->SetShaderViews(1, m_texture.GetAddressOfSRV()); pGUIShader->Draw(m_count * 6, 0); // restoring transformation pGUIShader->SetWVP(world, view, proj); pGUIShader->RestoreBuffers(); }
void COverlayQuadsDX::Render(SRenderState &state) { if (m_count == 0) return; ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); XMMATRIX world = pGUIShader->GetWorld(); XMMATRIX view = pGUIShader->GetView(); XMMATRIX proj = pGUIShader->GetProjection(); if (g_graphicsContext.GetStereoMode() == RENDER_STEREO_MODE_SPLIT_HORIZONTAL || g_graphicsContext.GetStereoMode() == RENDER_STEREO_MODE_SPLIT_VERTICAL) { CRect rect; g_Windowing.GetViewPort(rect); g_Windowing.SetCameraPosition(CPoint(rect.Width()*0.5f, rect.Height()*0.5f), rect.Width(), rect.Height()); } XMMATRIX trans = XMMatrixTranslation(state.x, state.y, 0.0f); XMMATRIX scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = sizeof(Vertex); const unsigned offset = 0; ID3D11Buffer* vertexBuffer = m_vertex.Get(); // Set the vertex buffer to active in the input assembler so it can be rendered. pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); g_Windowing.SetAlphaBlendEnable(true); pGUIShader->Begin(SHADER_METHOD_RENDER_FONT); ID3D11ShaderResourceView* views[] = { m_texture.GetShaderResource() }; pGUIShader->SetShaderViews(1, views); pGUIShader->Draw(m_count * 6, 0); // restoring transformation pGUIShader->SetWorld(world); pGUIShader->SetView(view); pGUIShader->SetProjection(proj); pGUIShader->RestoreBuffers(); }
void CGUIWindowTestPatternDX::DrawCircleEx(float originX, float originY, float radius, DWORD color) { float angle; float vectorX; float vectorY; float vectorY1 = originY; float vectorX1 = originX; Vertex vert[1084]; // 361*3 + 1 int p = 0; for (int i = 0; i <= 360; i++) { angle = (float)(((double)i)/57.29577957795135); vectorX = originX + (radius*(float)sin((double)angle)); vectorY = originY + (radius*(float)cos((double)angle)); vert[p].pos.x = originX; vert[p].pos.y = originY; vert[p].pos.z = 0.5f; CD3DHelper::XMStoreColor(&vert[p].color, color); ++p; vert[p].pos.x = vectorX1; vert[p].pos.y = vectorY1; vert[p].pos.z = 0.5f; CD3DHelper::XMStoreColor(&vert[p].color, color); ++p; vert[p].pos.x = vectorX; vert[p].pos.y = vectorY; vert[p].pos.z = 0.5f; CD3DHelper::XMStoreColor(&vert[p].color, color); ++p; vectorY1 = vectorY; vectorX1 = vectorX; } vert[1083] = vert[0]; UpdateVertexBuffer(vert, ARRAYSIZE(vert)); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pGUIShader->Draw(ARRAYSIZE(vert), 0); }
void COverlayImageDX::Render(SRenderState &state) { ID3D11Buffer* vertexBuffer = m_vertex.Get(); if (vertexBuffer == nullptr) return; ID3D11DeviceContext* pContext = DX::DeviceResources::Get()->GetD3DContext(); CGUIShaderDX* pGUIShader = DX::Windowing()->GetGUIShader(); XMMATRIX world, view, proj; pGUIShader->GetWVP(world, view, proj); if (CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode() == RENDER_STEREO_MODE_SPLIT_HORIZONTAL || CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode() == RENDER_STEREO_MODE_SPLIT_VERTICAL) { CRect rect; DX::Windowing()->GetViewPort(rect); DX::Windowing()->SetCameraPosition(CPoint(rect.Width() * 0.5f, rect.Height() * 0.5f), static_cast<int>(rect.Width()), static_cast<int>(rect.Height())); } XMMATRIX trans = m_pos == POSITION_RELATIVE ? XMMatrixTranslation(state.x - state.width * 0.5f, state.y - state.height * 0.5f, 0.0f) : XMMatrixTranslation(state.x, state.y, 0.0f), scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = m_vertex.GetStride(); const unsigned offset = 0; pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); pContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_NOBLEND); DX::Windowing()->SetAlphaBlendEnable(true); pGUIShader->SetShaderViews(1, m_texture.GetAddressOfSRV()); pGUIShader->Draw(4, 0); // restoring transformation pGUIShader->SetWVP(world, view, proj); pGUIShader->RestoreBuffers(); }
void COverlayImageDX::Render(SRenderState &state) { ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); XMMATRIX world = pGUIShader->GetWorld(); XMMATRIX view = pGUIShader->GetView(); XMMATRIX proj = pGUIShader->GetProjection(); if (g_graphicsContext.GetStereoMode() == RENDER_STEREO_MODE_SPLIT_HORIZONTAL || g_graphicsContext.GetStereoMode() == RENDER_STEREO_MODE_SPLIT_VERTICAL) { CRect rect; g_Windowing.GetViewPort(rect); g_Windowing.SetCameraPosition(CPoint(rect.Width()*0.5f, rect.Height()*0.5f), rect.Width(), rect.Height()); } XMMATRIX trans = m_pos == POSITION_RELATIVE ? XMMatrixTranslation(state.x - state.width * 0.5f, state.y - state.height * 0.5f, 0.0f) : XMMatrixTranslation(state.x, state.y, 0.0f), scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = m_vertex.GetStride(); const unsigned offset = 0; ID3D11Buffer* vertexBuffer = m_vertex.Get(); pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); pContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_NOBLEND); g_Windowing.SetAlphaBlendEnable(true); ID3D11ShaderResourceView* views[] = { m_texture.GetShaderResource() }; pGUIShader->SetShaderViews(1, views); pGUIShader->Draw(4, 0); // restoring transformation pGUIShader->SetWorld(world); pGUIShader->SetView(view); pGUIShader->SetProjection(proj); pGUIShader->RestoreBuffers(); }
void CD3DTexture::DrawQuad(const CPoint points[4], color_t color, unsigned numViews, ID3D11ShaderResourceView **view, const CRect *texCoords, SHADER_METHOD options) { XMFLOAT4 xcolor; CD3DHelper::XMStoreColor(&xcolor, color); CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f); Vertex verts[4] = { { XMFLOAT3(points[0].x, points[0].y, 0), xcolor, XMFLOAT2(coords.x1, coords.y1), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(points[1].x, points[1].y, 0), xcolor, XMFLOAT2(coords.x2, coords.y1), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(points[2].x, points[2].y, 0), xcolor, XMFLOAT2(coords.x2, coords.y2), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(points[3].x, points[3].y, 0), xcolor, XMFLOAT2(coords.x1, coords.y2), XMFLOAT2(0.0f, 0.0f) }, }; CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(view && numViews > 0 ? options : SHADER_METHOD_RENDER_DEFAULT); if (view && numViews > 0) pGUIShader->SetShaderViews(numViews, view); pGUIShader->DrawQuad(verts[0], verts[1], verts[2], verts[3]); }
void CGUIWindowTestPatternDX::DrawCheckers(int top, int left, int bottom, int right) { int c = (bottom-top+1)*(1+(right-left)/2); if (c < 1) return; Vertex* vert = new Vertex[c]; int i=0; for (int y = top; y <= bottom; y++) { for (int x = left; x <= right; x += 2) { if (y % 2 == 0) { vert[i].pos.x = (float)x; vert[i].pos.y = (float)y; vert[i].pos.z = 0.5f; vert[i].color = XMFLOAT4(m_white, m_white, m_white, 1.0f); } else { vert[i].pos.x = (float)x+1.0f; vert[i].pos.y = (float)y; vert[i].pos.z = 0.5f; vert[i].color = XMFLOAT4(m_white, m_white, m_white, 1.0f); } ++i; } } UpdateVertexBuffer(vert, i); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); pGUIShader->Draw(i, 0); delete [] vert; }
void CGUIWindowTestPatternDX::DrawContrastBrightnessPattern(int top, int left, int bottom, int right) { DWORD color; DWORD color_white = D3DCOLOR_COLORVALUE(m_white, m_white, m_white, 1.0f); DWORD color_black = D3DCOLOR_COLORVALUE(m_black, m_black, m_black, 1.0f); float x5p = (float) (left + (0.05f * (right - left))); float y5p = (float) (top + (0.05f * (bottom - top))); float x12p = (float) (left + (0.125f * (right - left))); float y12p = (float) (top + (0.125f * (bottom - top))); float x25p = (float) (left + (0.25f * (right - left))); float y25p = (float) (top + (0.25f * (bottom - top))); float x37p = (float) (left + (0.375f * (right - left))); float y37p = (float) (top + (0.375f * (bottom - top))); float x50p = (float)(left + (right - left) / 2); float y50p = (float)(top + (bottom - top) / 2); float x62p = (float) (left + (0.625f * (right - left))); float y62p = (float) (top + (0.625f * (bottom - top))); float x75p = (float) (left + (0.75f * (right - left))); float y75p = (float) (top + (0.75f * (bottom - top))); float x87p = (float) (left + (0.875f * (right - left))); float y87p = (float) (top + (0.875f * (bottom - top))); float x95p = (float) (left + (0.95f * (right - left))); float y95p = (float) (top + (0.95f * (bottom - top))); m_blinkFrame = (m_blinkFrame + 1) % TEST_PATTERNS_BLINK_CYCLE; // draw main quadrants DrawRectangle(x50p, (float)top, (float)right, y50p, color_white); DrawRectangle((float)left, (float)y50p, x50p, (float)bottom, color_white); XMFLOAT4 xcolor_white, xcolor_black; CD3DHelper::XMStoreColor(&xcolor_white, color_white); CD3DHelper::XMStoreColor(&xcolor_black, color_black); // draw border lines Vertex vert[] = { { XMFLOAT3((float)left, y5p, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x50p, y5p, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x5p, (float)top, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x5p, y50p, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x50p, y95p, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3((float)right, y95p, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x95p, y50p, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x95p, (float)bottom, 0.5f), xcolor_white, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x50p, y5p, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3((float)right, y5p, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x5p, y50p, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x5p, (float)bottom, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3((float)left, y95p, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x50p, y95p, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x95p, (float)top, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x95p, y50p, 0.5f), xcolor_black, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, }; UpdateVertexBuffer(vert, ARRAYSIZE(vert)); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); pGUIShader->Draw(ARRAYSIZE(vert), 0); // draw inner rectangles DrawRectangle(x12p, y12p, x37p, y37p, color_white); DrawRectangle(x62p, y62p, x87p, y87p, color_white); DrawRectangle(x62p, y12p, x87p, y37p, color_black); DrawRectangle(x12p, y62p, x37p, y87p, color_black); // draw inner circles if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2) color = D3DCOLOR_COLORVALUE(m_black + 0.05f, m_black + 0.05f, m_black + 0.05f, 1.0f); else color = D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0f, 1.0f); // BTB DrawCircleEx(x25p, y75p, (y37p - y12p) / 3, color); DrawCircleEx(x75p, y25p, (y37p - y12p) / 3, color); if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2) color = D3DCOLOR_COLORVALUE(m_white - 0.05f, m_white - 0.05f, m_white - 0.05f, 1.0f); else color = D3DCOLOR_COLORVALUE(1.0f, 1.0f, 1.0f, 1.0f); // WTW DrawCircleEx(x25p, y25p, (y37p - y12p) / 3, color); DrawCircleEx(x75p, y75p, (y37p - y12p) / 3, color); }
void CGUITextureD3D::Draw(float *x, float *y, float *z, const CRect &texture, const CRect &diffuse, int orientation) { XMFLOAT4 xcolor; CD3DHelper::XMStoreColor(&xcolor, m_col); Vertex verts[4]; verts[0].pos.x = x[0]; verts[0].pos.y = y[0]; verts[0].pos.z = z[0]; verts[0].texCoord.x = texture.x1; verts[0].texCoord.y = texture.y1; verts[0].texCoord2.x = diffuse.x1; verts[0].texCoord2.y = diffuse.y1; verts[0].color = xcolor; verts[1].pos.x = x[1]; verts[1].pos.y = y[1]; verts[1].pos.z = z[1]; if (orientation & 4) { verts[1].texCoord.x = texture.x1; verts[1].texCoord.y = texture.y2; } else { verts[1].texCoord.x = texture.x2; verts[1].texCoord.y = texture.y1; } if (m_info.orientation & 4) { verts[1].texCoord2.x = diffuse.x1; verts[1].texCoord2.y = diffuse.y2; } else { verts[1].texCoord2.x = diffuse.x2; verts[1].texCoord2.y = diffuse.y1; } verts[1].color = xcolor; verts[2].pos.x = x[2]; verts[2].pos.y = y[2]; verts[2].pos.z = z[2]; verts[2].texCoord.x = texture.x2; verts[2].texCoord.y = texture.y2; verts[2].texCoord2.x = diffuse.x2; verts[2].texCoord2.y = diffuse.y2; verts[2].color = xcolor; verts[3].pos.x = x[3]; verts[3].pos.y = y[3]; verts[3].pos.z = z[3]; if (orientation & 4) { verts[3].texCoord.x = texture.x2; verts[3].texCoord.y = texture.y1; } else { verts[3].texCoord.x = texture.x1; verts[3].texCoord.y = texture.y2; } if (m_info.orientation & 4) { verts[3].texCoord2.x = diffuse.x2; verts[3].texCoord2.y = diffuse.y1; } else { verts[3].texCoord2.x = diffuse.x1; verts[3].texCoord2.y = diffuse.y2; } verts[3].color = xcolor; CDXTexture* tex = (CDXTexture *)m_texture.m_textures[m_currentFrame]; CGUIShaderDX* pGUIShader = DX::Windowing().GetGUIShader(); pGUIShader->Begin(m_diffuse.size() ? SHADER_METHOD_RENDER_MULTI_TEXTURE_BLEND : SHADER_METHOD_RENDER_TEXTURE_BLEND); if (m_diffuse.size()) { CDXTexture* diff = (CDXTexture *)m_diffuse.m_textures[0]; ID3D11ShaderResourceView* resource[] = { tex->GetShaderResource(), diff->GetShaderResource() }; pGUIShader->SetShaderViews(ARRAYSIZE(resource), resource); } else { ID3D11ShaderResourceView* resource = tex->GetShaderResource(); pGUIShader->SetShaderViews(1, &resource); } pGUIShader->DrawQuad(verts[0], verts[1], verts[2], verts[3]); }
void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, UTILS::Color color) { #ifdef HAS_DX Vertex vertex[5]; for (int i = 0; i < 4; i++) { vertex[i].pos = XMFLOAT3( x[i], y[i], 0); CD3DHelper::XMStoreColor(&vertex[i].color, color); vertex[i].texCoord = XMFLOAT2(0.0f, 0.0f); vertex[i].texCoord2 = XMFLOAT2(0.0f, 0.0f); } if (pTexture) { vertex[1].texCoord.x = vertex[2].texCoord.x = (float) pTexture->GetWidth() / pTexture->GetTextureWidth(); vertex[2].texCoord.y = vertex[3].texCoord.y = (float) pTexture->GetHeight() / pTexture->GetTextureHeight(); } else { vertex[1].texCoord.x = vertex[2].texCoord.x = 1.0f; vertex[2].texCoord.y = vertex[3].texCoord.y = 1.0f; } vertex[4] = vertex[0]; // Not used when pTexture != NULL CGUIShaderDX* pGUIShader = DX::Windowing()->GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND); // Set state to render the image if (pTexture) { pTexture->LoadToGPU(); CDXTexture* dxTexture = reinterpret_cast<CDXTexture*>(pTexture); ID3D11ShaderResourceView* shaderRes = dxTexture->GetShaderResource(); pGUIShader->SetShaderViews(1, &shaderRes); pGUIShader->DrawQuad(vertex[0], vertex[1], vertex[2], vertex[3]); } else { if (!UpdateVertexBuffer(vertex)) return; ComPtr<ID3D11DeviceContext> pContext = DX::DeviceResources::Get()->GetD3DContext(); unsigned stride = sizeof(Vertex); unsigned offset = 0; pContext->IASetVertexBuffers(0, 1, m_vb.GetAddressOf(), &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); pGUIShader->Draw(5, 0); pGUIShader->RestoreBuffers(); } #elif defined(HAS_GL) CRenderSystemGL *renderSystem = dynamic_cast<CRenderSystemGL*>(CServiceBroker::GetRenderSystem()); if (pTexture) { pTexture->LoadToGPU(); pTexture->BindToUnit(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); renderSystem->EnableShader(SM_TEXTURE); } else { renderSystem->EnableShader(SM_DEFAULT); } float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } GLubyte colour[4]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of the vertices GLuint vertexVBO; GLuint indexVBO; struct PackedVertex { float x, y, z; float u1, v1; } vertex[4]; // Setup vertex position values vertex[0].x = x[0]; vertex[0].y = y[0]; vertex[0].z = 0; vertex[0].u1 = u1; vertex[0].v1 = v1; vertex[1].x = x[1]; vertex[1].y = y[1]; vertex[1].z = 0; vertex[1].u1 = u2; vertex[1].v1 = v1; vertex[2].x = x[2]; vertex[2].y = y[2]; vertex[2].z = 0; vertex[2].u1 = u2; vertex[2].v1 = v2; vertex[3].x = x[3]; vertex[3].y = y[3]; vertex[3].z = 0; vertex[3].u1 = u1; vertex[3].v1 = v2; GLint posLoc = renderSystem->ShaderGetPos(); GLint tex0Loc = renderSystem->ShaderGetCoord0(); GLint uniColLoc= renderSystem->ShaderGetUniCol(); glGenBuffers(1, &vertexVBO); glBindBuffer(GL_ARRAY_BUFFER, vertexVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(PackedVertex)*4, &vertex[0], GL_STATIC_DRAW); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, x))); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, u1))); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); // Setup Colour values colour[0] = (GLubyte)GET_R(color); colour[1] = (GLubyte)GET_G(color); colour[2] = (GLubyte)GET_B(color); colour[3] = (GLubyte)GET_A(color); glUniform4f(uniColLoc,(colour[0] / 255.0f), (colour[1] / 255.0f), (colour[2] / 255.0f), (colour[3] / 255.0f)); glGenBuffers(1, &indexVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*4, idx, GL_STATIC_DRAW); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, 0); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &vertexVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDeleteBuffers(1, &indexVBO); renderSystem->DisableShader(); #elif defined(HAS_GLES) CRenderSystemGLES *renderSystem = dynamic_cast<CRenderSystemGLES*>(CServiceBroker::GetRenderSystem()); if (pTexture) { pTexture->LoadToGPU(); pTexture->BindToUnit(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On renderSystem->EnableGUIShader(SM_TEXTURE); } else { renderSystem->EnableGUIShader(SM_DEFAULT); } float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } GLubyte col[4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip GLint posLoc = renderSystem->GUIShaderGetPos(); GLint tex0Loc = renderSystem->GUIShaderGetCoord0(); GLint uniColLoc= renderSystem->GUIShaderGetUniCol(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); // Setup Colour values col[0] = (GLubyte)GET_R(color); col[1] = (GLubyte)GET_G(color); col[2] = (GLubyte)GET_B(color); col[3] = (GLubyte)GET_A(color); if (CServiceBroker::GetWinSystem()->UseLimitedColor()) { col[0] = (235 - 16) * col[0] / 255 + 16; col[1] = (235 - 16) * col[1] / 255 + 16; col[2] = (235 - 16) * col[2] / 255 + 16; } for (int i=0; i<4; i++) { // Setup vertex position values ver[i][0] = x[i]; ver[i][1] = y[i]; ver[i][2] = 0.0f; } // Setup texture coordinates tex[0][0] = tex[3][0] = u1; tex[0][1] = tex[1][1] = v1; tex[1][0] = tex[2][0] = u2; tex[2][1] = tex[3][1] = v2; glUniform4f(uniColLoc,(col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), (col[3] / 255.0f)); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); renderSystem->DisableGUIShader(); #endif }
void CSlideShowPic::Render(float *x, float *y, CBaseTexture* pTexture, color_t color) { #ifdef HAS_DX static const DWORD FVF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; Vertex vertex[5]; for (int i = 0; i < 4; i++) { vertex[i].pos = XMFLOAT3( x[i], y[i], 0); CD3DHelper::XMStoreColor(&vertex[i].color, color); vertex[i].texCoord = XMFLOAT2(0.0f, 0.0f); vertex[i].texCoord2 = XMFLOAT2(0.0f, 0.0f); } if (pTexture) { vertex[1].texCoord.x = vertex[2].texCoord.x = (float) pTexture->GetWidth() / pTexture->GetTextureWidth(); vertex[2].texCoord.y = vertex[3].texCoord.y = (float) pTexture->GetHeight() / pTexture->GetTextureHeight(); } else { vertex[1].texCoord.x = vertex[2].texCoord.x = 1.0f; vertex[2].texCoord.y = vertex[3].texCoord.y = 1.0f; } vertex[4] = vertex[0]; // Not used when pTexture != NULL CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_BLEND); // Set state to render the image if (pTexture) { pTexture->LoadToGPU(); CDXTexture* dxTexture = reinterpret_cast<CDXTexture*>(pTexture); ID3D11ShaderResourceView* shaderRes = dxTexture->GetShaderResource(); pGUIShader->SetShaderViews(1, &shaderRes); pGUIShader->DrawQuad(vertex[0], vertex[1], vertex[2], vertex[3]); } else { if (!UpdateVertexBuffer(vertex)) return; ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); unsigned stride = sizeof(Vertex); unsigned offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); pGUIShader->Draw(5, 0); pGUIShader->RestoreBuffers(); } #elif defined(HAS_GL) if (pTexture) { int unit = 0; pTexture->LoadToGPU(); pTexture->BindToUnit(unit++); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On // diffuse coloring 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_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); if(g_Windowing.UseLimitedColor()) { // compress range pTexture->BindToUnit(unit++); // dummy bind const GLfloat rgba1[4] = {(235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, (235.0 - 16.0f) / 255.0f, 1.0f}; glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba1); glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB , GL_MODULATE); 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); // transition pTexture->BindToUnit(unit++); // dummy bind const GLfloat rgba2[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, rgba2); 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); } } else glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, pTexture ? GL_FILL : GL_LINE); glBegin(GL_QUADS); float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u1, v1); glVertex3f(x[0], y[0], 0); // Bottom-left vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u2, v1); glVertex3f(x[1], y[1], 0); // Bottom-right vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u2, v2); glVertex3f(x[2], y[2], 0); // Top-right vertex (corner) glColor4ub((GLubyte)GET_R(color), (GLubyte)GET_G(color), (GLubyte)GET_B(color), (GLubyte)GET_A(color)); glTexCoord2f(u1, v2); glVertex3f(x[3], y[3], 0); glEnd(); #elif defined(HAS_GLES) if (pTexture) { pTexture->LoadToGPU(); pTexture->BindToUnit(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On g_Windowing.EnableGUIShader(SM_TEXTURE); } else { glDisable(GL_TEXTURE_2D); g_Windowing.EnableGUIShader(SM_DEFAULT); } float u1 = 0, u2 = 1, v1 = 0, v2 = 1; if (pTexture) { u2 = (float)pTexture->GetWidth() / pTexture->GetTextureWidth(); v2 = (float)pTexture->GetHeight() / pTexture->GetTextureHeight(); } GLubyte col[4]; GLfloat ver[4][3]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip GLint posLoc = g_Windowing.GUIShaderGetPos(); GLint tex0Loc = g_Windowing.GUIShaderGetCoord0(); GLint uniColLoc= g_Windowing.GUIShaderGetUniCol(); glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); // Setup Colour values col[0] = (GLubyte)GET_R(color); col[1] = (GLubyte)GET_G(color); col[2] = (GLubyte)GET_B(color); col[3] = (GLubyte)GET_A(color); for (int i=0; i<4; i++) { // Setup vertex position values ver[i][0] = x[i]; ver[i][1] = y[i]; ver[i][2] = 0.0f; } // Setup texture coordinates tex[0][0] = tex[3][0] = u1; tex[0][1] = tex[1][1] = v1; tex[1][0] = tex[2][0] = u2; tex[2][1] = tex[3][1] = v2; glUniform4f(uniColLoc,(col[0] / 255.0f), (col[1] / 255.0f), (col[2] / 255.0f), (col[3] / 255.0f)); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); g_Windowing.DisableGUIShader(); #else // SDL render g_Windowing.BlitToScreen(m_pImage, NULL, NULL); #endif }