Skip to content

Commit

Permalink
Cocoa Port: Update the OpenGL blitter code to reflect the current cod…
Browse files Browse the repository at this point in the history
…e pattern in OGLRender.h.

- Centralize all header includes into OGLDisplayOutput.h.
- Update all extension versions of OpenGL functions/tokens that would be core in OpenGL v1.5.
  • Loading branch information
rogerman committed Jul 15, 2024
1 parent 80694cd commit cc0b3ed
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 93 deletions.
156 changes: 78 additions & 78 deletions desmume/src/frontend/cocoa/OGLDisplayOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5628,34 +5628,34 @@ OGLImage::OGLImage(OGLContextInfo *contextInfo, GLsizei imageWidth, GLsizei imag
};

// Set up VBOs
glGenBuffersARB(1, &_vboVertexID);
glGenBuffersARB(1, &_vboTexCoordID);
glGenBuffers(1, &_vboVertexID);
glGenBuffers(1, &_vboTexCoordID);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vtxBuffer), vtxBuffer, GL_STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(_texCoordBuffer), _texCoordBuffer, GL_STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ARRAY_BUFFER, _vboVertexID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vtxBuffer), vtxBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glBufferData(GL_ARRAY_BUFFER, sizeof(_texCoordBuffer), _texCoordBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

// Set up VAO
glGenVertexArraysDESMUME(1, &_vaoMainStatesID);
glBindVertexArrayDESMUME(_vaoMainStatesID);

if (contextInfo->IsShaderSupported())
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_INT, GL_FALSE, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glVertexAttribPointer(OGLVertexAttributeID_TexCoord0, 2, GL_FLOAT, GL_FALSE, 0, 0);

glEnableVertexAttribArray(OGLVertexAttributeID_Position);
glEnableVertexAttribArray(OGLVertexAttributeID_TexCoord0);
}
else
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboVertexID);
glVertexPointer(2, GL_INT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glTexCoordPointer(2, GL_FLOAT, 0, 0);

glEnableClientState(GL_VERTEX_ARRAY);
Expand Down Expand Up @@ -5721,8 +5721,8 @@ OGLImage::~OGLImage()
_isVAOPresent = false;
}

glDeleteBuffersARB(1, &this->_vboVertexID);
glDeleteBuffersARB(1, &this->_vboTexCoordID);
glDeleteBuffers(1, &this->_vboVertexID);
glDeleteBuffers(1, &this->_vboTexCoordID);
glDeleteTextures(1, &this->_texCPUFilterDstID);
glDeleteTextures(1, &this->_texVideoInputDataID);

Expand Down Expand Up @@ -6223,8 +6223,8 @@ void OGLImage::ProcessOGL()
// Output
this->_texVideoOutputID = this->_texVideoPixelScalerID;

glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_vboTexCoordID);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(this->_texCoordBuffer), this->_texCoordBuffer);
glBindBuffer(GL_ARRAY_BUFFER, this->_vboTexCoordID);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(this->_texCoordBuffer), this->_texCoordBuffer);
}

void OGLImage::RenderOGL()
Expand Down Expand Up @@ -6330,22 +6330,22 @@ OGLHUDLayer::OGLHUDLayer(OGLVideoOutput *oglVO)
_workingCharBufferList->reserve(16);

// Set up VBOs
glGenBuffersARB(1, &_vboPositionVertexID);
glGenBuffersARB(1, &_vboColorVertexID);
glGenBuffersARB(1, &_vboTexCoordID);
glGenBuffersARB(1, &_vboElementID);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboPositionVertexID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboColorVertexID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, HUD_VERTEX_COLOR_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _vboElementID);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(GLshort) * HUD_TOTAL_ELEMENTS * 6, NULL, GL_STATIC_DRAW_ARB);
GLshort *idxBufferPtr = (GLshort *)glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
glGenBuffers(1, &_vboPositionVertexID);
glGenBuffers(1, &_vboColorVertexID);
glGenBuffers(1, &_vboTexCoordID);
glGenBuffers(1, &_vboElementID);

glBindBuffer(GL_ARRAY_BUFFER, _vboPositionVertexID);
glBufferData(GL_ARRAY_BUFFER, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, _vboColorVertexID);
glBufferData(GL_ARRAY_BUFFER, HUD_VERTEX_COLOR_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glBufferData(GL_ARRAY_BUFFER, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboElementID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLshort) * HUD_TOTAL_ELEMENTS * 6, NULL, GL_STATIC_DRAW);
GLshort *idxBufferPtr = (GLshort *)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_ARB);

