From 4997bee1bf51017df665588886e50cd42853b1e2 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 9 Dec 2008 09:52:38 +0100 Subject: [PATCH] wined3d: Add functions to initialize and free shader buffers. --- dlls/wined3d/arb_program_shader.c | 22 ++++++++-------------- dlls/wined3d/baseshader.c | 14 ++++++++++++++ dlls/wined3d/glsl_shader.c | 7 ++----- dlls/wined3d/pixelshader.c | 9 ++------- dlls/wined3d/vertexshader.c | 9 ++------- dlls/wined3d/wined3d_private.h | 2 ++ 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index 9d5125042f3..3faa17c8b2a 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -2694,10 +2694,7 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, IWi } /* Shader header */ - buffer.bsize = 0; - buffer.lineNo = 0; - buffer.newline = TRUE; - buffer.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SHADER_PGMSIZE); + shader_buffer_init(&buffer); shader_addline(&buffer, "!!ARBfp1.0\n"); @@ -2888,7 +2885,7 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, IWi FIXME("Fragment program error at position %d: %s\n", pos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB))); } - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return ret; } @@ -3426,10 +3423,7 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum yuv_fixup yuv_fixu struct arbfp_blit_priv *priv = (struct arbfp_blit_priv *) device->blit_priv; /* Shader header */ - buffer.bsize = 0; - buffer.lineNo = 0; - buffer.newline = TRUE; - buffer.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SHADER_PGMSIZE); + shader_buffer_init(&buffer); ENTER_GL(); GL_EXTCALL(glGenProgramsARB(1, &shader)); @@ -3438,7 +3432,7 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum yuv_fixup yuv_fixu checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader)"); LEAVE_GL(); if(!shader) { - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return 0; } @@ -3493,7 +3487,7 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum yuv_fixup yuv_fixu case YUV_FIXUP_YUY2: if (!gen_planar_yuv_read(&buffer, yuv_fixup, textype, &luminance_component)) { - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return 0; } break; @@ -3501,14 +3495,14 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum yuv_fixup yuv_fixu case YUV_FIXUP_YV12: if (!gen_yv12_read(&buffer, textype, &luminance_component)) { - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return 0; } break; default: FIXME("Unsupported YUV fixup %#x\n", yuv_fixup); - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return 0; } @@ -3533,7 +3527,7 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum yuv_fixup yuv_fixu FIXME("Fragment program error at position %d: %s\n", pos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB))); } - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); LEAVE_GL(); switch (yuv_fixup) diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c index c0b149f8288..941429227b2 100644 --- a/dlls/wined3d/baseshader.c +++ b/dlls/wined3d/baseshader.c @@ -40,6 +40,20 @@ static inline BOOL shader_is_version_token(DWORD token) { shader_is_vshader_version(token); } +void shader_buffer_init(struct SHADER_BUFFER *buffer) +{ + buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE); + buffer->buffer[0] = '\0'; + buffer->bsize = 0; + buffer->lineNo = 0; + buffer->newline = TRUE; +} + +void shader_buffer_free(struct SHADER_BUFFER *buffer) +{ + HeapFree(GetProcessHeap(), 0, buffer->buffer); +} + int shader_addline( SHADER_BUFFER* buffer, const char *format, ...) { diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 4c1d2239a61..f1a0f956a32 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -2958,10 +2958,7 @@ static GLhandleARB generate_param_reorder_function(IWineD3DVertexShader *vertexs char reg_mask[6]; const struct semantic *semantics_out, *semantics_in; - buffer.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SHADER_PGMSIZE); - buffer.bsize = 0; - buffer.lineNo = 0; - buffer.newline = TRUE; + shader_buffer_init(&buffer); shader_addline(&buffer, "#version 120\n"); @@ -3093,7 +3090,7 @@ static GLhandleARB generate_param_reorder_function(IWineD3DVertexShader *vertexs GL_EXTCALL(glCompileShaderARB(ret)); checkGLcall("glCompileShaderARB(ret)"); - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return ret; } diff --git a/dlls/wined3d/pixelshader.c b/dlls/wined3d/pixelshader.c index 6a4d7d5dc5c..09a99dcf29c 100644 --- a/dlls/wined3d/pixelshader.c +++ b/dlls/wined3d/pixelshader.c @@ -277,14 +277,9 @@ static inline GLuint IWineD3DPixelShaderImpl_GenerateShader( SHADER_BUFFER buffer; GLuint shader; - buffer.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SHADER_PGMSIZE); - buffer.bsize = 0; - buffer.lineNo = 0; - buffer.newline = TRUE; - + shader_buffer_init(&buffer); shader = ((IWineD3DDeviceImpl *)This->baseShader.device)->shader_backend->shader_generate_pshader((IWineD3DPixelShader *)This, &buffer); - - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); return shader; } diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c index 31802624463..9c47930d1e0 100644 --- a/dlls/wined3d/vertexshader.c +++ b/dlls/wined3d/vertexshader.c @@ -325,14 +325,9 @@ static void IWineD3DVertexShaderImpl_GenerateShader(IWineD3DVertexShader *iface, find_swizzled_attribs(decl, This); - buffer.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SHADER_PGMSIZE); - buffer.bsize = 0; - buffer.lineNo = 0; - buffer.newline = TRUE; - + shader_buffer_init(&buffer); ((IWineD3DDeviceImpl *)This->baseShader.device)->shader_backend->shader_generate_vshader(iface, &buffer); - - HeapFree(GetProcessHeap(), 0, buffer.buffer); + shader_buffer_free(&buffer); } /* ******************************************* diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 359be448f51..b4464f99864 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2229,6 +2229,8 @@ typedef struct IWineD3DBaseShaderImpl { HRESULT WINAPI IWineD3DBaseShaderImpl_QueryInterface(IWineD3DBaseShader *iface, REFIID riid, LPVOID *ppobj); ULONG WINAPI IWineD3DBaseShaderImpl_AddRef(IWineD3DBaseShader *iface); ULONG WINAPI IWineD3DBaseShaderImpl_Release(IWineD3DBaseShader *iface); +void shader_buffer_init(struct SHADER_BUFFER *buffer); +void shader_buffer_free(struct SHADER_BUFFER *buffer); extern HRESULT shader_get_registers_used( IWineD3DBaseShader *iface,