1 // SwiftShader Software Renderer
\r
3 // Copyright(c) 2005-2013 TransGaming Inc.
\r
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,
\r
6 // transcribed, stored in a retrieval system, translated into any human or computer
\r
7 // language by any means, or disclosed to third parties without the explicit written
\r
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
\r
9 // or implied, including but not limited to any patent rights, are granted to you.
\r
12 // main.cpp: DLL entry point and management of thread-local data.
\r
16 #include "Framebuffer.h"
\r
17 #include "libEGL/Surface.h"
\r
18 #include "Common/Thread.hpp"
\r
19 #include "Common/SharedLibrary.hpp"
\r
20 #include "common/debug.h"
\r
22 #if !defined(_MSC_VER)
\r
23 #define CONSTRUCTOR __attribute__((constructor))
\r
24 #define DESTRUCTOR __attribute__((destructor))
\r
30 static void glAttachThread()
\r
35 static void glDetachThread()
\r
40 CONSTRUCTOR static bool glAttachProcess()
\r
47 const char *libEGL_lib = "libEGL.dll";
\r
49 const char *libEGL_lib = "libEGL.so.1";
\r
52 libEGL = loadLibrary(libEGL_lib);
\r
53 egl::getCurrentContext = (egl::Context *(*)())getProcAddress(libEGL, "clientGetCurrentContext");
\r
54 egl::getCurrentDisplay = (egl::Display *(*)())getProcAddress(libEGL, "clientGetCurrentDisplay");
\r
59 DESTRUCTOR static void glDetachProcess()
\r
64 freeLibrary(libEGL);
\r
68 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
\r
72 case DLL_PROCESS_ATTACH:
\r
73 return glAttachProcess();
\r
75 case DLL_THREAD_ATTACH:
\r
78 case DLL_THREAD_DETACH:
\r
81 case DLL_PROCESS_DETACH:
\r
94 es2::Context *getContext()
\r
96 egl::Context *context = egl::getCurrentContext();
\r
98 if(context && context->getClientVersion() == 2)
\r
100 return static_cast<es2::Context*>(context);
\r
106 egl::Display *getDisplay()
\r
108 return egl::getCurrentDisplay();
\r
111 Device *getDevice()
\r
113 Context *context = getContext();
\r
115 return context ? context->getDevice() : 0;
\r
121 GLint getClientVersion()
\r
123 Context *context = egl::getCurrentContext();
\r
125 return context ? context->getClientVersion() : 0;
\r
129 // Records an error code
\r
130 void error(GLenum errorCode)
\r
132 es2::Context *context = es2::getContext();
\r
138 case GL_INVALID_ENUM:
\r
139 context->recordInvalidEnum();
\r
140 TRACE("\t! Error generated: invalid enum\n");
\r
142 case GL_INVALID_VALUE:
\r
143 context->recordInvalidValue();
\r
144 TRACE("\t! Error generated: invalid value\n");
\r
146 case GL_INVALID_OPERATION:
\r
147 context->recordInvalidOperation();
\r
148 TRACE("\t! Error generated: invalid operation\n");
\r
150 case GL_OUT_OF_MEMORY:
\r
151 context->recordOutOfMemory();
\r
152 TRACE("\t! Error generated: out of memory\n");
\r
154 case GL_INVALID_FRAMEBUFFER_OPERATION:
\r
155 context->recordInvalidFramebufferOperation();
\r
156 TRACE("\t! Error generated: invalid framebuffer operation\n");
\r
158 default: UNREACHABLE();
\r
165 egl::Context *(*getCurrentContext)() = 0;
\r
166 egl::Display *(*getCurrentDisplay)() = 0;
\r
169 void *libEGL = 0; // Handle to the libEGL module
\r