summaryrefslogtreecommitdiff
path: root/macosx/plugins/DFXVideo/macsrc/GL3Code.m
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-11-27 02:00:15 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-11-27 02:00:15 +0000
commita4463d88e3a0b941bef85db712517b2d67de83b4 (patch)
tree854abd0278676d587b40b00b82db1e45a43c2d03 /macosx/plugins/DFXVideo/macsrc/GL3Code.m
parent26a39c749b337ef038a949447c5356ddaa0bc912 (diff)
downloadpcsxr-a4463d88e3a0b941bef85db712517b2d67de83b4.tar.gz
Apple seems to be really pushing OpenGL3, let’s see if I can make an OpenGL 3 context on the Software renderer.
We’ll begin by splitting up the renderers into different files. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@87979 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/plugins/DFXVideo/macsrc/GL3Code.m')
-rw-r--r--macosx/plugins/DFXVideo/macsrc/GL3Code.m187
1 files changed, 187 insertions, 0 deletions
diff --git a/macosx/plugins/DFXVideo/macsrc/GL3Code.m b/macosx/plugins/DFXVideo/macsrc/GL3Code.m
new file mode 100644
index 00000000..bc4ea3e0
--- /dev/null
+++ b/macosx/plugins/DFXVideo/macsrc/GL3Code.m
@@ -0,0 +1,187 @@
+//
+// GL3Code.m
+// Pcsxr
+//
+// Created by C.W. Betts on 11/26/13.
+//
+//
+
+#import <Cocoa/Cocoa.h>
+#include <OpenGL/gl3.h>
+#include <OpenGL/gl3ext.h>
+#import <GLKit/GLKit.h>
+#import "PluginGLView.h"
+#import "SGPUPreferences.h"
+#include "externals.h"
+#undef BOOL
+#include "gpu.h"
+#include "swap.h"
+
+static int mylog2(int val)
+{
+ int i;
+ for (i=1; i<31; i++)
+ if (val <= (1 << i))
+ return (1 << i);
+
+ return -1;
+}
+
+@implementation PluginGLView (GL3)
+
+- (BOOL)setupOpenGL3
+{
+ static const NSOpenGLPixelFormatAttribute attrs[] =
+ {
+ NSOpenGLPFAAccelerated,
+ NSOpenGLPFANoRecovery,
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAOpenGLProfile,
+ NSOpenGLProfileVersion3_2Core,
+ 0
+ };
+
+ // Get pixel format from OpenGL
+ NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+ if (!pixFmt)
+ return NO;
+
+ [self setPixelFormat:pixFmt];
+
+ return NO;
+}
+
+- (void)cleanupGL3
+{
+
+}
+
+- (void)reshapeGL3
+{
+ NSOpenGLContext *oglContext = [self openGLContext];
+ NSRect rect;
+
+ [oglContext makeCurrentContext];
+ [oglContext update];
+
+ rect = [[oglContext view] bounds];
+
+ glViewport(0, 0, (int) rect.size.width, (int) rect.size.height);
+
+ //glMatrixMode(GL_PROJECTION);
+ //glLoadIdentity();
+
+ //glMatrixMode(GL_MODELVIEW);
+ //glLoadIdentity();
+
+ drawBG = YES;
+
+ [NSOpenGLContext clearCurrentContext];
+}
+
+- (void)renderScreenGL3
+{
+ NSRect rect = [[[self openGLContext] view] bounds];
+
+ GLKMatrix4 matrix = GLKMatrix4MakeOrtho(0, rect.size.width, 0, rect.size.height, 0, 0);
+}
+
+- (void)loadTexturesGL3:(GLboolean)first
+{
+
+}
+
+- (void)swapBufferGL3
+{
+
+}
+
+- (GLuint)loadShader:(GLenum)type location:(NSURL*)filename
+{
+ GLuint myShader = 0;
+
+ GLsizei logsize = 0;
+ GLint compile_status = GL_TRUE;
+ char *log = NULL;
+ char *src = NULL;
+
+ /* creation d'un shader de sommet */
+ myShader = glCreateShader(type);
+ if(myShader == 0)
+ {
+ fprintf(stderr, "impossible de creer le shader\n");
+ return 0;
+ }
+
+ /* chargement du code source */
+ src = [self loadSource:filename];
+ if(src == NULL)
+ {
+ /* theoriquement, la fonction LoadSource a deja affiche un message
+ d'erreur, nous nous contenterons de supprimer notre shader
+ et de retourner 0 */
+
+ glDeleteShader(myShader);
+ return 0;
+ }
+
+ /* assignation du code source */
+ glShaderSource(myShader, 1, (const GLchar**)&src, NULL);
+
+ /* compilation du shader */
+ glCompileShader(myShader);
+
+ /* liberation de la memoire du code source */
+ free(src);
+ src = NULL;
+
+ /* verification du succes de la compilation */
+ glGetShaderiv(myShader, GL_COMPILE_STATUS, &compile_status);
+ if(compile_status != GL_TRUE)
+ {
+ /* erreur a la compilation recuperation du log d'erreur */
+
+ /* on recupere la taille du message d'erreur */
+ glGetShaderiv(myShader, GL_INFO_LOG_LENGTH, &logsize);
+
+ /* on alloue un espace memoire dans lequel OpenGL ecrira le message */
+ log = malloc(logsize + 1);
+ if(log == NULL)
+ {
+ fprintf(stderr, "impossible d'allouer de la memoire !\n");
+ return 0;
+ }
+ /* initialisation du contenu */
+ memset(log, '\0', logsize + 1);
+
+ glGetShaderInfoLog(myShader, logsize, &logsize, log);
+ fprintf(stderr, "impossible de compiler le shader '%s' :\n%s",
+ [[filename path] UTF8String], log);
+
+ /* ne pas oublier de liberer la memoire et notre shader */
+ free(log);
+ glDeleteShader(myShader);
+
+ return 0;
+ }
+ return myShader;
+}
+
+@end
+
+void printProgramInfoLog(GLuint obj)
+{
+ int infologLength = 0;
+ int charsWritten = 0;
+ char *infoLog;
+
+ glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &infologLength);
+
+ if (infologLength > 0)
+ {
+ infoLog = (char *)malloc(infologLength);
+ glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
+ printf("%s\n",infoLog);
+ free(infoLog);
+ }
+}