aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/engines/direct3d/evas_direct3d_object_rect.cpp
blob: ebdd22be9585ae013736311598cd961c24585141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "evas_direct3d_object_rect.h"
#include "evas_direct3d_device.h"
#include "evas_direct3d_shader_pack.h"

TArray<D3DObjectRect::Vertex> D3DObjectRect::_cache;
bool D3DObjectRect::_cache_enabled = false;

D3DObjectRect::D3DObjectRect()
{
   _x = _y = 0;
   _w = _h = 0;
}

void D3DObjectRect::BeginCache()
{
   _cache.Allocate(0);
   _cache_enabled = true;
}

void D3DObjectRect::EndCache(D3DDevice *d3d)
{
   if (!_cache_enabled || _cache.Length() == 0)
      return;
   D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYC);
   D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_COLOR);
   D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_COLOR);
   d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, _cache.Length() / 3,
      _cache.Data(), sizeof(Vertex));

   DBG("Rect cache drawn: %d items", _cache.Length() / 6);
   _cache_enabled = false;
}

void D3DObjectRect::Draw(D3DDevice *d3d)
{
   Vertex data[6] = {
      {_x, _y, _color}, {_x + _w, _y, _color}, {_x, _y + _h, _color},
      {_x, _y + _h, _color}, {_x + _w, _y, _color}, {_x + _w, _y + _h, _color}};

   if (!_cache_enabled)
   {
      D3DShaderPack::Current()->SetVDecl(d3d, D3DShaderPack::VDECL_XYC);
      D3DShaderPack::Current()->SetVS(d3d, D3DShaderPack::VS_COPY_COLOR);
      D3DShaderPack::Current()->SetPS(d3d, D3DShaderPack::PS_COLOR);
      d3d->GetDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, data, sizeof(Vertex));
   }
   else
   {
      _cache.Add(data[0]);
      _cache.Add(data[1]);
      _cache.Add(data[2]);
      _cache.Add(data[3]);
      _cache.Add(data[4]);
      _cache.Add(data[5]);
   }
}

void D3DObjectRect::Setup(FLOAT x, FLOAT y, FLOAT w, FLOAT h, DWORD color)
{
   _x = x;
   _y = y;
   _w = w;
   _h = h;
   _color = color;
}