Skip to content

Commit

Permalink
Fix issues after rebase to latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
fzurita committed Jan 26, 2019
1 parent 816a6da commit d28eb0c
Show file tree
Hide file tree
Showing 17 changed files with 278 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/BufferCopy/RDRAMtoColorBuffer.cpp
Expand Up @@ -252,7 +252,7 @@ void RDRAMtoColorBuffer::_copyFromRDRAM(u32 _height, bool _fullAlpha)
updateParams.format = fbTexFormats.colorFormat;
updateParams.dataType = fbTexFormats.colorType;
updateParams.data = m_pbuf;
updateParams.dataBytes = gpuDataSize;
updateParams.dataBytes = m_pTexture->textureBytes;
updateParams.fromBuffer = true;
gfxContext.update2DTexture(updateParams);

Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/ColorBufferReader.cpp
Expand Up @@ -19,7 +19,7 @@ namespace graphics {
u32 _heightOffset, u32 _stride)
{
int bytesToCopy = m_pTexture->realWidth * _height * 16;
std::copy_n(_gpuData, bytesToCopy, m_tempPixelData.data());
std::copy_n(_gpuData, bytesToCopy, m_tempPixelData.begin());
u8* pixelDataAlloc = m_pixelData.data();
float* pixelData = reinterpret_cast<float*>(m_tempPixelData.data());
const u32 colorsPerPixel = 4;
Expand Down
2 changes: 0 additions & 2 deletions src/Graphics/OpenGLContext/GLFunctions.h
Expand Up @@ -36,8 +36,6 @@ typedef double GLdouble;

#define IS_GL_FUNCTION_VALID(proc_name) g_##proc_name != nullptr

#if defined(EGL) || defined(OS_IOS)

#if defined(EGL) || defined(OS_IOS)
extern PFNGLBLENDFUNCPROC g_glBlendFunc;
extern PFNGLPIXELSTOREIPROC g_glPixelStorei;
Expand Down
10 changes: 5 additions & 5 deletions src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramImpl.cpp
Expand Up @@ -99,22 +99,22 @@ bool CombinerProgramImpl::getBinaryForm(std::vector<char> & _buffer)
_buffer.resize(totalSize);

char* keyData = reinterpret_cast<char*>(&key);
std::copy_n(keyData, sizeof(key), _buffer.data());
std::copy_n(keyData, sizeof(key), _buffer.begin());
int offset = sizeof(key);

char* inputData = reinterpret_cast<char*>(&inputs);
std::copy_n(inputData, sizeof(inputs), _buffer.data() + offset);
std::copy_n(inputData, sizeof(inputs), _buffer.begin() + offset);
offset += sizeof(inputs);

char* binaryFormatData = reinterpret_cast<char*>(&binaryFormat);
std::copy_n(binaryFormatData, sizeof(binaryFormat), _buffer.data() + offset);
std::copy_n(binaryFormatData, sizeof(binaryFormat), _buffer.begin() + offset);
offset += sizeof(binaryFormat);

char* binaryLengthData = reinterpret_cast<char*>(&binaryLength);
std::copy_n(binaryLengthData, sizeof(binaryLength), _buffer.data() + offset);
std::copy_n(binaryLengthData, sizeof(binaryLength), _buffer.begin() + offset);
offset += sizeof(binaryLength);

std::copy_n(binary.data(), binaryLength, _buffer.data() + offset);
std::copy_n(binary.begin(), binaryLength, _buffer.begin() + offset);

return true;
}
Expand Up @@ -62,8 +62,12 @@ struct fv3Uniform {
const size_t szData = sizeof(float)* 3;
if (loc >= 0 && (_force || memcmp(val, _pVal, szData) != 0)) {
memcpy(val, _pVal, szData);

std::unique_ptr<GLfloat[]> values(new GLfloat[3]);
std::copy_n(val, 3, values.get());
values.get()[0] = _pVal[0];
values.get()[1] = _pVal[1];
values.get()[2] = _pVal[2];

FunctionWrapper::glUniform3fv(loc, 1, std::move(values));
}
}
Expand All @@ -76,8 +80,13 @@ struct fv4Uniform {
const size_t szData = sizeof(float)* 4;
if (loc >= 0 && (_force || memcmp(val, _pVal, szData) != 0)) {
memcpy(val, _pVal, szData);

std::unique_ptr<GLfloat[]> values(new GLfloat[4]);
std::copy_n(val, 4, values.get());
values.get()[0] = _pVal[0];
values.get()[1] = _pVal[1];
values.get()[2] = _pVal[2];
values.get()[3] = _pVal[3];

FunctionWrapper::glUniform4fv(loc, 1, std::move(values));
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Graphics/OpenGLContext/GLSL/glsl_SpecialShadersFactory.cpp
Expand Up @@ -506,9 +506,9 @@ namespace glsl {

void activate() override {
ShadowMapShaderBase::activate();

std::unique_ptr<GLfloat[]> values(new GLfloat[4]);
std::copy_n(&gDP.fogColor.r, 4, values.get());
FunctionWrapper::glUniform4fv(m_loc, 1, std::move(values));
FunctionWrapper::glUniform4fv(m_locFog, 1, std::move(values));
FunctionWrapper::glUniform1i(m_locZlut, int(graphics::textureIndices::ZLUTTex));
FunctionWrapper::glUniform1i(m_locTlut, int(graphics::textureIndices::PaletteTex));
FunctionWrapper::glUniform1i(m_locDepthImage, 0);
Expand Down Expand Up @@ -538,7 +538,7 @@ namespace glsl {
: FXAAShaderBase(_glinfo, _useProgram, _vertexHeader, _fragmentHeader, _fragmentEnd)
{
m_useProgram->useProgram(m_program);
m_textureSizeLoc = glGetUniformLocation(GLuint(m_program), "uTextureSize");
m_textureSizeLoc = FunctionWrapper::glGetUniformLocation(GLuint(m_program), "uTextureSize");
m_useProgram->useProgram(graphics::ObjectHandle::null);
}

Expand All @@ -549,7 +549,7 @@ namespace glsl {
(m_width != pBuffer->m_pTexture->realWidth || m_height != pBuffer->m_pTexture->realHeight)) {
m_width = pBuffer->m_pTexture->realWidth;
m_height = pBuffer->m_pTexture->realHeight;
glUniform2f(m_textureSizeLoc, GLfloat(m_width), GLfloat(m_height));
FunctionWrapper::glUniform2f(m_textureSizeLoc, GLfloat(m_width), GLfloat(m_height));
}
}

Expand Down Expand Up @@ -617,7 +617,7 @@ namespace glsl {
const GLfloat depth = gDP.otherMode.depthSource == G_ZS_PRIM ? gDP.primDepth.z : 0.0f;
if (depth != m_depth) {
m_depth = depth;
glUniform1f(m_primDepthLoc, m_depth);
FunctionWrapper::glUniform1f(m_primDepthLoc, m_depth);
}
}
gDP.changed |= CHANGED_COMBINE;
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp
Expand Up @@ -98,7 +98,7 @@ void BufferedDrawer::_updateBuffer(Buffer & _buffer, u32 _count, u32 _dataSize,
memcpy(&_buffer.data[_buffer.offset], _data, _dataSize);
#ifdef GL_DEBUG
m_bindBuffer->bind(Parameter(_buffer.type), ObjectHandle(_buffer.handle));
glFlushMappedBufferRange(_buffer.type, _buffer.offset, _dataSize);
FunctionWrapper::glFlushMappedBufferRange(_buffer.type, _buffer.offset, _dataSize);
#endif
} else {
std::unique_ptr<u8[]> data((new u8[_dataSize]));
Expand Down Expand Up @@ -217,7 +217,7 @@ void BufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParamete
}

u16* indices = (u16*)nullptr + m_trisBuffers.ebo.pos - _params.elementsCount;
FunctionWrapper:glDrawRangeElementsBaseVertex(GLenum(_params.mode), 0, _params.verticesCount - 1, _params.elementsCount, GL_UNSIGNED_SHORT,
FunctionWrapper::glDrawRangeElementsBaseVertex(GLenum(_params.mode), 0, _params.verticesCount - 1, _params.elementsCount, GL_UNSIGNED_SHORT,
indices, m_trisBuffers.vbo.pos - _params.verticesCount);
}

Expand Down
1 change: 0 additions & 1 deletion src/Graphics/OpenGLContext/opengl_CachedFunctions.cpp
Expand Up @@ -60,7 +60,6 @@ void CachedBindRenderbuffer::bind(graphics::Parameter _target, graphics::ObjectH
void CachedBindBuffer::bind(graphics::Parameter _target, graphics::ObjectHandle _name) {
if (update(_target, _name))
FunctionWrapper::glBindBuffer(GLenum(_target), GLuint(_name));
>>>>>>> Refactor code to use new OpenGL wrapper
}

/*---------------CachedBindTexture-------------*/
Expand Down
Expand Up @@ -21,7 +21,7 @@ ColorBufferReaderWithPixelBuffer::~ColorBufferReaderWithPixelBuffer()

void ColorBufferReaderWithPixelBuffer::_destroyBuffers()
{
auto buffers = std::unique_ptr<GLuint[]>(new GLuint[_numPBO]);
auto buffers = std::unique_ptr<GLuint[]>(new GLuint[m_numPBO]);

for(unsigned int index = 0; index < m_numPBO; ++index) {
buffers[index] = m_PBO[index];
Expand Down Expand Up @@ -66,12 +66,12 @@ const u8 * ColorBufferReaderWithPixelBuffer::_readPixels(const ReadColorBufferPa
m_curIndex = (m_curIndex + 1) % m_numPBO;
m_bindBuffer->bind(Parameter(GL_PIXEL_PACK_BUFFER), ObjectHandle(m_PBO[m_curIndex]));
FunctionWrapper::glReadPixelsAsync(_params.x0, _params.y0, m_pTexture->realWidth, _params.height, format, type);
m_localData = FunctionWrapper::glMapBufferRangeReadAsync(GL_PIXEL_PACK_BUFFER, m_PBO[nextIndex], 0,
m_localData = FunctionWrapper::glMapBufferRangeReadAsync(GL_PIXEL_PACK_BUFFER, m_PBO[m_curIndex], 0,
m_pTexture->realWidth * _params.height * _params.colorFormatBytes, GL_MAP_READ_BIT);
return m_localData->data();
} else {
GLubyte* pixelData = nullptr;
m_bindBuffer->bind(Parameter(GL_PIXEL_PACK_BUFFER), ObjectHandle(m_PBO[_numPBO -1]));
m_bindBuffer->bind(Parameter(GL_PIXEL_PACK_BUFFER), ObjectHandle(m_PBO[m_numPBO -1]));
FunctionWrapper::glReadPixels(_params.x0, _params.y0, m_pTexture->realWidth, _params.height, format, type, 0);
pixelData = (GLubyte*)FunctionWrapper::glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0,
m_pTexture->realWidth * _params.height * _params.colorFormatBytes, GL_MAP_READ_BIT);
Expand Down
23 changes: 16 additions & 7 deletions src/Graphics/OpenGLContext/opengl_ContextImpl.cpp
Expand Up @@ -171,8 +171,12 @@ void ContextImpl::clearColorBuffer(f32 _red, f32 _green, f32 _blue, f32 _alpha)
m_cachedFunctions->getCachedClearColor()->setClearColor(_red, _green, _blue, _alpha);
FunctionWrapper::glClear(GL_COLOR_BUFFER_BIT);
} else {
GLfloat values[4] = {_red, _green, _blue, _alpha};
FunctionWrapper::glClearBufferfv(GL_COLOR, 0, values);
std::unique_ptr<GLfloat[]> values(new GLfloat[4]);
values.get()[0] = _red;
values.get()[1] = _green;
values.get()[2] = _blue;
values.get()[3] = _alpha;
FunctionWrapper::glClearBufferfv(GL_COLOR, 0, std::move(values));
}

enableScissor->enable(true);
Expand All @@ -186,7 +190,7 @@ void ContextImpl::clearDepthBuffer()

if (m_glInfo.renderer == Renderer::PowerVR) {
depthMask->setDepthMask(false);
FunctionWrapper:glClear(GL_DEPTH_BUFFER_BIT);
FunctionWrapper::glClear(GL_DEPTH_BUFFER_BIT);
}

depthMask->setDepthMask(true);
Expand Down Expand Up @@ -281,9 +285,9 @@ u32 ContextImpl::convertInternalTextureFormat(u32 _format) const
void ContextImpl::textureBarrier()
{
if (m_glInfo.texture_barrier)
glTextureBarrier();
FunctionWrapper::glTextureBarrier();
else if (m_glInfo.texture_barrierNV)
glTextureBarrierNV();
FunctionWrapper::glTextureBarrierNV();
}

/*---------------Framebuffer-------------*/
Expand Down Expand Up @@ -340,8 +344,13 @@ bool ContextImpl::blitFramebuffers(const graphics::Context::BlitFramebuffersPara

void ContextImpl::setDrawBuffers(u32 _num)
{
GLenum targets[4] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3};
glDrawBuffers(_num, targets);
std::unique_ptr<GLenum[]> targets(new GLenum[4]);
targets.get()[0] = GL_COLOR_ATTACHMENT0;
targets.get()[1] = GL_COLOR_ATTACHMENT1;
targets.get()[2] = GL_COLOR_ATTACHMENT2;
targets.get()[3] = GL_COLOR_ATTACHMENT3;

FunctionWrapper::glDrawBuffers(_num, std::move(targets));
}

graphics::PixelReadBuffer * ContextImpl::createPixelReadBuffer(size_t _sizeInBytes)
Expand Down
Expand Up @@ -224,8 +224,8 @@ namespace opengl {
class Update2DTexSubImage : public Update2DTexture
{
public:
Update2DTexSubImage(CachedBindTexture* _bind)
: m_bind(_bind) {}
Update2DTexSubImage(const GLInfo & _glinfo, CachedBindTexture* _bind)
: m_glinfo(_glinfo), m_bind(_bind) {}

void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override
{
Expand Down
21 changes: 4 additions & 17 deletions src/Graphics/OpenGLContext/opengl_UnbufferedDrawerThreadSafe.cpp
Expand Up @@ -97,25 +97,12 @@ void UnbufferedDrawerThreadSafe::drawTriangles(const graphics::Context::DrawTria
return;
}

if (config.frameBufferEmulation.N64DepthCompare == 0) {
std::unique_ptr<char[]> elementsCopy(new char[_params.elementsCount]);
std::copy_n(reinterpret_cast<char*>(_params.elements), _params.elementsCount, elementsCopy.get());
std::unique_ptr<u16[]> elementsCopy(new u16[_params.elementsCount]);
std::copy_n(reinterpret_cast<u16*>(_params.elements), _params.elementsCount, elementsCopy.get());

FunctionWrapper::glDrawElementsUnbuffered(GLenum(_params.mode), _params.elementsCount, GL_UNSIGNED_BYTE,
std::move(elementsCopy), std::move(verticesCopy));
return;
}

// Draw polygons one by one
for (GLuint i = 0; i < _params.elementsCount; i += 3) {
FunctionWrapper::glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
FunctionWrapper::glDrawElementsUnbuffered(GLenum(_params.mode), _params.elementsCount, GL_UNSIGNED_SHORT,
std::move(elementsCopy), std::move(verticesCopy));

std::unique_ptr<char[]> elementsCopy(new char[3]);
std::copy_n(reinterpret_cast<char*>(_params.elements) + i, 3, elementsCopy.get());

FunctionWrapper::glDrawElementsUnbuffered(GLenum(_params.mode), 3, GL_UNSIGNED_BYTE, std::move(elementsCopy),
std::move(verticesCopy));
}
}

void UnbufferedDrawerThreadSafe::drawRects(const graphics::Context::DrawRectParameters & _params)
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/OpenGLContext/opengl_WrappedFunctions.cpp
Expand Up @@ -2,7 +2,7 @@

namespace opengl {

std::unique_ptr<char[]> GlVertexAttribPointerUnbufferedCommand::m_attribsData;
std::vector<char> GlVertexAttribPointerUnbufferedCommand::m_attribsData;
std::unordered_map<int, std::shared_ptr<std::vector<u8>>> GlMapBufferRangeReadAsyncCommand::m_data;
std::mutex GlMapBufferRangeReadAsyncCommand::m_mapMutex;
}

0 comments on commit d28eb0c

Please sign in to comment.