fix up the rest of the GL code, add glew to project, add makefiles for opengl, fix makefiles so that it can be built with gcc, update project files to automatically output to the build directory

This commit is contained in:
jp9000
2013-10-16 23:31:18 -07:00
parent 0dfc844abc
commit dfa2dc6eab
40 changed files with 937 additions and 389 deletions

View File

@@ -33,14 +33,14 @@ EXPORT uint32_t device_getwidth(device_t device);
EXPORT uint32_t device_getheight(device_t device);
EXPORT texture_t device_create_texture(device_t device, uint32_t width,
uint32_t height, enum gs_color_format color_format,
uint32_t levels, void **data, uint32_t flags);
uint32_t levels, const void **data, uint32_t flags);
EXPORT texture_t device_create_cubetexture(device_t device, uint32_t size,
enum gs_color_format color_format, uint32_t levels,
void **data, uint32_t flags);
const void **data, uint32_t flags);
EXPORT texture_t device_create_volumetexture(device_t device, uint32_t width,
uint32_t height, uint32_t depth,
enum gs_color_format color_format, uint32_t levels, void **data,
uint32_t flags);
enum gs_color_format color_format, uint32_t levels,
const void **data, uint32_t flags);
EXPORT zstencil_t device_create_zstencil(device_t device, uint32_t width,
uint32_t height, enum gs_zstencil_format format);
EXPORT stagesurf_t device_create_stagesurface(device_t device, uint32_t width,
@@ -124,8 +124,6 @@ EXPORT void device_ortho(device_t device, float left, float right,
float top, float bottom, float znear, float zfar);
EXPORT void device_frustum(device_t device, float left, float right,
float top, float bottom, float znear, float zfar);
EXPORT void device_perspective(device_t device, float fovy, float aspect,
float znear, float zfar);
EXPORT void device_projection_push(device_t device);
EXPORT void device_projection_pop(device_t device);

View File

@@ -18,27 +18,43 @@
#include "d3d11-subsystem.hpp"
#include "graphics/vec4.h"
const D3D11_TEXTURE_ADDRESS_MODE convertAddressMode[] =
static inline D3D11_TEXTURE_ADDRESS_MODE ConvertGSAddressMode(
gs_address_mode mode)
{
D3D11_TEXTURE_ADDRESS_CLAMP,
D3D11_TEXTURE_ADDRESS_WRAP,
D3D11_TEXTURE_ADDRESS_MIRROR,
D3D11_TEXTURE_ADDRESS_BORDER,
D3D11_TEXTURE_ADDRESS_MIRROR_ONCE
};
const D3D11_FILTER convertFilter[] =
switch (mode) {
default:
case GS_ADDRESS_WRAP: return D3D11_TEXTURE_ADDRESS_WRAP;
case GS_ADDRESS_CLAMP: return D3D11_TEXTURE_ADDRESS_CLAMP;
case GS_ADDRESS_MIRROR: return D3D11_TEXTURE_ADDRESS_MIRROR;
case GS_ADDRESS_BORDER: return D3D11_TEXTURE_ADDRESS_BORDER;
case GS_ADDRESS_MIRRORONCE: return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE;
}
}
static inline D3D11_FILTER ConvertGSFilter( gs_sample_filter filter)
{
D3D11_FILTER_MIN_MAG_MIP_LINEAR,
D3D11_FILTER_MIN_MAG_MIP_POINT,
D3D11_FILTER_ANISOTROPIC,
D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR,
D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT,
D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR,
D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT,
D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT
};
switch (filter) {
default:
case GS_FILTER_POINT:
return D3D11_FILTER_MIN_MAG_MIP_POINT;
case GS_FILTER_LINEAR:
return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
case GS_FILTER_MIN_MAG_POINT_MIP_LINEAR:
return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
case GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT:
return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
case GS_FILTER_MIN_POINT_MAG_MIP_LINEAR:
return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
case GS_FILTER_MIN_LINEAR_MAG_MIP_POINT:
return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
case GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR:
return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
case GS_FILTER_MIN_MAG_LINEAR_MIP_POINT:
return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
case GS_FILTER_ANISOTROPIC:
return D3D11_FILTER_ANISOTROPIC;
}
}
gs_sampler_state::gs_sampler_state(device_t device, gs_sampler_info *info)
: device (device),
@@ -49,11 +65,11 @@ gs_sampler_state::gs_sampler_state(device_t device, gs_sampler_info *info)
vec4 v4;
memset(&sd, 0, sizeof(sd));
sd.AddressU = convertAddressMode[(uint32_t)info->address_u];
sd.AddressV = convertAddressMode[(uint32_t)info->address_v];
sd.AddressW = convertAddressMode[(uint32_t)info->address_w];
sd.AddressU = ConvertGSAddressMode(info->address_u);
sd.AddressV = ConvertGSAddressMode(info->address_v);
sd.AddressW = ConvertGSAddressMode(info->address_w);
sd.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
sd.Filter = convertFilter[(uint32_t)info->filter];
sd.Filter = ConvertGSFilter(info->filter);
sd.MaxAnisotropy = info->max_anisotropy;
sd.MaxLOD = FLT_MAX;

