added z-stencil buffers to GL and made a GS_MAX_TEXTURES macro

master
jp9000 2013-10-10 12:37:03 -07:00
parent 904725390a
commit c1939de49b
10 changed files with 104 additions and 26 deletions

View File

@ -397,7 +397,7 @@ gs_device::gs_device(gs_init_data *data)
memset(&viewport, 0, sizeof(viewport));
for (size_t i = 0; i < MAX_TEXTURES; i++) {
for (size_t i = 0; i < GS_MAX_TEXTURES; i++) {
curTextures[i] = NULL;
curSamplers[i] = NULL;
}
@ -789,17 +789,17 @@ void device_load_vertexshader(device_t device, shader_t vertshader)
static inline void clear_textures(device_t device)
{
ID3D11ShaderResourceView *views[MAX_TEXTURES];
ID3D11ShaderResourceView *views[GS_MAX_TEXTURES];
memset(views, 0, sizeof(views));
memset(device->curTextures, 0, sizeof(device->curTextures));
device->context->PSSetShaderResources(0, MAX_TEXTURES, views);
device->context->PSSetShaderResources(0, GS_MAX_TEXTURES, views);
}
void device_load_pixelshader(device_t device, shader_t pixelshader)
{
ID3D11PixelShader *shader = NULL;
ID3D11Buffer *constants = NULL;
ID3D11SamplerState *states[MAX_TEXTURES];
ID3D11SamplerState *states[GS_MAX_TEXTURES];
if (device->curPixelShader == pixelshader)
return;
@ -825,7 +825,7 @@ void device_load_pixelshader(device_t device, shader_t pixelshader)
device->curPixelShader = ps;
device->context->PSSetShader(shader, NULL, 0);
device->context->PSSetConstantBuffers(0, 1, &constants);
device->context->PSSetSamplers(0, MAX_TEXTURES, states);
device->context->PSSetSamplers(0, GS_MAX_TEXTURES, states);
}
void device_load_defaultsamplerstate(device_t device, bool b_3d,

View File

@ -47,8 +47,6 @@ using namespace std;
* "public" and "private" does not matter at all for this subproject.
*/
#define MAX_TEXTURES 8
static inline uint32_t GetWinVer()
{
OSVERSIONINFO ovi;
@ -420,7 +418,7 @@ struct gs_pixel_shader : gs_shader {
size_t i;
for (i = 0; i < samplers.size(); i++)
states[i] = samplers[i].sampler.state;
for (; i < MAX_TEXTURES; i++)
for (; i < GS_MAX_TEXTURES; i++)
states[i] = NULL;
}
@ -574,8 +572,8 @@ struct gs_device {
gs_texture_2d *curRenderTarget;
gs_zstencil_buffer *curZStencilBuffer;
int curRenderSide;
gs_texture *curTextures[MAX_TEXTURES];
gs_sampler_state *curSamplers[MAX_TEXTURES];
gs_texture *curTextures[GS_MAX_TEXTURES];
gs_sampler_state *curSamplers[GS_MAX_TEXTURES];
gs_vertex_buffer *curVertexBuffer;
gs_vertex_shader *curVertexShader;
gs_index_buffer *curIndexBuffer;

View File

@ -60,6 +60,12 @@ static inline bool gl_bind_buffer(GLenum target, GLuint buffer)
return gl_success("glBindBuffer");
}
static inline bool gl_bind_renderbuffer(GLenum target, GLuint buffer)
{
glBindRenderbuffer(target, buffer);
return gl_success("glBindRendebuffer");
}
extern bool upload_face(GLenum type, uint32_t num_levels,
GLenum format, GLint internal_format, bool compressed,
uint32_t width, uint32_t height, uint32_t size, void ***p_data);

View File

@ -29,7 +29,6 @@ static inline void shader_param_init(struct shader_param *param)
memset(param, 0, sizeof(struct shader_param));
}
static inline void shader_param_free(struct shader_param *param)
{
bfree(param->name);
@ -50,6 +49,7 @@ static void gl_get_program_info(GLuint program, char **error_string)
errors = bmalloc(info_len+1);
memset(errors, 0, info_len+1);
glGetProgramInfoLog(program, info_len, &chars_written, errors);
gl_success("glGetProgramInfoLog");
*error_string = errors;
}
@ -154,7 +154,8 @@ static struct gs_shader *shader_create(device_t device, enum shader_type type,
bool success = true;
memset(shader, 0, sizeof(struct gs_shader));
shader->type = type;
shader->device = device;
shader->type = type;
gl_shader_parser_init(&glsp);
if (!gl_shader_parse(&glsp, shader_str, file))
@ -306,6 +307,7 @@ void shader_setvec4(shader_t shader, sparam_t param,
void shader_settexture(shader_t shader, sparam_t param, texture_t val)
{
param->texture = val;
}
static void shader_setval_data(shader_t shader, sparam_t param,

View File

@ -100,11 +100,6 @@ texture_t device_create_volumetexture(device_t device, uint32_t width,
return NULL;
}
zstencil_t device_create_zstencil(device_t device, uint32_t width,
uint32_t height, enum gs_zstencil_format format)
{
}
stagesurf_t device_create_stagesurface(device_t device, uint32_t width,
uint32_t height, enum gs_color_format color_format)
{
@ -393,10 +388,6 @@ void stagesurface_unmap(stagesurf_t stagesurf)
{
}
void zstencil_destroy(zstencil_t zstencil)
{
}
void samplerstate_destroy(samplerstate_t samplerstate)
{
}

View File

@ -75,7 +75,7 @@ static inline GLint convert_gs_internal_format(enum gs_color_format format)
}
}
static inline GLint convert_zstencil_format(enum gs_zstencil_format format)
static inline GLenum convert_zstencil_format(enum gs_zstencil_format format)
{
switch (format) {
case GS_Z16: return GL_DEPTH_COMPONENT16;
@ -171,6 +171,8 @@ struct shader_param {
size_t sampler_id;
int array_count;
struct gs_texture *texture;
DARRAY(uint8_t) cur_value;
DARRAY(uint8_t) def_value;
bool changed;
@ -216,18 +218,26 @@ struct gs_texture_cube {
uint32_t size;
};
struct gs_zstencil_buffer {
device_t device;
GLuint buffer;
GLenum format;
};
struct gs_swap_chain {
device_t device;
device_t device;
struct gl_windowinfo *wi;
struct gs_init_data info;
};
struct gs_device {
struct gl_platform *plat;
struct gl_platform *plat;
struct gs_swap_chain *cur_swap;
int cur_render_side;
struct gs_texture *cur_render_texture;
int cur_render_side;
struct gs_texture *cur_textures[GS_MAX_TEXTURES];
struct gs_sampler *cur_samplers[GS_MAX_TEXTURES];
struct gs_swap_chain *cur_swap;
};
extern struct gl_platform *gl_platform_create(device_t device,

View File

@ -0,0 +1,65 @@
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "gl-subsystem.h"
static bool gl_init_zsbuffer(struct gs_zstencil_buffer *zs, uint32_t width,
uint32_t height)
{
glGenRenderbuffers(1, &zs->buffer);
if (!gl_success("glGenRenderbuffers"))
return false;
if (!gl_bind_renderbuffer(GL_RENDERBUFFER, zs->buffer))
return false;
glRenderbufferStorage(GL_RENDERBUFFER, zs->format, width, height);
if (!gl_success("glRenderbufferStorage"))
return false;
gl_bind_renderbuffer(GL_RENDERBUFFER, 0);
return true;
}
zstencil_t device_create_zstencil(device_t device, uint32_t width,
uint32_t height, enum gs_zstencil_format format)
{
struct gs_zstencil_buffer *zs;
zs = bmalloc(sizeof(struct gs_zstencil_buffer));
memset(zs, 0, sizeof(struct gs_zstencil_buffer));
zs->format = convert_zstencil_format(format);
if (!gl_init_zsbuffer(zs, width, height)) {
zstencil_destroy(zs);
return NULL;
}
return zs;
}
void zstencil_destroy(zstencil_t zs)
{
if (zs) {
if (zs->buffer) {
glDeleteRenderbuffers(1, &zs->buffer);
gl_success("glDeleteRenderbuffers");
}
bfree(zs);
}
}

View File

@ -32,6 +32,8 @@
extern "C" {
#endif
#define GS_MAX_TEXTURES 8
struct vec2;
struct vec3;
struct vec4;

View File

@ -168,6 +168,7 @@
<ClCompile Include="..\..\..\libobs-opengl\gl-texture2d.c" />
<ClCompile Include="..\..\..\libobs-opengl\gl-texturecube.c" />
<ClCompile Include="..\..\..\libobs-opengl\gl-windows.c" />
<ClCompile Include="..\..\..\libobs-opengl\gl-zstencil.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -50,5 +50,8 @@
<ClCompile Include="..\..\..\libobs-opengl\gl-shader.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\libobs-opengl\gl-zstencil.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>