for (size_t i = 0, j = 0, k = 0; i < HUD_TOTAL_ELEMENTS; i++, j+=6, k+=4)
{
Expand All @@ -6357,36 +6357,36 @@ OGLHUDLayer::OGLHUDLayer(OGLVideoOutput *oglVO)
idxBufferPtr[j+5] = k+0;
}

glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

// Set up VAO
glGenVertexArraysDESMUME(1, &_vaoMainStatesID);
glBindVertexArrayDESMUME(_vaoMainStatesID);

if (oglVO->GetContextInfo()->IsShaderSupported())
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboPositionVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboPositionVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboColorVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboColorVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glVertexAttribPointer(OGLVertexAttributeID_TexCoord0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _vboElementID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboElementID);

glEnableVertexAttribArray(OGLVertexAttributeID_Position);
glEnableVertexAttribArray(OGLVertexAttributeID_Color);
glEnableVertexAttribArray(OGLVertexAttributeID_TexCoord0);
}
else
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboPositionVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboPositionVertexID);
glVertexPointer(2, GL_FLOAT, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboColorVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboColorVertexID);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _vboElementID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboElementID);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
Expand All @@ -6405,10 +6405,10 @@ OGLHUDLayer::~OGLHUDLayer()
}

glDeleteVertexArraysDESMUME(1, &this->_vaoMainStatesID);
glDeleteBuffersARB(1, &this->_vboPositionVertexID);
glDeleteBuffersARB(1, &this->_vboColorVertexID);
glDeleteBuffersARB(1, &this->_vboTexCoordID);
glDeleteBuffersARB(1, &this->_vboElementID);
glDeleteBuffers(1, &this->_vboPositionVertexID);
glDeleteBuffers(1, &this->_vboColorVertexID);
glDeleteBuffers(1, &this->_vboTexCoordID);
glDeleteBuffers(1, &this->_vboElementID);

glDeleteTextures(1, &this->_texCharMap);

Expand Down Expand Up @@ -6517,25 +6517,25 @@ void OGLHUDLayer::_UpdateVerticesOGL()
return;
}

glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_vboPositionVertexID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW_ARB);
float *vtxPositionBufferPtr = (float *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
glBindBuffer(GL_ARRAY_BUFFER, this->_vboPositionVertexID);
glBufferData(GL_ARRAY_BUFFER, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
float *vtxPositionBufferPtr = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY_ARB);
this->_output->SetHUDPositionVertices((float)this->_output->GetViewportWidth(), (float)this->_output->GetViewportHeight(), vtxPositionBufferPtr);
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
glUnmapBuffer(GL_ARRAY_BUFFER);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_vboColorVertexID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, HUD_VERTEX_COLOR_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW_ARB);
uint32_t *vtxColorBufferPtr = (uint32_t *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
glBindBuffer(GL_ARRAY_BUFFER, this->_vboColorVertexID);
glBufferData(GL_ARRAY_BUFFER, HUD_VERTEX_COLOR_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
uint32_t *vtxColorBufferPtr = (uint32_t *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY_ARB);
this->_output->SetHUDColorVertices(vtxColorBufferPtr);
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
glUnmapBuffer(GL_ARRAY_BUFFER);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_vboTexCoordID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW_ARB);
float *texCoordBufferPtr = (float *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
glBindBuffer(GL_ARRAY_BUFFER, this->_vboTexCoordID);
glBufferData(GL_ARRAY_BUFFER, HUD_VERTEX_ATTRIBUTE_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
float *texCoordBufferPtr = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY_ARB);
this->_output->SetHUDTextureCoordinates(texCoordBufferPtr);
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
glUnmapBuffer(GL_ARRAY_BUFFER);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

this->_output->ClearHUDNeedsUpdate();
}
Expand Down Expand Up @@ -6725,34 +6725,34 @@ OGLDisplayLayer::OGLDisplayLayer(OGLVideoOutput *oglVO)
pthread_rwlock_init(&_cpuFilterRWLock[NDSDisplayID_Touch][1], NULL);

// Set up VBOs
glGenBuffersARB(1, &_vboVertexID);
glGenBuffersARB(1, &_vboTexCoordID);
glGenBuffers(1, &_vboVertexID);
glGenBuffers(1, &_vboTexCoordID);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(GLfloat) * (4 * 8), NULL, GL_STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(GLfloat) * (4 * 8), NULL, GL_STREAM_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ARRAY_BUFFER, _vboVertexID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * (4 * 8), NULL, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * (4 * 8), NULL, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

// Set up VAO
glGenVertexArraysDESMUME(1, &_vaoMainStatesID);
glBindVertexArrayDESMUME(_vaoMainStatesID);

if (this->_output->GetContextInfo()->IsShaderSupported())
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboVertexID);
glVertexAttribPointer(OGLVertexAttributeID_Position, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glVertexAttribPointer(OGLVertexAttributeID_TexCoord0, 2, GL_FLOAT, GL_FALSE, 0, NULL);

glEnableVertexAttribArray(OGLVertexAttributeID_Position);
glEnableVertexAttribArray(OGLVertexAttributeID_TexCoord0);
}
else
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboVertexID);
glBindBuffer(GL_ARRAY_BUFFER, _vboVertexID);
glVertexPointer(2, GL_FLOAT, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vboTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, _vboTexCoordID);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);

