| Index: ddraw/BufferObject.cpp |
| — | — | @@ -0,0 +1,119 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2015 William Feely
|
| | 4 | +
|
| | 5 | +// This library is free software; you can redistribute it and/or
|
| | 6 | +// modify it under the terms of the GNU Lesser General Public
|
| | 7 | +// License as published by the Free Software Foundation; either
|
| | 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| | 9 | +
|
| | 10 | +// This library is distributed in the hope that it will be useful,
|
| | 11 | +// but WITHOUT ANY W ARRANTY; without even the implied warranty of
|
| | 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| | 13 | +// Lesser General Public License for more details.
|
| | 14 | +
|
| | 15 | +// You should have received a copy of the GNU Lesser General Public
|
| | 16 | +// License along with this library; if not, write to the Free Software
|
| | 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| | 18 | +
|
| | 19 | +#include "common.h"
|
| | 20 | +#include "glUtil.h"
|
| | 21 | +#include "BufferObject.h"
|
| | 22 | +
|
| | 23 | +extern "C" {
|
| | 24 | +
|
| | 25 | +void BufferObject_Create(BufferObject **out, glExtensions *ext, glUtil *util)
|
| | 26 | +{
|
| | 27 | + BufferObject *buffer = (BufferObject*)malloc(sizeof(BufferObject));
|
| | 28 | + if (!buffer)
|
| | 29 | + {
|
| | 30 | + *out = NULL;
|
| | 31 | + return;
|
| | 32 | + }
|
| | 33 | + ZeroMemory(buffer, sizeof(BufferObject));
|
| | 34 | + buffer->ext = ext;
|
| | 35 | + buffer->util = util;
|
| | 36 | + ext->glGenBuffers(1, &buffer->buffer);
|
| | 37 | +}
|
| | 38 | +
|
| | 39 | +void BufferObject_AddRef(BufferObject *This)
|
| | 40 | +{
|
| | 41 | + InterlockedIncrement(&This->refcount);
|
| | 42 | +}
|
| | 43 | +
|
| | 44 | +void BufferObject_Release(BufferObject *This)
|
| | 45 | +{
|
| | 46 | + InterlockedDecrement(&This->refcount);
|
| | 47 | + if (!This->refcount)
|
| | 48 | + {
|
| | 49 | + This->ext->glDeleteBuffers(1, &This->buffer);
|
| | 50 | + free(This);
|
| | 51 | + }
|
| | 52 | +}
|
| | 53 | +
|
| | 54 | +void BufferObject_SetData(BufferObject *This, GLenum target, GLsizeiptr size, GLvoid *data, GLenum usage)
|
| | 55 | +{
|
| | 56 | + if (This->ext->GLEXT_ARB_direct_state_access)
|
| | 57 | + {
|
| | 58 | + This->ext->glNamedBufferData(This->buffer, size, data, usage);
|
| | 59 | + }
|
| | 60 | + else if (This->ext->GLEXT_EXT_direct_state_access)
|
| | 61 | + {
|
| | 62 | + This->ext->glNamedBufferDataEXT(This->buffer, size, data, usage);
|
| | 63 | + }
|
| | 64 | + else
|
| | 65 | + {
|
| | 66 | + This->util->BindBuffer(This, target);
|
| | 67 | + This->ext->glBufferData(target, size, data, usage);
|
| | 68 | + This->util->UndoBindBuffer(target);
|
| | 69 | + }
|
| | 70 | +}
|
| | 71 | +
|
| | 72 | +void BufferObject_Bind(BufferObject *This, GLenum target)
|
| | 73 | +{
|
| | 74 | + This->util->BindBuffer(This, target);
|
| | 75 | +}
|
| | 76 | +void BufferObject_Unbind(BufferObject *This, GLenum target)
|
| | 77 | +{
|
| | 78 | + This->util->BindBuffer(NULL, target);
|
| | 79 | +}
|
| | 80 | +
|
| | 81 | +void *BufferObject_Map(BufferObject *This, GLenum target, GLenum access)
|
| | 82 | +{
|
| | 83 | + void *ptr;
|
| | 84 | + if (This->ext->GLEXT_ARB_direct_state_access)
|
| | 85 | + {
|
| | 86 | + ptr = This->ext->glMapNamedBuffer(This->buffer, access);
|
| | 87 | + }
|
| | 88 | + else if (This->ext->GLEXT_EXT_direct_state_access)
|
| | 89 | + {
|
| | 90 | + ptr = This->ext->glMapNamedBufferEXT(This->buffer, access);
|
| | 91 | + }
|
| | 92 | + else
|
| | 93 | + {
|
| | 94 | + This->util->BindBuffer(This, target);
|
| | 95 | + ptr = This->ext->glMapBuffer(target, access);
|
| | 96 | + This->util->UndoBindBuffer(target);
|
| | 97 | + }
|
| | 98 | + return ptr;
|
| | 99 | +}
|
| | 100 | +GLboolean BufferObject_Unmap(BufferObject *This, GLenum target)
|
| | 101 | +{
|
| | 102 | + GLboolean ret;
|
| | 103 | + if (This->ext->GLEXT_ARB_direct_state_access)
|
| | 104 | + {
|
| | 105 | + ret = This->ext->glUnmapNamedBuffer(This->buffer);
|
| | 106 | + }
|
| | 107 | + else if (This->ext->GLEXT_EXT_direct_state_access)
|
| | 108 | + {
|
| | 109 | + ret = This->ext->glUnmapNamedBufferEXT(This->buffer);
|
| | 110 | + }
|
| | 111 | + else
|
| | 112 | + {
|
| | 113 | + This->util->BindBuffer(This, target);
|
| | 114 | + ret = This->ext->glUnmapBuffer(target);
|
| | 115 | + This->util->UndoBindBuffer(target);
|
| | 116 | + }
|
| | 117 | + return ret;
|
| | 118 | +}
|
| | 119 | +
|
| | 120 | +} |
| \ No newline at end of file |
| Index: ddraw/BufferObject.h |
| — | — | @@ -0,0 +1,57 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2015 William Feely
|
| | 4 | +
|
| | 5 | +// This library is free software; you can redistribute it and/or
|
| | 6 | +// modify it under the terms of the GNU Lesser General Public
|
| | 7 | +// License as published by the Free Software Foundation; either
|
| | 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| | 9 | +
|
| | 10 | +// This library is distributed in the hope that it will be useful,
|
| | 11 | +// but WITHOUT ANY W ARRANTY; without even the implied warranty of
|
| | 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| | 13 | +// Lesser General Public License for more details.
|
| | 14 | +
|
| | 15 | +// You should have received a copy of the GNU Lesser General Public
|
| | 16 | +// License along with this library; if not, write to the Free Software
|
| | 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| | 18 | +
|
| | 19 | +#pragma once
|
| | 20 | +#ifndef __PBO_H
|
| | 21 | +#define __PBO_H
|
| | 22 | +
|
| | 23 | +#ifdef __cplusplus
|
| | 24 | +extern "C" {
|
| | 25 | +#else
|
| | 26 | +typedef int glUtil;
|
| | 27 | +#endif
|
| | 28 | +
|
| | 29 | +
|
| | 30 | +typedef struct BufferObject
|
| | 31 | +{
|
| | 32 | + ULONG refcount;
|
| | 33 | + ULONG busy;
|
| | 34 | + GLuint buffer;
|
| | 35 | + GLsizei size;
|
| | 36 | + void *pointer;
|
| | 37 | + BOOL mapped;
|
| | 38 | + BOOL bound;
|
| | 39 | + BOOL target;
|
| | 40 | + glExtensions *ext;
|
| | 41 | + glUtil *util;
|
| | 42 | +} BufferObject;
|
| | 43 | +
|
| | 44 | +void BufferObject_Create(BufferObject **out, glExtensions *ext, glUtil *util);
|
| | 45 | +void BufferObject_AddRef(BufferObject *This);
|
| | 46 | +void BufferObject_Release(BufferObject *This);
|
| | 47 | +void BufferObject_SetData(BufferObject *This, GLenum target, GLsizeiptr size, GLvoid *data, GLenum usage);
|
| | 48 | +void BufferObject_Bind(BufferObject *This, GLenum target);
|
| | 49 | +void BufferObject_Unbind(BufferObject *This, GLenum target);
|
| | 50 | +void *BufferObject_Map(BufferObject *This, GLenum target, GLenum access);
|
| | 51 | +GLboolean BufferObject_Unmap(BufferObject *This, GLenum target);
|
| | 52 | +
|
| | 53 | +#ifdef __cplusplus
|
| | 54 | +}
|
| | 55 | +#endif
|
| | 56 | +
|
| | 57 | +
|
| | 58 | +#endif //__PBO_H |
| \ No newline at end of file |
| Index: ddraw/TextureManager.c |
| — | — | @@ -16,6 +16,7 @@ |
| 17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | 18 |
|
| 19 | 19 | #include "common.h"
|
| | 20 | +#include "BufferObject.h"
|
| 20 | 21 | #include "TextureManager.h"
|
| 21 | 22 | #include <math.h>
|
| 22 | 23 |
|
| — | — | @@ -491,7 +492,8 @@ |
| 492 | 493 | texture->bordercolor = texture->format = texture->type = texture->width =
|
| 493 | 494 | texture->height = texture->magfilter = texture->minfilter =
|
| 494 | 495 | texture->miplevel = texture->wraps = texture->wrapt =
|
| 495 | | - texture->pbo = texture->id = 0;
|
| | 496 | + texture->id = 0;
|
| | 497 | + texture->pboPack = texture->pboUnpack = NULL;
|
| 496 | 498 | ZeroMemory(texture->internalformats, 8 * sizeof(GLint));
|
| 497 | 499 | }
|
| 498 | 500 |
|
| Index: ddraw/TextureManager.h |
| — | — | @@ -23,17 +23,9 @@ |
| 24 | 24 | extern "C" {
|
| 25 | 25 | #endif
|
| 26 | 26 |
|
| 27 | | -typedef struct
|
| 28 | | -{
|
| 29 | | - ULONG refcount;
|
| 30 | | - GLuint buffer;
|
| 31 | | - GLsizei size;
|
| 32 | | - void *pointer;
|
| 33 | | - BOOL mapped;
|
| 34 | | - BOOL busy;
|
| 35 | | -} PBO;
|
| | 27 | +struct BufferObject;
|
| 36 | 28 |
|
| 37 | | -typedef struct
|
| | 29 | +typedef struct TEXTURE
|
| 38 | 30 | {
|
| 39 | 31 | GLuint id;
|
| 40 | 32 | GLsizei width;
|
| — | — | @@ -50,7 +42,8 @@ |
| 51 | 43 | int colororder;
|
| 52 | 44 | GLenum format;
|
| 53 | 45 | GLenum type;
|
| 54 | | - GLuint pbo;
|
| | 46 | + BufferObject *pboPack;
|
| | 47 | + BufferObject *pboUnpack;
|
| 55 | 48 | DDPIXELFORMAT pixelformat;
|
| 56 | 49 | } TEXTURE;
|
| 57 | 50 |
|
| Index: ddraw/common.h |
| — | — | @@ -106,6 +106,7 @@ |
| 107 | 107 | out[2] = (GLint)(in& 0xff);
|
| 108 | 108 | out[3] = (GLint)((in>>24) & 0xff);
|
| 109 | 109 | }
|
| | 110 | +#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
| 110 | 111 |
|
| 111 | 112 | #ifdef _M_X64
|
| 112 | 113 | #define NextMultipleOfWord NextMultipleOf8
|
| Index: ddraw/ddraw.vcxproj |
| — | — | @@ -294,6 +294,7 @@ |
| 295 | 295 | <ClInclude Include="include\GL\wglext.h" />
|
| 296 | 296 | <ClInclude Include="include\winedef.h" />
|
| 297 | 297 | <ClInclude Include="matrix.h" />
|
| | 298 | + <ClInclude Include="BufferObject.h" />
|
| 298 | 299 | <ClInclude Include="resource.h" />
|
| 299 | 300 | <ClInclude Include="scalers.h" />
|
| 300 | 301 | <ClInclude Include="ShaderGen3D.h" />
|
| — | — | @@ -383,6 +384,14 @@ |
| 384 | 385 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| 385 | 386 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
|
| 386 | 387 | </ClCompile>
|
| | 388 | + <ClCompile Include="BufferObject.cpp">
|
| | 389 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
| | 390 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| | 391 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
| | 392 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
| | 393 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| | 394 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
|
| | 395 | + </ClCompile>
|
| 387 | 396 | <ClCompile Include="precomp.cpp">
|
| 388 | 397 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">Create</PrecompiledHeader>
|
| 389 | 398 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
| Index: ddraw/ddraw.vcxproj.filters |
| — | — | @@ -146,6 +146,9 @@ |
| 147 | 147 | <ClInclude Include="hooks.h">
|
| 148 | 148 | <Filter>Header Files</Filter>
|
| 149 | 149 | </ClInclude>
|
| | 150 | + <ClInclude Include="BufferObject.h">
|
| | 151 | + <Filter>Header Files</Filter>
|
| | 152 | + </ClInclude>
|
| 150 | 153 | </ItemGroup>
|
| 151 | 154 | <ItemGroup>
|
| 152 | 155 | <ClCompile Include="ddraw.cpp">
|
| — | — | @@ -247,6 +250,9 @@ |
| 248 | 251 | <ClCompile Include="hooks.c">
|
| 249 | 252 | <Filter>Source Files</Filter>
|
| 250 | 253 | </ClCompile>
|
| | 254 | + <ClCompile Include="BufferObject.cpp">
|
| | 255 | + <Filter>Source Files</Filter>
|
| | 256 | + </ClCompile>
|
| 251 | 257 | </ItemGroup>
|
| 252 | 258 | <ItemGroup>
|
| 253 | 259 | <ResourceCompile Include="ddraw.rc">
|
| Index: ddraw/glExtensions.c |
| — | — | @@ -155,6 +155,9 @@ |
| 156 | 156 | ext->glGetTextureImageEXT = (PFNGLGETTEXTUREIMAGEEXTPROC)wglGetProcAddress("glGetTextureImageEXT");
|
| 157 | 157 | ext->glMatrixLoadfEXT = (PFNGLMATRIXLOADFEXTPROC)wglGetProcAddress("glMatrixLoadfEXT");
|
| 158 | 158 | ext->glMatrixMultfEXT = (PFNGLMATRIXMULTFEXTPROC)wglGetProcAddress("glMatrixMultfEXT");
|
| | 159 | + ext->glNamedBufferDataEXT = (PFNGLNAMEDBUFFERDATAEXTPROC)wglGetProcAddress("glNamedBufferDataEXT");
|
| | 160 | + ext->glMapNamedBufferEXT = (PFNGLMAPNAMEDBUFFEREXTPROC)wglGetProcAddress("glMapNamedBufferEXT");
|
| | 161 | + ext->glUnmapNamedBufferEXT = (PFNGLUNMAPNAMEDBUFFEREXTPROC)wglGetProcAddress("glUnmapNamedBufferEXT");
|
| 159 | 162 | }
|
| 160 | 163 | if (ext->GLEXT_ARB_direct_state_access)
|
| 161 | 164 | {
|
| — | — | @@ -164,6 +167,9 @@ |
| 165 | 168 | ext->glTextureParameteriv = (PFNGLTEXTUREPARAMETERIVPROC)wglGetProcAddress("glTextureParameteriv");
|
| 166 | 169 | ext->glTextureSubImage2D = (PFNGLTEXTURESUBIMAGE2DPROC)wglGetProcAddress("glTextureSubImage2D");
|
| 167 | 170 | ext->glGetTextureImage = (PFNGLGETTEXTUREIMAGEPROC)wglGetProcAddress("glGetTextureImage");
|
| | 171 | + ext->glNamedBufferData = (PFNGLNAMEDBUFFERDATAPROC)wglGetProcAddress("glNamedBufferData");
|
| | 172 | + ext->glMapNamedBuffer = (PFNGLMAPNAMEDBUFFERPROC)wglGetProcAddress("glMapNamedBuffer");
|
| | 173 | + ext->glUnmapNamedBuffer = (PFNGLUNMAPNAMEDBUFFERPROC)wglGetProcAddress("glUnmapNamedBuffer");
|
| 168 | 174 | }
|
| 169 | 175 | if (ext->GLEXT_ARB_sampler_objects)
|
| 170 | 176 | {
|
| Index: ddraw/glExtensions.h |
| — | — | @@ -114,6 +114,9 @@ |
| 115 | 115 | void (APIENTRY *glGetTextureImageEXT)(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels);
|
| 116 | 116 | void (APIENTRY *glMatrixLoadfEXT)(GLenum mode, const GLfloat *m);
|
| 117 | 117 | void (APIENTRY *glMatrixMultfEXT)(GLenum mode, const GLfloat *m);
|
| | 118 | + void (APIENTRY *glNamedBufferDataEXT)(GLuint buffer, GLsizeiptr size, const void *data, GLenum usage);
|
| | 119 | + void* (APIENTRY *glMapNamedBufferEXT)(GLuint buffer, GLenum access);
|
| | 120 | + GLboolean (APIENTRY *glUnmapNamedBufferEXT)(GLuint buffer);
|
| 118 | 121 |
|
| 119 | 122 | void (APIENTRY *glTextureParameterf)(GLuint texture, GLenum pname, GLfloat param);
|
| 120 | 123 | void (APIENTRY *glTextureParameterfv)(GLuint texture, GLenum pname, const GLfloat *params);
|
| — | — | @@ -122,8 +125,10 @@ |
| 123 | 126 | void (APIENTRY *glTextureSubImage2D)(GLuint texture, GLint level, GLint xoffset, GLint yoffset,
|
| 124 | 127 | GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
|
| 125 | 128 | void (APIENTRY *glGetTextureImage)(GLuint texture, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *pixels);
|
| | 129 | + void (APIENTRY *glNamedBufferData)(GLuint buffer, GLsizei size, const void *data, GLenum usage);
|
| | 130 | + void* (APIENTRY *glMapNamedBuffer)(GLuint buffer, GLenum access);
|
| | 131 | + GLboolean (APIENTRY *glUnmapNamedBuffer)(GLuint buffer);
|
| 126 | 132 |
|
| 127 | | -
|
| 128 | 133 | void (APIENTRY *glBindSampler)(GLuint unit, GLuint sampler);
|
| 129 | 134 | void (APIENTRY *glDeleteSamplers)(GLsizei n, const GLuint *samplers);
|
| 130 | 135 | void (APIENTRY *glGenSamplers)(GLsizei n, GLuint *samplers);
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -16,6 +16,7 @@ |
| 17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | 18 |
|
| 19 | 19 | #include "common.h"
|
| | 20 | +#include "BufferObject.h"
|
| 20 | 21 | #include "TextureManager.h"
|
| 21 | 22 | #include "glUtil.h"
|
| 22 | 23 | #include "timer.h"
|
| — | — | @@ -212,7 +213,7 @@ |
| 213 | 214 | This->backbuffer = NULL;
|
| 214 | 215 | This->hDC = NULL;
|
| 215 | 216 | This->hRC = NULL;
|
| 216 | | - This->PBO = 0;
|
| | 217 | + This->pbo = NULL;
|
| 217 | 218 | This->dib.enabled = false;
|
| 218 | 219 | This->hWnd = hwnd;
|
| 219 | 220 | InitializeCriticalSection(&This->cs);
|
| — | — | @@ -889,11 +890,10 @@ |
| 890 | 891 | }
|
| 891 | 892 | TextureManager_DeleteSamplers(This->texman);
|
| 892 | 893 | This->util->DeleteFBO(&This->fbo);
|
| 893 | | - if(This->PBO)
|
| | 894 | + if(This->pbo)
|
| 894 | 895 | {
|
| 895 | | - This->ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
| 896 | | - This->ext->glDeleteBuffers(1,&This->PBO);
|
| 897 | | - This->PBO = 0;
|
| | 896 | + BufferObject_Release(This->pbo);
|
| | 897 | + This->pbo = NULL;
|
| 898 | 898 | }
|
| 899 | 899 | if(This->backbuffer)
|
| 900 | 900 | {
|
| — | — | @@ -1149,10 +1149,8 @@ |
| 1150 | 1150 | This->dib.hbitmap = CreateDIBSection(This->dib.hdc,&This->dib.info,
|
| 1151 | 1151 | DIB_RGB_COLORS,(void**)&This->dib.pixels,NULL,0);
|
| 1152 | 1152 | }
|
| 1153 | | - This->ext->glGenBuffers(1,&This->PBO);
|
| 1154 | | - This->ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,This->PBO);
|
| 1155 | | - This->ext->glBufferData(GL_PIXEL_PACK_BUFFER,width*height*4,NULL,GL_STREAM_READ);
|
| 1156 | | - This->ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
| | 1153 | + BufferObject_Create(&This->pbo, This->ext, This->util);
|
| | 1154 | + BufferObject_SetData(This->pbo, GL_PIXEL_PACK_BUFFER, width*height * 4, NULL, GL_STREAM_READ);
|
| 1157 | 1155 | TextureManager_InitSamplers(This->texman);
|
| 1158 | 1156 | TRACE_SYSINFO();
|
| 1159 | 1157 | return TRUE;
|
| — | — | @@ -1759,20 +1757,21 @@ |
| 1760 | 1758 | else
|
| 1761 | 1759 | {
|
| 1762 | 1760 | glReadBuffer(GL_FRONT);
|
| 1763 | | - This->ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,This->PBO);
|
| | 1761 | + BufferObject_Bind(This->pbo, GL_PIXEL_PACK_BUFFER);
|
| 1764 | 1762 | GLint packalign;
|
| 1765 | 1763 | glGetIntegerv(GL_PACK_ALIGNMENT,&packalign);
|
| 1766 | 1764 | glPixelStorei(GL_PACK_ALIGNMENT,1);
|
| 1767 | 1765 | This->ddInterface->GetSizes(sizes);
|
| 1768 | 1766 | glReadPixels(0,0,sizes[4],sizes[5],GL_BGRA,GL_UNSIGNED_BYTE,0);
|
| 1769 | | - GLubyte *pixels = (GLubyte*)This->ext->glMapBuffer(GL_PIXEL_PACK_BUFFER,GL_READ_ONLY);
|
| | 1767 | + BufferObject_Map(This->pbo, GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
|
| | 1768 | + GLubyte *pixels = (GLubyte*)This->pbo->pointer;
|
| 1770 | 1769 | for(int i = 0; i < sizes[5];i++)
|
| 1771 | 1770 | {
|
| 1772 | 1771 | memcpy(&This->dib.pixels[This->dib.pitch*i],
|
| 1773 | 1772 | &pixels[((sizes[5]-1)-i)*(sizes[4]*4)],sizes[4]*4);
|
| 1774 | 1773 | }
|
| 1775 | | - This->ext->glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
| 1776 | | - This->ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
| | 1774 | + BufferObject_Unmap(This->pbo, GL_PIXEL_PACK_BUFFER);
|
| | 1775 | + BufferObject_Unbind(This->pbo, GL_PIXEL_PACK_BUFFER);
|
| 1777 | 1776 | glPixelStorei(GL_PACK_ALIGNMENT,packalign);
|
| 1778 | 1777 | HDC hRenderDC = (HDC)::GetDC(This->RenderWnd->GetHWnd());
|
| 1779 | 1778 | HGDIOBJ hPrevObj = 0;
|
| Index: ddraw/glRenderer.h |
| — | — | @@ -137,7 +137,7 @@ |
| 138 | 138 | glRenderWindow *RenderWnd;
|
| 139 | 139 | DIB dib;
|
| 140 | 140 | FBO fbo;
|
| 141 | | - GLuint PBO;
|
| | 141 | + BufferObject *pbo;
|
| 142 | 142 | CRITICAL_SECTION cs;
|
| 143 | 143 | HANDLE busy;
|
| 144 | 144 | HANDLE start;
|
| Index: ddraw/glUtil.cpp |
| — | — | @@ -18,6 +18,7 @@ |
| 19 | 19 | #include "common.h"
|
| 20 | 20 | #include "TextureManager.h"
|
| 21 | 21 | #include "glUtil.h"
|
| | 22 | +#include "BufferObject.h"
|
| 22 | 23 | #include "glDirectDrawSurface.h"
|
| 23 | 24 |
|
| 24 | 25 | glUtil::glUtil(glExtensions *glext)
|
| — | — | @@ -60,6 +61,8 @@ |
| 61 | 62 | cullenabled = false;
|
| 62 | 63 | polymode = D3DFILL_SOLID;
|
| 63 | 64 | shademode = D3DSHADE_GOURAUD;
|
| | 65 | + pboPackBinding = pboUnpackBinding = vboArrayBinding =
|
| | 66 | + vboElementArrayBinding = uboUniformBufferBinding = LastBoundBuffer = NULL;
|
| 64 | 67 | }
|
| 65 | 68 | void glUtil::InitFBO(FBO *fbo)
|
| 66 | 69 | {
|
| — | — | @@ -522,4 +525,42 @@ |
| 523 | 526 | break;
|
| 524 | 527 | }
|
| 525 | 528 | }
|
| | 529 | +}
|
| | 530 | +
|
| | 531 | +void glUtil::BindBuffer(BufferObject *buffer, GLenum target)
|
| | 532 | +{
|
| | 533 | + switch (target)
|
| | 534 | + {
|
| | 535 | + case GL_PIXEL_PACK_BUFFER:
|
| | 536 | + LastBoundBuffer = pboPackBinding;
|
| | 537 | + pboPackBinding = buffer;
|
| | 538 | + break;
|
| | 539 | + case GL_PIXEL_UNPACK_BUFFER:
|
| | 540 | + LastBoundBuffer = pboUnpackBinding;
|
| | 541 | + pboUnpackBinding = buffer;
|
| | 542 | + break;
|
| | 543 | + case GL_ARRAY_BUFFER:
|
| | 544 | + LastBoundBuffer = vboArrayBinding;
|
| | 545 | + vboArrayBinding = buffer;
|
| | 546 | + break;
|
| | 547 | + case GL_ELEMENT_ARRAY_BUFFER:
|
| | 548 | + LastBoundBuffer = vboElementArrayBinding;
|
| | 549 | + vboElementArrayBinding = buffer;
|
| | 550 | + break;
|
| | 551 | + case GL_UNIFORM_BUFFER:
|
| | 552 | + LastBoundBuffer = uboUniformBufferBinding;
|
| | 553 | + uboUniformBufferBinding = buffer;
|
| | 554 | + break;
|
| | 555 | + default:
|
| | 556 | + LastBoundBuffer = NULL;
|
| | 557 | + }
|
| | 558 | + if(buffer) ext->glBindBuffer(target, buffer->buffer);
|
| | 559 | + else ext->glBindBuffer(target, 0);
|
| | 560 | +}
|
| | 561 | +
|
| | 562 | +void glUtil::UndoBindBuffer(GLenum target)
|
| | 563 | +{
|
| | 564 | + if (LastBoundBuffer) ext->glBindBuffer(target, LastBoundBuffer->buffer);
|
| | 565 | + else ext->glBindBuffer(target, 0);
|
| | 566 | + LastBoundBuffer = NULL;
|
| 526 | 567 | } |
| \ No newline at end of file |
| Index: ddraw/glUtil.h |
| — | — | @@ -19,6 +19,10 @@ |
| 20 | 20 | #ifndef _GLUTIL_H
|
| 21 | 21 | #define _GLUTIL_H
|
| 22 | 22 |
|
| | 23 | +struct TEXTURE;
|
| | 24 | +struct BufferObject;
|
| | 25 | +struct TextureManager;
|
| | 26 | +
|
| 23 | 27 | typedef struct
|
| 24 | 28 | {
|
| 25 | 29 | GLuint fbo;
|
| — | — | @@ -68,7 +72,14 @@ |
| 69 | 73 | void SetCull(D3DCULL mode);
|
| 70 | 74 | void SetPolyMode(D3DFILLMODE mode);
|
| 71 | 75 | void SetShadeMode(D3DSHADEMODE mode);
|
| | 76 | + void BindBuffer(BufferObject *buffer, GLenum target);
|
| | 77 | + void UndoBindBuffer(GLenum target);
|
| 72 | 78 | FBO *currentfbo;
|
| | 79 | + BufferObject *pboPackBinding;
|
| | 80 | + BufferObject *pboUnpackBinding;
|
| | 81 | + BufferObject *vboArrayBinding;
|
| | 82 | + BufferObject *vboElementArrayBinding;
|
| | 83 | + BufferObject *uboUniformBufferBinding;
|
| 73 | 84 | private:
|
| 74 | 85 | glExtensions *ext;
|
| 75 | 86 | bool depthwrite;
|
| — | — | @@ -107,6 +118,7 @@ |
| 108 | 119 | bool cullenabled;
|
| 109 | 120 | D3DFILLMODE polymode;
|
| 110 | 121 | D3DSHADEMODE shademode;
|
| | 122 | + BufferObject *LastBoundBuffer;
|
| 111 | 123 | };
|
| 112 | 124 |
|
| 113 | 125 | #endif //_GLUTIL_H
|