View File

@@ -232,10 +232,12 @@ ID3D11RasterizerState *gs_device::AddRasterState()
ID3D11RasterizerState *state;
memset(&rd, 0, sizeof(rd));
rd.FillMode = D3D11_FILL_SOLID;
rd.CullMode = ConvertGSCullMode(rasterState.cullMode);
rd.DepthClipEnable = true;
rd.ScissorEnable = rasterState.scissorEnabled;
/* use CCW to convert to for a right-handed coordinate system */
rd.FrontCounterClockwise = true;
rd.FillMode = D3D11_FILL_SOLID;
rd.CullMode = ConvertGSCullMode(rasterState.cullMode);
rd.DepthClipEnable = true;
rd.ScissorEnable = rasterState.scissorEnabled;
hr = device->CreateRasterizerState(&rd, savedState.state.Assign());
if (FAILED(hr))
@@ -364,6 +366,13 @@ void gs_device::UpdateViewProjMatrix()
gs_matrix_get(&cur_matrix);
matrix4_from_matrix3(&curViewMatrix, &cur_matrix);
/* negate Z col of the view matrix for right-handed coordinate system */
curViewMatrix.x.z = -curViewMatrix.x.z;
curViewMatrix.y.z = -curViewMatrix.y.z;
curViewMatrix.z.z = -curViewMatrix.z.z;
curViewMatrix.t.z = -curViewMatrix.t.z;
matrix4_mul(&curViewProjMatrix, &curViewMatrix, &curProjMatrix);
matrix4_transpose(&curViewProjMatrix, &curViewProjMatrix);
@@ -490,7 +499,7 @@ uint32_t device_getheight(device_t device)
texture_t device_create_texture(device_t device, uint32_t width,
uint32_t height, enum gs_color_format color_format,
uint32_t levels, void **data, uint32_t flags)
uint32_t levels, const void **data, uint32_t flags)
{
gs_texture *texture = NULL;
try {
@@ -508,8 +517,8 @@ texture_t device_create_texture(device_t device, uint32_t width,
}
texture_t device_create_cubetexture(device_t device, uint32_t size,
enum gs_color_format color_format, uint32_t levels, void **data,
uint32_t flags)
enum gs_color_format color_format, uint32_t levels,
const void **data, uint32_t flags)
{
gs_texture *texture = NULL;
try {
@@ -531,7 +540,7 @@ texture_t device_create_cubetexture(device_t device, uint32_t size,
texture_t device_create_volumetexture(device_t device, uint32_t width,
uint32_t height, uint32_t depth,
enum gs_color_format color_format, uint32_t levels,
void **data, uint32_t flags)
const void **data, uint32_t flags)
{
/* TODO */
return NULL;
@@ -884,14 +893,14 @@ void device_setrendertarget(device_t device, texture_t tex, zstencil_t zstencil)
if (tex->type != GS_TEXTURE_2D) {
blog(LOG_ERROR, "device_setrendertarget (D3D11): "
"texture is not a 2D texture");
"texture is not a 2D texture");
return;
}
gs_texture_2d *tex2d = static_cast<gs_texture_2d*>(tex);
if (!tex2d->renderTarget[0]) {
blog(LOG_ERROR, "device_setrendertarget (D3D11): "
"texture is not a render target");
"texture is not a render target");
return;
}
@@ -942,8 +951,6 @@ void device_setcuberendertarget(device_t device, texture_t tex, int side,
inline void gs_device::CopyTex(ID3D11Texture2D *dst, texture_t src)
{
if (!src)
src = curRenderTarget;
if (src->type != GS_TEXTURE_2D)
throw "Source texture must be a 2D texture";
@@ -954,10 +961,22 @@ inline void gs_device::CopyTex(ID3D11Texture2D *dst, texture_t src)
void device_copy_texture(device_t device, texture_t dst, texture_t src)
{
try {
gs_texture_2d *src2d = static_cast<gs_texture_2d*>(src);
gs_texture_2d *dst2d = static_cast<gs_texture_2d*>(dst);
if (!src)
throw "Source texture is NULL";
if (!dst)
throw "Failed because destination texture is NULL";
if (dst->type != GS_TEXTURE_2D)
throw "Destination texture must be a 2D texture";
throw "Destination texture is NULL";
if (src->type != GS_TEXTURE_2D || dst->type != GS_TEXTURE_2D)
throw "Source and destination textures must be a 2D "
"textures";
if (dst->format != src->format)
throw "Source and destination formats do not match";
if (dst2d->width != src2d->width ||
dst2d->height != src2d->height)
throw "Source and destination must have the same "
"dimensions";
gs_texture_2d *tex2d = static_cast<gs_texture_2d*>(dst);
device->CopyTex(tex2d->texture, src);
@@ -970,8 +989,20 @@ void device_copy_texture(device_t device, texture_t dst, texture_t src)
void device_stage_texture(device_t device, stagesurf_t dst, texture_t src)
{
try {
gs_texture_2d *src2d = static_cast<gs_texture_2d*>(src);
if (!src)
throw "Source texture is NULL";
if (src->type != GS_TEXTURE_2D)
throw "Source texture must be a 2D texture";
if (!dst)
throw "Failed because destination texture is NULL";
throw "Destination surface is NULL";
if (dst->format != src->format)
throw "Source and destination formats do not match";
if (dst->width != src2d->width ||
dst->height != src2d->height)
throw "Source and destination must have the same "
"dimensions";
device->CopyTex(dst->texture, src);
@@ -1025,13 +1056,15 @@ void device_draw(device_t device, enum gs_draw_mode draw_mode,
device->curToplogy = newTopology;
}
if (num_verts == 0)
num_verts = (uint32_t)device->curVertexBuffer->numVerts;
if (device->curIndexBuffer)
if (device->curIndexBuffer) {
if (num_verts == 0)
num_verts = (uint32_t)device->curIndexBuffer->num;
device->context->DrawIndexed(num_verts, start_vert, 0);
else
} else {
if (num_verts == 0)
num_verts = (uint32_t)device->curVertexBuffer->numVerts;
device->context->Draw(num_verts, start_vert);
}
}
void device_endscene(device_t device)
@@ -1292,23 +1325,56 @@ void device_setscissorrect(device_t device, struct gs_rect *rect)
}
void device_ortho(device_t device, float left, float right, float top,
float bottom, float znear, float zfar)
float bottom, float zNear, float zFar)
{
matrix4_ortho(&device->curProjMatrix, left, right, top, bottom, znear,
zfar);
matrix4 *dst = &device->curProjMatrix;
float rml = right-left;
float bmt = bottom-top;
float fmn = zFar-zNear;
vec4_zero(&dst->x);
vec4_zero(&dst->y);
vec4_zero(&dst->z);
vec4_zero(&dst->t);
dst->x.x = 2.0f / rml;
dst->t.x = (left+right) / -rml;
dst->y.y = 2.0f / -bmt;
dst->t.y = (bottom+top) / bmt;
dst->z.z = 1.0f / fmn;
dst->t.z = zNear / -fmn;
dst->t.w = 1.0f;
}
void device_frustum(device_t device, float left, float right, float top,
float bottom, float znear, float zfar)
float bottom, float zNear, float zFar)
{
matrix4_frustum(&device->curProjMatrix, left, right, top, bottom,
znear, zfar);
}
matrix4 *dst = &device->curProjMatrix;
void device_perspective(device_t device, float fovy, float aspect,
float znear, float zfar)
{
matrix4_perspective(&device->curProjMatrix, fovy, aspect, znear, zfar);
float rml = right-left;
float bmt = bottom-top;
float fmn = zFar-zNear;
float nearx2 = 2.0f*zNear;
vec4_zero(&dst->x);
vec4_zero(&dst->y);
vec4_zero(&dst->z);
vec4_zero(&dst->t);
dst->x.x = nearx2 / rml;
dst->z.x = (left+right) / -rml;
dst->y.y = nearx2 / -bmt;
dst->z.y = (bottom+top) / bmt;
dst->z.z = zFar / fmn;
dst->t.z = (zNear*zFar) / -fmn;
dst->z.w = 1.0f;
}
void device_projection_push(device_t device)

View File

@@ -221,14 +221,16 @@ struct gs_texture {
gs_texture_type type;
gs_device *device;
uint32_t levels;
gs_color_format format;
ComPtr<ID3D11ShaderResourceView> shaderRes;
inline gs_texture(gs_device *device, gs_texture_type type,
uint32_t levels)
uint32_t levels, gs_color_format format)
: device (device),
type (type),
levels (levels)
levels (levels),
format (format)
{
}
@@ -241,7 +243,6 @@ struct gs_texture_2d : gs_texture {
ComPtr<IDXGISurface1> gdiSurface;
uint32_t width, height;
gs_color_format format;
DXGI_FORMAT dxgiFormat;
bool isRenderTarget;
bool isGDICompatible;
@@ -250,16 +251,15 @@ struct gs_texture_2d : gs_texture {
bool genMipmaps;
HANDLE sharedHandle;
void InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd, void **data);
void InitTexture(void **data);
void InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd, const void **data);
void InitTexture(const void **data);
void InitResourceView();
void InitRenderTargets();
inline gs_texture_2d()
: gs_texture (NULL, GS_TEXTURE_2D, 0),
: gs_texture (NULL, GS_TEXTURE_2D, 0, GS_UNKNOWN),
width (0),
height (0),
format (GS_UNKNOWN),
dxgiFormat (DXGI_FORMAT_UNKNOWN),
isRenderTarget (false),
isGDICompatible (false),
@@ -272,7 +272,7 @@ struct gs_texture_2d : gs_texture {
gs_texture_2d(device_t device, uint32_t width, uint32_t height,
gs_color_format colorFormat, uint32_t levels,
void **data, uint32_t flags, gs_texture_type type,
const void **data, uint32_t flags, gs_texture_type type,
bool gdiCompatible, bool shared);
};

View File

@@ -18,7 +18,8 @@
#include "util/base.h"
#include "d3d11-subsystem.hpp"
void gs_texture_2d::InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd, void **data)
void gs_texture_2d::InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd,
const void **data)
{
uint32_t rowSizeBytes = width * gs_get_format_bpp(format);
uint32_t texSizeBytes = height * rowSizeBytes / 8;
@@ -48,7 +49,7 @@ void gs_texture_2d::InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd, void **data)
}
}
void gs_texture_2d::InitTexture(void **data)
void gs_texture_2d::InitTexture(const void **data)
{
vector<D3D11_SUBRESOURCE_DATA> srd;
D3D11_TEXTURE2D_DESC td;
@@ -131,13 +132,12 @@ void gs_texture_2d::InitRenderTargets()
}
gs_texture_2d::gs_texture_2d(device_t device, uint32_t width, uint32_t height,
gs_color_format colorFormat, uint32_t levels, void **data,
gs_color_format colorFormat, uint32_t levels, const void **data,
uint32_t flags, gs_texture_type type, bool gdiCompatible,
bool shared)
: gs_texture (device, type, levels),
: gs_texture (device, type, levels, colorFormat),
width (width),
height (height),
format (colorFormat),
dxgiFormat (ConvertGSTextureFormat(format)),
isGDICompatible (gdiCompatible),
isShared (shared),