glEnableClientState(GL_VERTEX_ARRAY);
Expand Down Expand Up @@ -6816,8 +6816,8 @@ OGLDisplayLayer::~OGLDisplayLayer()
glDeleteVertexArraysDESMUME(1, &this->_vaoMainStatesID);
}

glDeleteBuffersARB(1, &this->_vboVertexID);
glDeleteBuffersARB(1, &this->_vboTexCoordID);
glDeleteBuffers(1, &this->_vboVertexID);
glDeleteBuffers(1, &this->_vboTexCoordID);

if (_output->GetContextInfo()->IsShaderSupported())
{
Expand Down Expand Up @@ -6863,10 +6863,10 @@ void OGLDisplayLayer::_UpdateRotationScaleOGL()

void OGLDisplayLayer::_UpdateVerticesOGL()
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_vboVertexID);
float *vtxBufferPtr = (float *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
glBindBuffer(GL_ARRAY_BUFFER, this->_vboVertexID);
float *vtxBufferPtr = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY_ARB);
this->_output->SetScreenVertices(vtxBufferPtr);
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
glUnmapBuffer(GL_ARRAY_BUFFER);

this->_needUpdateVertices = false;
}
Expand Down Expand Up @@ -7480,15 +7480,15 @@ void OGLDisplayLayer::ProcessOGL()
}

// Update the texture coordinates
glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_vboTexCoordID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (4 * 8) * sizeof(GLfloat), NULL, GL_STREAM_DRAW_ARB);
float *texCoordPtr = (float *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
glBindBuffer(GL_ARRAY_BUFFER, this->_vboTexCoordID);
glBufferData(GL_ARRAY_BUFFER, (4 * 8) * sizeof(GLfloat), NULL, GL_STREAM_DRAW);
float *texCoordPtr = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY_ARB);

this->_output->SetScreenTextureCoordinates((float)width[NDSDisplayID_Main], (float)height[NDSDisplayID_Main],
(float)width[NDSDisplayID_Touch], (float)height[NDSDisplayID_Touch],
texCoordPtr);

glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
glUnmapBuffer(GL_ARRAY_BUFFER);

// OpenGL shader-based filters can modify the viewport, so it needs to be reset here.
glViewport(0, 0, this->_output->GetViewportWidth(), this->_output->GetViewportHeight());
Expand Down
18 changes: 10 additions & 8 deletions desmume/src/frontend/cocoa/OGLDisplayOutput.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2014-2022 DeSmuME team
Copyright (C) 2014-2024 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -18,16 +18,18 @@
#ifndef _OGLDISPLAYOUTPUT_H_
#define _OGLDISPLAYOUTPUT_H_

#ifndef _OGLDISPLAYOUTPUT_3_2_H_

#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#ifdef _OGLDISPLAYOUTPUT_3_2_H_
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#else
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#endif

#include <OpenGL/OpenGL.h>
#endif

#endif // _OGLDISPLAYOUTPUT_3_2_H_

#include <set>
#include <string>
#include <pthread.h>
Expand All @@ -47,7 +49,7 @@ enum ShaderSupportTier
ShaderSupport_MidTier = 3,
ShaderSupport_HighTier = 4,
ShaderSupport_TopTier = 5,
ShaderSupport_FutureTier = 6,
ShaderSupport_FutureTier = 6
};

struct OGLProcessedFrameInfo
Expand Down
8 changes: 1 addition & 7 deletions desmume/src/frontend/cocoa/OGLDisplayOutput_3_2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2015 DeSmuME team
Copyright (C) 2015-2024 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -18,12 +18,6 @@
#ifndef _OGLDISPLAYOUTPUT_3_2_H_
#define _OGLDISPLAYOUTPUT_3_2_H_

#if defined(__APPLE__)
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#include <OpenGL/OpenGL.h>
#endif

#include "OGLDisplayOutput.h"

class OGLContextInfo_3_2 : public OGLContextInfo
Expand Down

0 comments on commit cc0b3ed

Please sign in to comment.