Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
45e4a393
Commit
45e4a393
authored
Feb 15, 2019
by
chili
Browse files
static bindables (crashes, but try 1 box only)
parent
b8dbcc7c
Changes
7
Hide whitespace changes
Inline
Side-by-side
hw3d/Box.cpp
View file @
45e4a393
...
...
@@ -20,75 +20,78 @@ Box::Box( Graphics& gfx,
theta
(
adist
(
rng
)
),
phi
(
adist
(
rng
)
)
{
struct
Vertex
if
(
!
IsStaticInitialized
()
)
{
struct
struct
Vertex
{
float
x
;
float
y
;
float
z
;
}
pos
;
};
const
std
::
vector
<
Vertex
>
vertices
=
{
{
-
1.0
f
,
-
1.0
f
,
-
1.0
f
},
{
1.0
f
,
-
1.0
f
,
-
1.0
f
},
{
-
1.0
f
,
1.0
f
,
-
1.0
f
},
{
1.0
f
,
1.0
f
,
-
1.0
f
},
{
-
1.0
f
,
-
1.0
f
,
1.0
f
},
{
1.0
f
,
-
1.0
f
,
1.0
f
},
{
-
1.0
f
,
1.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
};
AddBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
vertices
)
);
struct
{
float
x
;
float
y
;
float
z
;
}
pos
;
};
const
std
::
vector
<
Vertex
>
vertices
=
{
{
-
1.0
f
,
-
1.0
f
,
-
1.0
f
},
{
1.0
f
,
-
1.0
f
,
-
1.0
f
},
{
-
1.0
f
,
1.0
f
,
-
1.0
f
},
{
1.0
f
,
1.0
f
,
-
1.0
f
},
{
-
1.0
f
,
-
1.0
f
,
1.0
f
},
{
1.0
f
,
-
1.0
f
,
1.0
f
},
{
-
1.0
f
,
1.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
1.0
f
},
};
AddStaticBind
(
std
::
make_unique
<
VertexBuffer
>
(
gfx
,
vertices
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"VertexShader.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
AddBind
(
std
::
move
(
pvs
)
);
auto
pvs
=
std
::
make_unique
<
VertexShader
>
(
gfx
,
L"VertexShader.cso"
);
auto
pvsbc
=
pvs
->
GetBytecode
();
Add
Static
Bind
(
std
::
move
(
pvs
)
);
AddBind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"PixelShader.cso"
)
);
Add
Static
Bind
(
std
::
make_unique
<
PixelShader
>
(
gfx
,
L"PixelShader.cso"
)
);
const
std
::
vector
<
unsigned
short
>
indices
=
{
0
,
2
,
1
,
2
,
3
,
1
,
1
,
3
,
5
,
3
,
7
,
5
,
2
,
6
,
3
,
3
,
6
,
7
,
4
,
5
,
7
,
4
,
7
,
6
,
0
,
4
,
2
,
2
,
4
,
6
,
0
,
1
,
4
,
1
,
5
,
4
};
AddIndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
indices
)
);
const
std
::
vector
<
unsigned
short
>
indices
=
{
0
,
2
,
1
,
2
,
3
,
1
,
1
,
3
,
5
,
3
,
7
,
5
,
2
,
6
,
3
,
3
,
6
,
7
,
4
,
5
,
7
,
4
,
7
,
6
,
0
,
4
,
2
,
2
,
4
,
6
,
0
,
1
,
4
,
1
,
5
,
4
};
Add
Static
IndexBuffer
(
std
::
make_unique
<
IndexBuffer
>
(
gfx
,
indices
)
);
struct
ConstantBuffer2
{
struct
struct
ConstantBuffer2
{
float
r
;
float
g
;
float
b
;
float
a
;
}
face_colors
[
6
];
};
const
ConstantBuffer2
cb2
=
{
struct
{
float
r
;
float
g
;
float
b
;
float
a
;
}
face_colors
[
6
];
};
const
ConstantBuffer2
cb2
=
{
{
1.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
0.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
1.0
f
},
}
};
AddBind
(
std
::
make_unique
<
PixelConstantBuffer
<
ConstantBuffer2
>>
(
gfx
,
cb2
)
);
{
{
1.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
0.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
1.0
f
},
}
};
AddStaticBind
(
std
::
make_unique
<
PixelConstantBuffer
<
ConstantBuffer2
>>
(
gfx
,
cb2
)
);
const
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
ied
=
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
AddBind
(
std
::
make_unique
<
InputLayout
>
(
gfx
,
ied
,
pvsbc
)
);
const
std
::
vector
<
D3D11_INPUT_ELEMENT_DESC
>
ied
=
{
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
};
Add
Static
Bind
(
std
::
make_unique
<
InputLayout
>
(
gfx
,
ied
,
pvsbc
)
);
AddBind
(
std
::
make_unique
<
Topology
>
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
AddStaticBind
(
std
::
make_unique
<
Topology
>
(
gfx
,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
)
);
}
AddBind
(
std
::
make_unique
<
TransformCbuf
>
(
gfx
,
*
this
)
);
}
...
...
hw3d/Box.h
View file @
45e4a393
#pragma once
#include "Drawable.h"
#include "Drawable
Base
.h"
class
Box
:
public
Drawable
class
Box
:
public
Drawable
Base
<
Box
>
{
public:
Box
(
Graphics
&
gfx
,
std
::
mt19937
&
rng
,
...
...
hw3d/Drawable.cpp
View file @
45e4a393
...
...
@@ -10,6 +10,10 @@ void Drawable::Draw( Graphics& gfx ) const noexcept(!IS_DEBUG)
{
b
->
Bind
(
gfx
);
}
for
(
auto
&
b
:
GetStaticBinds
()
)
{
b
->
Bind
(
gfx
);
}
gfx
.
DrawIndexed
(
pIndexBuffer
->
GetCount
()
);
}
...
...
@@ -19,9 +23,9 @@ void Drawable::AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG)
binds
.
push_back
(
std
::
move
(
bind
)
);
}
void
Drawable
::
AddIndexBuffer
(
std
::
unique_ptr
<
IndexBuffer
>
ibuf
)
noexcept
void
Drawable
::
AddIndexBuffer
(
std
::
unique_ptr
<
IndexBuffer
>
ibuf
)
noexcept
(
!
IS_DEBUG
)
{
assert
(
"Attempting to add index buffer a second time"
&&
pIndexBuffer
==
nullptr
);
pIndexBuffer
=
ibuf
.
get
();
binds
.
push_back
(
std
::
move
(
ibuf
)
);
}
}
\ No newline at end of file
hw3d/Drawable.h
View file @
45e4a393
...
...
@@ -6,6 +6,8 @@ class Bindable;
class
Drawable
{
template
<
class
T
>
friend
class
DrawableBase
;
public:
Drawable
()
=
default
;
Drawable
(
const
Drawable
&
)
=
delete
;
...
...
@@ -13,9 +15,11 @@ public:
void
Draw
(
Graphics
&
gfx
)
const
noexcept
(
!
IS_DEBUG
);
virtual
void
Update
(
float
dt
)
noexcept
=
0
;
void
AddBind
(
std
::
unique_ptr
<
Bindable
>
bind
)
noexcept
(
!
IS_DEBUG
);
void
AddIndexBuffer
(
std
::
unique_ptr
<
class
IndexBuffer
>
ibuf
)
noexcept
;
void
AddIndexBuffer
(
std
::
unique_ptr
<
class
IndexBuffer
>
ibuf
)
noexcept
(
!
IS_DEBUG
)
;
virtual
~
Drawable
()
=
default
;
private:
const
IndexBuffer
*
pIndexBuffer
=
nullptr
;
virtual
const
std
::
vector
<
std
::
unique_ptr
<
Bindable
>>&
GetStaticBinds
()
const
noexcept
=
0
;
private:
const
class
IndexBuffer
*
pIndexBuffer
=
nullptr
;
std
::
vector
<
std
::
unique_ptr
<
Bindable
>>
binds
;
};
\ No newline at end of file
hw3d/DrawableBase.h
0 → 100644
View file @
45e4a393
#pragma once
#include "Drawable.h"
#include "IndexBuffer.h"
template
<
class
T
>
class
DrawableBase
:
public
Drawable
{
public:
bool
IsStaticInitialized
()
const
noexcept
{
return
!
staticBinds
.
empty
();
}
void
AddStaticBind
(
std
::
unique_ptr
<
Bindable
>
bind
)
noexcept
(
!
IS_DEBUG
)
{
assert
(
"*Must* use AddIndexBuffer to bind index buffer"
&&
typeid
(
*
bind
)
!=
typeid
(
IndexBuffer
)
);
staticBinds
.
push_back
(
std
::
move
(
bind
)
);
}
void
AddStaticIndexBuffer
(
std
::
unique_ptr
<
IndexBuffer
>
ibuf
)
noexcept
(
!
IS_DEBUG
)
{
assert
(
pIndexBuffer
==
nullptr
);
pIndexBuffer
=
ibuf
.
get
();
staticBinds
.
push_back
(
std
::
move
(
ibuf
)
);
}
private:
const
std
::
vector
<
std
::
unique_ptr
<
Bindable
>>&
GetStaticBinds
()
const
noexcept
override
{
return
staticBinds
;
}
private:
static
std
::
vector
<
std
::
unique_ptr
<
Bindable
>>
staticBinds
;
};
template
<
class
T
>
std
::
vector
<
std
::
unique_ptr
<
Bindable
>>
DrawableBase
<
T
>::
staticBinds
;
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
45e4a393
...
...
@@ -179,6 +179,7 @@
<ClInclude
Include=
"ChiliWin.h"
/>
<ClInclude
Include=
"ConstantBuffers.h"
/>
<ClInclude
Include=
"Drawable.h"
/>
<ClInclude
Include=
"DrawableBase.h"
/>
<ClInclude
Include=
"dxerr.h"
/>
<ClInclude
Include=
"DxgiInfoManager.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
45e4a393
...
...
@@ -179,6 +179,9 @@
<ClInclude
Include=
"Box.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
<ClInclude
Include=
"DrawableBase.h"
>
<Filter>
Header Files\Drawable
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment