John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // SwiftShader Software Renderer
|
| 2 | //
|
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 3 | // Copyright(c) 2005-2013 TransGaming Inc.
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 4 | //
|
| 5 | // All rights reserved. No part of this software may be copied, distributed, transmitted,
|
| 6 | // transcribed, stored in a retrieval system, translated into any human or computer
|
| 7 | // language by any means, or disclosed to third parties without the explicit written
|
| 8 | // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
|
| 9 | // or implied, including but not limited to any patent rights, are granted to you.
|
| 10 | //
|
| 11 |
|
| 12 | // main.cpp: DLL entry point and management of thread-local data.
|
| 13 |
|
| 14 | #include "main.h"
|
| 15 |
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 16 | #include "libGLESv2.hpp"
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 17 | #include "Framebuffer.h"
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 18 | #include "libEGL/main.h"
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 19 | #include "libEGL/Surface.h"
|
| 20 | #include "Common/Thread.hpp"
|
Nicolas Capens | afd1f9f | 2014-10-28 02:53:50 -0400 | [diff] [blame] | 21 | #include "Common/SharedLibrary.hpp"
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 22 | #include "common/debug.h"
|
| 23 |
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 24 | #if !defined(_MSC_VER)
|
| 25 | #define CONSTRUCTOR __attribute__((constructor))
|
| 26 | #define DESTRUCTOR __attribute__((destructor))
|
| 27 | #else
|
| 28 | #define CONSTRUCTOR
|
| 29 | #define DESTRUCTOR
|
| 30 | #endif
|
| 31 |
|
| 32 | static void glAttachThread()
|
| 33 | {
|
| 34 | TRACE("()");
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 35 | }
|
| 36 |
|
| 37 | static void glDetachThread()
|
| 38 | {
|
| 39 | TRACE("()");
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 40 | }
|
| 41 |
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 42 | CONSTRUCTOR static void glAttachProcess()
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 43 | {
|
| 44 | TRACE("()");
|
| 45 |
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 46 | glAttachThread();
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 47 | }
|
| 48 |
|
| 49 | DESTRUCTOR static void glDetachProcess()
|
| 50 | {
|
| 51 | TRACE("()");
|
| 52 |
|
| 53 | glDetachThread();
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 54 | }
|
| 55 |
|
| 56 | #if defined(_WIN32)
|
| 57 | extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
| 58 | {
|
| 59 | switch(reason)
|
| 60 | {
|
| 61 | case DLL_PROCESS_ATTACH:
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 62 | glAttachProcess();
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 63 | break;
|
| 64 | case DLL_THREAD_ATTACH:
|
| 65 | glAttachThread();
|
| 66 | break;
|
| 67 | case DLL_THREAD_DETACH:
|
| 68 | glDetachThread();
|
| 69 | break;
|
| 70 | case DLL_PROCESS_DETACH:
|
| 71 | glDetachProcess();
|
| 72 | break;
|
| 73 | default:
|
| 74 | break;
|
| 75 | }
|
| 76 |
|
| 77 | return TRUE;
|
| 78 | }
|
| 79 | #endif
|
| 80 |
|
Nicolas Capens | 14ee762 | 2014-10-28 23:48:41 -0400 | [diff] [blame] | 81 | namespace es2
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 82 | {
|
Nicolas Capens | 14ee762 | 2014-10-28 23:48:41 -0400 | [diff] [blame] | 83 | es2::Context *getContext()
|
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 84 | {
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 85 | egl::Context *context = libEGL->clientGetCurrentContext();
|
Nicolas Capens | 8d869e0 | 2014-12-08 16:52:06 -0500 | [diff] [blame] | 86 |
|
Nicolas Capens | b97ad2e | 2015-02-11 17:40:30 -0500 | [diff] [blame] | 87 | if(context && (context->getClientVersion() == 2 ||
|
| 88 | context->getClientVersion() == 3))
|
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 89 | {
|
Nicolas Capens | 14ee762 | 2014-10-28 23:48:41 -0400 | [diff] [blame] | 90 | return static_cast<es2::Context*>(context);
|
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 91 | }
|
Nicolas Capens | 8d869e0 | 2014-12-08 16:52:06 -0500 | [diff] [blame] | 92 |
|
Nicolas Capens | afd1f9f | 2014-10-28 02:53:50 -0400 | [diff] [blame] | 93 | return 0;
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 94 | }
|
| 95 |
|
| 96 | egl::Display *getDisplay()
|
| 97 | {
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 98 | return libEGL->clientGetCurrentDisplay();
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 99 | }
|
| 100 |
|
| 101 | Device *getDevice()
|
| 102 | {
|
Nicolas Capens | c78445c | 2014-10-27 17:29:04 -0400 | [diff] [blame] | 103 | Context *context = getContext();
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 104 |
|
Nicolas Capens | c78445c | 2014-10-27 17:29:04 -0400 | [diff] [blame] | 105 | return context ? context->getDevice() : 0;
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 106 | }
|
Nicolas Capens | d76b5df | 2014-10-28 15:54:46 -0400 | [diff] [blame] | 107 |
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 108 | // Records an error code
|
| 109 | void error(GLenum errorCode)
|
| 110 | {
|
Nicolas Capens | 14ee762 | 2014-10-28 23:48:41 -0400 | [diff] [blame] | 111 | es2::Context *context = es2::getContext();
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 112 |
|
| 113 | if(context)
|
| 114 | {
|
| 115 | switch(errorCode)
|
| 116 | {
|
| 117 | case GL_INVALID_ENUM:
|
| 118 | context->recordInvalidEnum();
|
| 119 | TRACE("\t! Error generated: invalid enum\n");
|
| 120 | break;
|
| 121 | case GL_INVALID_VALUE:
|
| 122 | context->recordInvalidValue();
|
| 123 | TRACE("\t! Error generated: invalid value\n");
|
| 124 | break;
|
| 125 | case GL_INVALID_OPERATION:
|
| 126 | context->recordInvalidOperation();
|
| 127 | TRACE("\t! Error generated: invalid operation\n");
|
| 128 | break;
|
| 129 | case GL_OUT_OF_MEMORY:
|
| 130 | context->recordOutOfMemory();
|
| 131 | TRACE("\t! Error generated: out of memory\n");
|
| 132 | break;
|
| 133 | case GL_INVALID_FRAMEBUFFER_OPERATION:
|
| 134 | context->recordInvalidFramebufferOperation();
|
| 135 | TRACE("\t! Error generated: invalid framebuffer operation\n");
|
| 136 | break;
|
| 137 | default: UNREACHABLE();
|
| 138 | }
|
| 139 | }
|
| 140 | }
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 141 | }
|
Nicolas Capens | afd1f9f | 2014-10-28 02:53:50 -0400 | [diff] [blame] | 142 |
|
| 143 | namespace egl
|
| 144 | {
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 145 | GLint getClientVersion()
|
Nicolas Capens | d76b5df | 2014-10-28 15:54:46 -0400 | [diff] [blame] | 146 | {
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 147 | Context *context = libEGL->clientGetCurrentContext();
|
| 148 |
|
| 149 | return context ? context->getClientVersion() : 0;
|
| 150 | }
|
Nicolas Capens | d76b5df | 2014-10-28 15:54:46 -0400 | [diff] [blame] | 151 | }
|
| 152 |
|
Nicolas Capens | a230805 | 2015-04-15 16:50:21 -0400 | [diff] [blame^] | 153 | egl::Context *es2CreateContext(const egl::Config *config, const egl::Context *shareContext, int clientVersion);
|
| 154 | extern "C" __eglMustCastToProperFunctionPointerType es2GetProcAddress(const char *procname);
|
| 155 | egl::Image *createBackBuffer(int width, int height, const egl::Config *config);
|
| 156 | egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
|
| 157 | sw::FrameBuffer *createFrameBuffer(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height);
|
| 158 |
|
| 159 | LibGLESv2exports::LibGLESv2exports()
|
| 160 | {
|
| 161 | this->es2CreateContext = ::es2CreateContext;
|
| 162 | this->es2GetProcAddress = ::es2GetProcAddress;
|
| 163 | this->createBackBuffer = ::createBackBuffer;
|
| 164 | this->createDepthStencil = ::createDepthStencil;
|
| 165 | this->createFrameBuffer = ::createFrameBuffer;
|
| 166 | }
|
| 167 |
|
| 168 | extern "C" LibGLESv2exports *libGLESv2exports()
|
| 169 | {
|
| 170 | static LibGLESv2exports libGLESv2;
|
| 171 | return &libGLESv2;
|
| 172 | }
|
| 173 |
|
| 174 | LibEGL libEGL;
|
| 175 | LibGLES_CM libGLES_CM; |