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 "libGLES_CM.hpp"
\r
17 #include "Framebuffer.h"
\r
18 #include "libEGL/Surface.h"
\r
19 #include "Common/Thread.hpp"
\r
20 #include "Common/SharedLibrary.hpp"
\r
21 #include "common/debug.h"
\r
23 #include <GLES/glext.h>
\r
25 #if !defined(_MSC_VER)
\r
26 #define CONSTRUCTOR __attribute__((constructor))
\r
27 #define DESTRUCTOR __attribute__((destructor))
\r
33 static void glAttachThread()
\r
38 static void glDetachThread()
\r
43 CONSTRUCTOR static void glAttachProcess()
\r
50 DESTRUCTOR static void glDetachProcess()
\r
58 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
\r
62 case DLL_PROCESS_ATTACH:
\r
65 case DLL_THREAD_ATTACH:
\r
68 case DLL_THREAD_DETACH:
\r
71 case DLL_PROCESS_DETACH:
\r
84 es1::Context *getContext()
\r
86 egl::Context *context = libEGL->clientGetCurrentContext();
\r
88 if(context && context->getClientVersion() == 1)
\r
90 return static_cast<es1::Context*>(context);
\r
96 egl::Display *getDisplay()
\r
98 return libEGL->clientGetCurrentDisplay();
\r
101 Device *getDevice()
\r
103 Context *context = getContext();
\r
105 return context ? context->getDevice() : 0;
\r
108 // Records an error code
\r
109 void error(GLenum errorCode)
\r
111 es1::Context *context = es1::getContext();
\r
117 case GL_INVALID_ENUM:
\r
118 context->recordInvalidEnum();
\r
119 TRACE("\t! Error generated: invalid enum\n");
\r
121 case GL_INVALID_VALUE:
\r
122 context->recordInvalidValue();
\r
123 TRACE("\t! Error generated: invalid value\n");
\r
125 case GL_INVALID_OPERATION:
\r
126 context->recordInvalidOperation();
\r
127 TRACE("\t! Error generated: invalid operation\n");
\r
129 case GL_OUT_OF_MEMORY:
\r
130 context->recordOutOfMemory();
\r
131 TRACE("\t! Error generated: out of memory\n");
\r
133 case GL_INVALID_FRAMEBUFFER_OPERATION_OES:
\r
134 context->recordInvalidFramebufferOperation();
\r
135 TRACE("\t! Error generated: invalid framebuffer operation\n");
\r
137 default: UNREACHABLE();
\r
143 egl::Context *es1CreateContext(const egl::Config *config, const egl::Context *shareContext);
\r
144 extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname);
\r
145 egl::Image *createBackBuffer(int width, int height, const egl::Config *config);
\r
146 egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
\r
147 sw::FrameBuffer *createFrameBuffer(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height);
\r
149 LibGLES_CMexports::LibGLES_CMexports()
\r
151 this->es1CreateContext = ::es1CreateContext;
\r
152 this->es1GetProcAddress = ::es1GetProcAddress;
\r
153 this->createBackBuffer = ::createBackBuffer;
\r
154 this->createDepthStencil = ::createDepthStencil;
\r
155 this->createFrameBuffer = ::createFrameBuffer;
\r
156 this->glEGLImageTargetTexture2DOES = ::glEGLImageTargetTexture2DOES;
\r
159 extern "C" LibGLES_CMexports *libGLES_CM_swiftshader()
\r
161 static LibGLES_CMexports libGLES_CM;
\r
162 return &libGLES_CM;
\r