Commit a9b4937f by Nicolas Capens

Implement an OpenGL 2.1 prototype.

Bug 18962347 Change-Id: I9a7b07647b1b3f561dd9e4597670e63641b155a8 Reviewed-on: https://swiftshader-review.googlesource.com/1810Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 80b4125a
......@@ -11,7 +11,6 @@
// Buffer.cpp: Implements the Buffer class, representing storage of vertex and/or
// index data. Implements GL buffer objects and related functionality.
// [OpenGL ES 2.0.24] section 2.9 page 21.
#include "Buffer.h"
......
......@@ -11,7 +11,6 @@
// Buffer.h: Defines the Buffer class, representing storage of vertex and/or
// index data. Implements GL buffer objects and related functionality.
// [OpenGL ES 2.0.24] section 2.9 page 21.
#ifndef LIBGL_BUFFER_H_
#define LIBGL_BUFFER_H_
......@@ -19,8 +18,11 @@
#include "common/Object.hpp"
#include "Common/Resource.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
#include <cstddef>
#include <vector>
......
......@@ -140,6 +140,25 @@ namespace gl
setVertexShaderConstantF(i, zero, 1);
}
setLightingEnable(false);
setGlobalAmbient(sw::Color<float>(0.2f, 0.2f, 0.2f, 1.0f));
setMaterialAmbient(sw::Color<float>(0.2f, 0.2f, 0.2f, 1.0f));
setMaterialDiffuse(sw::Color<float>(0.8f, 0.8f, 0.8f, 1.0f));
setMaterialSpecular(sw::Color<float>(0.0f, 0.0f, 0.0f, 1.0f));
setMaterialEmission(sw::Color<float>(0.0f, 0.0f, 0.0f, 1.0f));
for(int i = 0; i < 8; i++)
{
setLightEnable(i, false);
setLightAttenuation(i, 1.0f, 0.0f, 0.0f);
}
setDiffuseMaterialSource(sw::MATERIAL_COLOR1);
setSpecularMaterialSource(sw::MATERIAL_MATERIAL);
setAmbientMaterialSource(sw::MATERIAL_COLOR1);
setEmissiveMaterialSource(sw::MATERIAL_MATERIAL);
}
Device::~Device()
......@@ -370,13 +389,14 @@ namespace gl
case DRAW_TRIANGLELIST: drawType = sw::DRAW_TRIANGLELIST; break;
case DRAW_TRIANGLESTRIP: drawType = sw::DRAW_TRIANGLESTRIP; break;
case DRAW_TRIANGLEFAN: drawType = sw::DRAW_TRIANGLEFAN; break;
case DRAW_QUADLIST: drawType = sw::DRAW_QUADLIST; break;
default: UNREACHABLE();
}
draw(drawType, 0, primitiveCount);
}
void Device::setDepthStencilSurface(egl::Image *depthStencil)
void Device::setDepthStencilSurface(Image *depthStencil)
{
if(this->depthStencil == depthStencil)
{
......@@ -423,7 +443,7 @@ namespace gl
scissorEnable = enable;
}
void Device::setRenderTarget(egl::Image *renderTarget)
void Device::setRenderTarget(Image *renderTarget)
{
if(renderTarget)
{
......@@ -470,7 +490,7 @@ namespace gl
this->viewport = viewport;
}
bool Device::stretchRect(egl::Image *source, const sw::Rect *sourceRect, egl::Image *dest, const sw::Rect *destRect, bool filter)
bool Device::stretchRect(Image *source, const sw::Rect *sourceRect, Image *dest, const sw::Rect *destRect, bool filter)
{
if(!source || !dest || !validRectangle(sourceRect, source) || !validRectangle(destRect, dest))
{
......@@ -721,7 +741,7 @@ namespace gl
return true;
}
bool Device::validRectangle(const sw::Rect *rect, egl::Image *surface)
bool Device::validRectangle(const sw::Rect *rect, Image *surface)
{
if(!rect)
{
......
......@@ -14,15 +14,10 @@
#include "Renderer/Renderer.hpp"
namespace egl
{
class Image;
}
namespace gl
{
class Texture;
class Image;
class Texture;
enum PrimitiveType
{
......@@ -32,7 +27,8 @@ namespace gl
DRAW_LINELOOP,
DRAW_TRIANGLELIST,
DRAW_TRIANGLESTRIP,
DRAW_TRIANGLEFAN
DRAW_TRIANGLEFAN,
DRAW_QUADLIST
};
struct Viewport
......@@ -59,17 +55,17 @@ namespace gl
virtual Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
virtual void drawIndexedPrimitive(PrimitiveType type, unsigned int indexOffset, unsigned int primitiveCount, int indexSize);
virtual void drawPrimitive(PrimitiveType primitiveType, unsigned int primiveCount);
virtual void setDepthStencilSurface(egl::Image *newDepthStencil);
virtual void setDepthStencilSurface(Image *newDepthStencil);
virtual void setPixelShader(sw::PixelShader *shader);
virtual void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
virtual void setScissorEnable(bool enable);
virtual void setRenderTarget(egl::Image *renderTarget);
virtual void setRenderTarget(Image *renderTarget);
virtual void setScissorRect(const sw::Rect &rect);
virtual void setVertexShader(sw::VertexShader *shader);
virtual void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
virtual void setViewport(const Viewport &viewport);
virtual bool stretchRect(egl::Image *sourceSurface, const sw::Rect *sourceRect, egl::Image *destSurface, const sw::Rect *destRect, bool filter);
virtual bool stretchRect(Image *sourceSurface, const sw::Rect *sourceRect, Image *destSurface, const sw::Rect *destRect, bool filter);
virtual void finish();
private:
......@@ -79,7 +75,7 @@ namespace gl
void bindShaderConstants();
bool bindViewport(); // Also adjusts for scissoring
bool validRectangle(const sw::Rect *rect, egl::Image *surface);
bool validRectangle(const sw::Rect *rect, Image *surface);
Viewport viewport;
sw::Rect scissorRect;
......@@ -96,8 +92,8 @@ namespace gl
float pixelShaderConstantF[224][4];
float vertexShaderConstantF[256][4];
egl::Image *renderTarget;
egl::Image *depthStencil;
Image *renderTarget;
Image *depthStencil;
};
}
......
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2013 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// Display.cpp: Implements the Display class, representing the abstract
// display on which graphics are drawn.
#include "Display.h"
#include "main.h"
#include "mathutil.h"
#include "Device.hpp"
#include "common/debug.h"
#include <algorithm>
#include <vector>
#include <map>
namespace gl
{
typedef std::map<NativeDisplayType, Display*> DisplayMap;
DisplayMap displays;
Display *Display::getDisplay(NativeDisplayType displayId)
{
if(displays.find(displayId) != displays.end())
{
return displays[displayId];
}
// FIXME: Check if displayId is a valid display device context
Display *display = new Display(displayId);
displays[displayId] = display;
return display;
}
Display::Display(NativeDisplayType displayId) : displayId(displayId)
{
mMinSwapInterval = 1;
mMaxSwapInterval = 0;
}
Display::~Display()
{
terminate();
displays.erase(displayId);
}
static void cpuid(int registers[4], int info)
{
#if defined(_WIN32)
__cpuid(registers, info);
#else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#endif
}
static bool detectSSE()
{
#if defined(__APPLE__)
int SSE = false;
size_t length = sizeof(SSE);
sysctlbyname("hw.optional.sse", &SSE, &length, 0, 0);
return SSE;
#else
int registers[4];
cpuid(registers, 1);
return (registers[3] & 0x02000000) != 0;
#endif
}
bool Display::initialize()
{
if(isInitialized())
{
return true;
}
if(!detectSSE())
{
return false;
}
mMinSwapInterval = 0;
mMaxSwapInterval = 4;
if(!isInitialized())
{
terminate();
return false;
}
return true;
}
void Display::terminate()
{
while(!mSurfaceSet.empty())
{
destroySurface(*mSurfaceSet.begin());
}
while(!mContextSet.empty())
{
destroyContext(*mContextSet.begin());
}
}
gl::Context *Display::createContext(const gl::Context *shareContext)
{
gl::Context *context = new gl::Context(shareContext);
mContextSet.insert(context);
return context;
}
void Display::destroySurface(Surface *surface)
{
delete surface;
mSurfaceSet.erase(surface);
}
void Display::destroyContext(gl::Context *context)
{
delete context;
if(context == gl::getContext())
{
gl::makeCurrent(NULL, NULL, NULL);
}
mContextSet.erase(context);
}
bool Display::isInitialized() const
{
return mMinSwapInterval <= mMaxSwapInterval;
}
bool Display::isValidContext(gl::Context *context)
{
return mContextSet.find(context) != mContextSet.end();
}
bool Display::isValidSurface(Surface *surface)
{
return mSurfaceSet.find(surface) != mSurfaceSet.end();
}
bool Display::isValidWindow(NativeWindowType window)
{
#if defined(_WIN32)
return IsWindow(window) == TRUE;
#else
XWindowAttributes windowAttributes;
Status status = XGetWindowAttributes(displayId, window, &windowAttributes);
return status == True;
#endif
}
GLint Display::getMinSwapInterval()
{
return mMinSwapInterval;
}
GLint Display::getMaxSwapInterval()
{
return mMaxSwapInterval;
}
Surface *Display::getPrimarySurface()
{
if(mSurfaceSet.size() == 0)
{
Surface *surface = new Surface(this, WindowFromDC(displayId));
if(!surface->initialize())
{
delete surface;
return 0;
}
mSurfaceSet.insert(surface);
gl::setCurrentDrawSurface(surface);
}
return *mSurfaceSet.begin();
}
NativeDisplayType Display::getNativeDisplay() const
{
return displayId;
}
DisplayMode Display::getDisplayMode() const
{
DisplayMode displayMode = {0};
#if defined(_WIN32)
HDC deviceContext = GetDC(0);
displayMode.width = ::GetDeviceCaps(deviceContext, HORZRES);
displayMode.height = ::GetDeviceCaps(deviceContext, VERTRES);
unsigned int bpp = ::GetDeviceCaps(deviceContext, BITSPIXEL);
switch(bpp)
{
case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break;
case 24: displayMode.format = sw::FORMAT_R8G8B8; break;
case 16: displayMode.format = sw::FORMAT_R5G6B5; break;
default:
ASSERT(false); // Unexpected display mode color depth
}
ReleaseDC(0, deviceContext);
#else
Screen *screen = XDefaultScreenOfDisplay(displayId);
displayMode.width = XWidthOfScreen(screen);
displayMode.height = XHeightOfScreen(screen);
unsigned int bpp = XPlanesOfScreen(screen);
switch(bpp)
{
case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break;
case 24: displayMode.format = sw::FORMAT_R8G8B8; break;
case 16: displayMode.format = sw::FORMAT_R5G6B5; break;
default:
ASSERT(false); // Unexpected display mode color depth
}
#endif
return displayMode;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// Display.h: Defines the Display class, representing the abstract
// display on which graphics are drawn.
#ifndef INCLUDE_DISPLAY_H_
#define INCLUDE_DISPLAY_H_
#include "Surface.h"
#include "Context.h"
#include "Device.hpp"
#include <set>
namespace gl
{
struct DisplayMode
{
unsigned int width;
unsigned int height;
sw::Format format;
};
class Display
{
public:
~Display();
static Display *getDisplay(NativeDisplayType displayId);
bool initialize();
void terminate();
Context *createContext(const Context *shareContext);
void destroySurface(Surface *surface);
void destroyContext(Context *context);
bool isInitialized() const;
bool isValidContext(Context *context);
bool isValidSurface(Surface *surface);
bool isValidWindow(NativeWindowType window);
GLint getMinSwapInterval();
GLint getMaxSwapInterval();
virtual Surface *getPrimarySurface();
NativeDisplayType getNativeDisplay() const;
private:
Display(NativeDisplayType displayId);
DisplayMode getDisplayMode() const;
const NativeDisplayType displayId;
GLint mMaxSwapInterval;
GLint mMinSwapInterval;
typedef std::set<Surface*> SurfaceSet;
SurfaceSet mSurfaceSet;
typedef std::set<Context*> ContextSet;
ContextSet mContextSet;
};
}
#endif // INCLUDE_DISPLAY_H_
......@@ -14,8 +14,11 @@
#ifndef LIBGL_FENCE_H_
#define LIBGL_FENCE_H_
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......
......@@ -10,7 +10,7 @@
//
// Framebuffer.cpp: Implements the Framebuffer class. Implements GL framebuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
// objects and related functionality.
#include "Framebuffer.h"
......@@ -123,7 +123,7 @@ void Framebuffer::detachRenderbuffer(GLuint renderbuffer)
// Increments refcount on surface.
// caller must Release() the returned surface
egl::Image *Framebuffer::getRenderTarget()
Image *Framebuffer::getRenderTarget()
{
Renderbuffer *colorbuffer = mColorbufferPointer;
......@@ -137,7 +137,7 @@ egl::Image *Framebuffer::getRenderTarget()
// Increments refcount on surface.
// caller must Release() the returned surface
egl::Image *Framebuffer::getDepthStencil()
Image *Framebuffer::getDepthStencil()
{
Renderbuffer *depthstencilbuffer = mDepthbufferPointer;
......@@ -323,11 +323,11 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples)
}
else if(width != depthbuffer->getWidth() || height != depthbuffer->getHeight())
{
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
}
else if(samples != depthbuffer->getSamples())
{
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT;
}
}
......@@ -375,11 +375,11 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples)
}
else if(width != stencilbuffer->getWidth() || height != stencilbuffer->getHeight())
{
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
}
else if(samples != stencilbuffer->getSamples())
{
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT;
}
}
......
......@@ -10,7 +10,7 @@
//
// Framebuffer.h: Defines the Framebuffer class. Implements GL framebuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
// objects and related functionality.
#ifndef LIBGL_FRAMEBUFFER_H_
#define LIBGL_FRAMEBUFFER_H_
......@@ -18,8 +18,11 @@
#include "common/Object.hpp"
#include "Image.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......@@ -43,8 +46,8 @@ public:
void detachTexture(GLuint texture);
void detachRenderbuffer(GLuint renderbuffer);
egl::Image *getRenderTarget();
egl::Image *getDepthStencil();
Image *getRenderTarget();
Image *getDepthStencil();
Renderbuffer *getColorbuffer();
Renderbuffer *getDepthbuffer();
......@@ -65,13 +68,13 @@ public:
protected:
GLenum mColorbufferType;
gl::BindingPointer<Renderbuffer> mColorbufferPointer;
BindingPointer<Renderbuffer> mColorbufferPointer;
GLenum mDepthbufferType;
gl::BindingPointer<Renderbuffer> mDepthbufferPointer;
BindingPointer<Renderbuffer> mDepthbufferPointer;
GLenum mStencilbufferType;
gl::BindingPointer<Renderbuffer> mStencilbufferPointer;
BindingPointer<Renderbuffer> mStencilbufferPointer;
private:
Renderbuffer *lookupRenderbuffer(GLenum type, GLuint handle) const;
......
......@@ -16,7 +16,11 @@
#include "../common/debug.h"
#include "Common/Thread.hpp"
#include <GLES2/gl2ext.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......@@ -31,15 +35,16 @@ namespace gl
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: parentTexture(parentTexture)
, egl::Image(getParentResource(parentTexture), width, height, 1, format, type, selectInternalFormat(format, type))
: parentTexture(parentTexture), width(width), height(height), format(format), type(type)
, internalFormat(selectInternalFormat(format, type)), multiSampleDepth(1)
, sw::Surface(getParentResource(parentTexture), width, height, 1, selectInternalFormat(format, type), true, true)
{
referenceCount = 1;
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
: parentTexture(parentTexture)
, egl::Image(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget)
: parentTexture(parentTexture), width(width), height(height), internalFormat(internalFormat), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), multiSampleDepth(multiSampleDepth)
, sw::Surface(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget)
{
referenceCount = 1;
}
......@@ -49,6 +54,51 @@ namespace gl
ASSERT(referenceCount == 0);
}
void *Image::lock(unsigned int left, unsigned int top, sw::Lock lock)
{
return lockExternal(left, top, 0, lock, sw::PUBLIC);
}
unsigned int Image::getPitch() const
{
return getExternalPitchB();
}
void Image::unlock()
{
unlockExternal();
}
int Image::getWidth()
{
return width;
}
int Image::getHeight()
{
return height;
}
GLenum Image::getFormat()
{
return format;
}
GLenum Image::getType()
{
return type;
}
sw::Format Image::getInternalFormat()
{
return internalFormat;
}
int Image::getMultiSampleDepth()
{
return multiSampleDepth;
}
void Image::addRef()
{
if(parentTexture)
......@@ -73,39 +123,35 @@ namespace gl
if(referenceCount == 0)
{
ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called
delete this;
}
}
void Image::unbind(const egl::Texture *parent)
void Image::unbind()
{
if(parentTexture == parent)
{
parentTexture = 0;
}
parentTexture = 0;
release();
}
sw::Format Image::selectInternalFormat(GLenum format, GLenum type)
{
if(format == GL_ETC1_RGB8_OES)
{
return sw::FORMAT_ETC1;
}
else
if(type == GL_NONE && format == GL_NONE)
{
return sw::FORMAT_NULL;
}
else
#if S3TC_SUPPORT
if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
{
return sw::FORMAT_DXT1;
}
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE)
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT)
{
return sw::FORMAT_DXT3;
}
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE)
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
{
return sw::FORMAT_DXT5;
}
......@@ -115,7 +161,7 @@ namespace gl
{
return sw::FORMAT_A32B32G32R32F;
}
else if(type == GL_HALF_FLOAT_OES)
else if(type == GL_HALF_FLOAT)
{
return sw::FORMAT_A16B16G16R16F;
}
......@@ -151,9 +197,9 @@ namespace gl
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_INT_24_8_OES)
else if(type == GL_UNSIGNED_INT_24_8_EXT)
{
if(format == GL_DEPTH_STENCIL_OES)
if(format == GL_DEPTH_STENCIL_EXT)
{
return sw::FORMAT_D32FS8_TEXTURE;
}
......@@ -171,6 +217,11 @@ namespace gl
{
return sw::FORMAT_X8R8G8B8;
}
else if(type == GL_UNSIGNED_INT_8_8_8_8_REV)
{
return sw::FORMAT_A8R8G8B8;
}
else UNREACHABLE();
return sw::FORMAT_A8R8G8B8;
......@@ -186,6 +237,7 @@ namespace gl
switch(type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_INT_8_8_8_8_REV:
switch(format)
{
case GL_ALPHA:
......@@ -258,7 +310,7 @@ namespace gl
default: UNREACHABLE();
}
break;
case GL_HALF_FLOAT_OES:
case GL_HALF_FLOAT:
switch(format)
{
// float textures are converted to RGBA, not BGRA
......@@ -286,7 +338,7 @@ namespace gl
case GL_UNSIGNED_INT:
loadD32ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
break;
case GL_UNSIGNED_INT_24_8_OES:
case GL_UNSIGNED_INT_24_8_EXT:
loadD24S8ImageData(xoffset, yoffset, width, height, inputPitch, input, buffer);
break;
default: UNREACHABLE();
......
......@@ -13,16 +13,18 @@
#define gl_Image_hpp
#include "Renderer/Surface.hpp"
#include "libEGL/Image.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
class Texture;
class Image : public egl::Image
class Image : public sw::Surface
{
public:
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
......@@ -31,9 +33,20 @@ namespace gl
void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
void *lock(unsigned int left, unsigned int top, sw::Lock lock);
unsigned int getPitch() const;
void unlock();
int getWidth();
int getHeight();
GLenum getFormat();
GLenum getType();
virtual sw::Format getInternalFormat();
int getMultiSampleDepth();
virtual void addRef();
virtual void release();
virtual void unbind(const egl::Texture *parent); // Break parent ownership and release
void unbind(); // Break parent ownership and release
static sw::Format selectInternalFormat(GLenum format, GLenum type);
......@@ -63,7 +76,14 @@ namespace gl
void loadD32ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer);
egl::Texture *parentTexture;
Texture *parentTexture;
const GLsizei width;
const GLsizei height;
const GLenum format;
const GLenum type;
const sw::Format internalFormat;
const int multiSampleDepth;
volatile int referenceCount;
};
......
......@@ -17,8 +17,11 @@
#include "Context.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......
#include "MatrixStack.hpp"
#include "Common/Math.hpp"
namespace sw
{
MatrixStack::MatrixStack(int size)
{
stack = new Matrix[size];
stack[0] = 1;
top = 0;
this->size = size;
}
MatrixStack::~MatrixStack()
{
delete[] stack;
stack = 0;
}
void MatrixStack::identity()
{
stack[top] = 1;
}
void MatrixStack::load(const float *M)
{
stack[top] = Matrix(M[0], M[4], M[8], M[12],
M[1], M[5], M[9], M[13],
M[2], M[6], M[10], M[14],
M[3], M[7], M[11], M[15]);
}
void MatrixStack::load(const double *M)
{
stack[top] = Matrix((float)M[0], (float)M[4], (float)M[8], (float)M[12],
(float)M[1], (float)M[5], (float)M[9], (float)M[13],
(float)M[2], (float)M[6], (float)M[10], (float)M[14],
(float)M[3], (float)M[7], (float)M[11], (float)M[15]);
}
void MatrixStack::translate(float x, float y, float z)
{
stack[top] *= Matrix::translate(x, y, z);
}
void MatrixStack::translate(double x, double y, double z)
{
translate((float)x, (float)y, (float)z);
}
void MatrixStack::rotate(float angle, float x, float y, float z)
{
float n = 1.0f / sqrt(x*x + y*y + z*z);
x *= n;
y *= n;
z *= n;
float theta = angle * 0.0174532925f; // In radians
float c = cos(theta);
float _c = 1 - c;
float s = sin(theta);
// Rodrigues' rotation formula
sw::Matrix rotate(c+x*x*_c, x*y*_c-z*s, x*z*_c+y*s,
x*y*_c+z*s, c+y*y*_c, y*z*_c-x*s,
x*z*_c-y*s, y*z*_c+x*s, c+z*z*_c);
stack[top] *= rotate;
}
void MatrixStack::rotate(double angle, double x, double y, double z)
{
rotate((float)angle, (float)x, (float)y, (float)z);
}
void MatrixStack::scale(float x, float y, float z)
{
stack[top] *= Matrix::scale(x, y, z);
}
void MatrixStack::scale(double x, double y, double z)
{
scale((float)x, (float)y, (float)z);
}
void MatrixStack::multiply(const float *M)
{
stack[top] *= Matrix(M[0], M[4], M[8], M[12],
M[1], M[5], M[9], M[13],
M[2], M[6], M[10], M[14],
M[3], M[7], M[11], M[15]);
}
void MatrixStack::multiply(const double *M)
{
stack[top] *= Matrix((float)M[0], (float)M[4], (float)M[8], (float)M[12],
(float)M[1], (float)M[5], (float)M[9], (float)M[13],
(float)M[2], (float)M[6], (float)M[10], (float)M[14],
(float)M[3], (float)M[7], (float)M[11], (float)M[15]);
}
void MatrixStack::frustum(float left, float right, float bottom, float top, float zNear, float zFar)
{
float l = (float)left;
float r = (float)right;
float b = (float)bottom;
float t = (float)top;
float n = (float)zNear;
float f = (float)zFar;
float A = (r + l) / (r - l);
float B = (t + b) / (t - b);
float C = -(f + n) / (r - n);
float D = -2 * r * n / (f - n);
Matrix frustum(2 * n / (r - l), 0, A, 0,
0, 2 * n / (t - b), B, 0,
0, 0, C, D,
0, 0, -1, 0);
stack[this->top] *= frustum;
}
void MatrixStack::ortho(double left, double right, double bottom, double top, double zNear, double zFar)
{
float l = (float)left;
float r = (float)right;
float b = (float)bottom;
float t = (float)top;
float n = (float)zNear;
float f = (float)zFar;
float tx = -(r + l) / (r - l);
float ty = -(t + b) / (t - b);
float tz = -(f + n) / (f - n);
Matrix ortho(2 / (r - l), 0, 0, tx,
0, 2 / (t - b), 0, ty,
0, 0, -2 / (f - n), tz,
0, 0, 0, 1);
stack[this->top] *= ortho;
}
bool MatrixStack::push()
{
if(top >= size - 1) return false;
stack[top + 1] = stack[top];
top++;
return true;
}
bool MatrixStack::pop()
{
if(top <= 0) return false;
top--;
return true;
}
const Matrix &MatrixStack::current()
{
return stack[top];
}
bool MatrixStack::isIdentity() const
{
const Matrix &m = stack[top];
if(m.m[0][0] != 1.0f) return false;
if(m.m[0][1] != 0.0f) return false;
if(m.m[0][2] != 0.0f) return false;
if(m.m[0][3] != 0.0f) return false;
if(m.m[1][0] != 0.0f) return false;
if(m.m[1][1] != 1.0f) return false;
if(m.m[1][2] != 0.0f) return false;
if(m.m[1][3] != 0.0f) return false;
if(m.m[2][0] != 0.0f) return false;
if(m.m[2][1] != 0.0f) return false;
if(m.m[2][2] != 1.0f) return false;
if(m.m[2][3] != 0.0f) return false;
if(m.m[3][0] != 0.0f) return false;
if(m.m[3][1] != 0.0f) return false;
if(m.m[3][2] != 0.0f) return false;
if(m.m[3][3] != 1.0f) return false;
return true;
}
}
#ifndef OpenGL32_MatrixStack_hpp
#define OpenGL32_MatrixStack_hpp
#include "Renderer/Matrix.hpp"
namespace sw
{
class MatrixStack
{
public:
MatrixStack(int size = 2);
~MatrixStack();
void identity();
void load(const float *M);
void load(const double *M);
void translate(float x, float y, float z);
void translate(double x, double y, double z);
void rotate(float angle, float x, float y, float z);
void rotate(double angle, double x, double y, double z);
void scale(float x, float y, float z);
void scale(double x, double y, double z);
void multiply(const float *M);
void multiply(const double *M);
void frustum(float left, float right, float bottom, float top, float zNear, float zFar);
void ortho(double left, double right, double bottom, double top, double zNear, double zFar);
bool push(); // False on overflow
bool pop(); // False on underflow
const Matrix &current();
bool isIdentity() const;
private:
int top;
int size;
Matrix *stack;
};
}
#endif // OpenGL32_MatrixStack_hpp
......@@ -10,7 +10,7 @@
//
// Program.cpp: Implements the Program class. Implements GL program objects
// and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28.
// and related functionality.
#include "Program.h"
......@@ -590,9 +590,7 @@ namespace gl
if(targetUniform->type == GL_INT ||
targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES ||
targetUniform->type == GL_SAMPLER_3D_OES)
targetUniform->type == GL_SAMPLER_CUBE)
{
memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLint),
v, sizeof(GLint) * count);
......@@ -925,8 +923,6 @@ namespace gl
case GL_FLOAT_MAT4: applyUniformMatrix4fv(location, size, f); break;
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_3D_OES:
case GL_INT: applyUniform1iv(location, size, i); break;
case GL_INT_VEC2: applyUniform2iv(location, size, i); break;
case GL_INT_VEC3: applyUniform3iv(location, size, i); break;
......@@ -940,7 +936,7 @@ namespace gl
}
}
// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
// Packs varyings into generic varying registers.
// Returns the number of used varying registers, or -1 if unsuccesful
int Program::packVaryings(const glsl::Varying *packing[][4])
{
......@@ -1317,7 +1313,7 @@ namespace gl
bool Program::defineUniform(GLenum shader, GLenum type, GLenum precision, const std::string &name, unsigned int arraySize, int registerIndex)
{
if(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_3D_OES)
if(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE)
{
int index = registerIndex;
......@@ -1738,9 +1734,7 @@ namespace gl
if(targetUniform->psRegisterIndex != -1)
{
if(targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES ||
targetUniform->type == GL_SAMPLER_3D_OES)
targetUniform->type == GL_SAMPLER_CUBE)
{
for(int i = 0; i < count; i++)
{
......@@ -1762,9 +1756,7 @@ namespace gl
if(targetUniform->vsRegisterIndex != -1)
{
if(targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES ||
targetUniform->type == GL_SAMPLER_3D_OES)
targetUniform->type == GL_SAMPLER_CUBE)
{
for(int i = 0; i < count; i++)
{
......
......@@ -10,7 +10,7 @@
//
// Program.h: Defines the Program class. Implements GL program objects
// and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28.
// and related functionality.
#ifndef LIBGL_PROGRAM_H_
#define LIBGL_PROGRAM_H_
......
......@@ -110,8 +110,8 @@ GLboolean Query::testQuery()
switch(mType)
{
case GL_ANY_SAMPLES_PASSED_EXT:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
case GL_ANY_SAMPLES_PASSED:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE;
break;
default:
......
......@@ -17,8 +17,11 @@
#include "common/Object.hpp"
#include "Renderer/Renderer.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......
......@@ -11,7 +11,7 @@
// Renderbuffer.cpp: the Renderbuffer class and its derived classes
// Colorbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
// objects and related functionality.
#include "Renderbuffer.h"
......@@ -90,25 +90,13 @@ void RenderbufferTexture2D::releaseProxy(const Renderbuffer *proxy)
mTexture2D->releaseProxy(proxy);
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *RenderbufferTexture2D::getRenderTarget()
// Increments refcount on surface.
// caller must release() the returned surface
Image *RenderbufferTexture2D::getRenderTarget()
{
return mTexture2D->getRenderTarget(GL_TEXTURE_2D, 0);
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *RenderbufferTexture2D::createSharedImage()
{
return mTexture2D->createSharedImage(GL_TEXTURE_2D, 0);
}
bool RenderbufferTexture2D::isShared() const
{
return mTexture2D->isShared(GL_TEXTURE_2D, 0);
}
GLsizei RenderbufferTexture2D::getWidth() const
{
return mTexture2D->getWidth(GL_TEXTURE_2D, 0);
......@@ -158,25 +146,13 @@ void RenderbufferTextureCubeMap::releaseProxy(const Renderbuffer *proxy)
mTextureCubeMap->releaseProxy(proxy);
}
// Increments refcount on image.
// caller must release() the returned image
// Increments refcount on surface.
// caller must release() the returned surface
Image *RenderbufferTextureCubeMap::getRenderTarget()
{
return mTextureCubeMap->getRenderTarget(mTarget, 0);
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *RenderbufferTextureCubeMap::createSharedImage()
{
return mTextureCubeMap->createSharedImage(mTarget, 0);
}
bool RenderbufferTextureCubeMap::isShared() const
{
return mTextureCubeMap->isShared(mTarget, 0);
}
GLsizei RenderbufferTextureCubeMap::getWidth() const
{
return mTextureCubeMap->getWidth(mTarget, 0);
......@@ -231,25 +207,13 @@ void Renderbuffer::release()
Object::release();
}
// Increments refcount on image.
// caller must Release() the returned image
egl::Image *Renderbuffer::getRenderTarget()
// Increments refcount on surface.
// caller must Release() the returned surface
Image *Renderbuffer::getRenderTarget()
{
return mInstance->getRenderTarget();
}
// Increments refcount on image.
// caller must Release() the returned image
egl::Image *Renderbuffer::createSharedImage()
{
return mInstance->createSharedImage();
}
bool Renderbuffer::isShared() const
{
return mInstance->isShared();
}
GLsizei Renderbuffer::getWidth() const
{
return mInstance->getWidth();
......@@ -326,6 +290,13 @@ RenderbufferStorage::~RenderbufferStorage()
{
}
// Increments refcount on surface.
// caller must Release() the returned surface
Image *RenderbufferStorage::getRenderTarget()
{
return NULL;
}
GLsizei RenderbufferStorage::getWidth() const
{
return mWidth;
......@@ -351,7 +322,7 @@ GLsizei RenderbufferStorage::getSamples() const
return mSamples;
}
Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget)
Colorbuffer::Colorbuffer(Image *renderTarget) : mRenderTarget(renderTarget)
{
if(renderTarget)
{
......@@ -361,7 +332,7 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget)
mHeight = renderTarget->getHeight();
internalFormat = renderTarget->getInternalFormat();
format = sw2es::ConvertBackBufferFormat(internalFormat);
mSamples = renderTarget->getDepth() & ~1;
mSamples = renderTarget->getMultiSampleDepth() & ~1;
}
}
......@@ -398,9 +369,9 @@ Colorbuffer::~Colorbuffer()
}
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *Colorbuffer::getRenderTarget()
// Increments refcount on surface.
// caller must release() the returned surface
Image *Colorbuffer::getRenderTarget()
{
if(mRenderTarget)
{
......@@ -410,25 +381,7 @@ egl::Image *Colorbuffer::getRenderTarget()
return mRenderTarget;
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *Colorbuffer::createSharedImage()
{
if(mRenderTarget)
{
mRenderTarget->addRef();
mRenderTarget->markShared();
}
return mRenderTarget;
}
bool Colorbuffer::isShared() const
{
return mRenderTarget->isShared();
}
DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil(depthStencil)
DepthStencilbuffer::DepthStencilbuffer(Image *depthStencil) : mDepthStencil(depthStencil)
{
if(depthStencil)
{
......@@ -438,7 +391,7 @@ DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil
mHeight = depthStencil->getHeight();
internalFormat = depthStencil->getInternalFormat();
format = sw2es::ConvertDepthStencilFormat(internalFormat);
mSamples = depthStencil->getDepth() & ~1;
mSamples = depthStencil->getMultiSampleDepth() & ~1;
}
}
......@@ -463,7 +416,7 @@ DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples)
mWidth = width;
mHeight = height;
format = GL_DEPTH24_STENCIL8_OES;
format = GL_DEPTH24_STENCIL8_EXT;
internalFormat = sw::FORMAT_D24S8;
mSamples = supportedSamples & ~1;
}
......@@ -476,9 +429,9 @@ DepthStencilbuffer::~DepthStencilbuffer()
}
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *DepthStencilbuffer::getRenderTarget()
// Increments refcount on surface.
// caller must release() the returned surface
Image *DepthStencilbuffer::getRenderTarget()
{
if(mDepthStencil)
{
......@@ -488,25 +441,7 @@ egl::Image *DepthStencilbuffer::getRenderTarget()
return mDepthStencil;
}
// Increments refcount on image.
// caller must release() the returned image
egl::Image *DepthStencilbuffer::createSharedImage()
{
if(mDepthStencil)
{
mDepthStencil->addRef();
mDepthStencil->markShared();
}
return mDepthStencil;
}
bool DepthStencilbuffer::isShared() const
{
return mDepthStencil->isShared();
}
Depthbuffer::Depthbuffer(egl::Image *depthStencil) : DepthStencilbuffer(depthStencil)
Depthbuffer::Depthbuffer(Image *depthStencil) : DepthStencilbuffer(depthStencil)
{
if(depthStencil)
{
......@@ -530,7 +465,7 @@ Depthbuffer::~Depthbuffer()
{
}
Stencilbuffer::Stencilbuffer(egl::Image *depthStencil) : DepthStencilbuffer(depthStencil)
Stencilbuffer::Stencilbuffer(Image *depthStencil) : DepthStencilbuffer(depthStencil)
{
if(depthStencil)
{
......
......@@ -12,7 +12,7 @@
// Renderbuffer.h: Defines the wrapper class Renderbuffer, as well as the
// class hierarchy used to store its contents: RenderbufferStorage, Colorbuffer,
// DepthStencilbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
// objects and related functionality.
#ifndef LIBGL_RENDERBUFFER_H_
#define LIBGL_RENDERBUFFER_H_
......@@ -20,8 +20,11 @@
#include "common/Object.hpp"
#include "Image.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......@@ -41,9 +44,7 @@ public:
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
virtual egl::Image *getRenderTarget() = 0;
virtual egl::Image *createSharedImage() = 0;
virtual bool isShared() const = 0;
virtual Image *getRenderTarget() = 0;
virtual GLsizei getWidth() const = 0;
virtual GLsizei getHeight() const = 0;
......@@ -69,9 +70,7 @@ public:
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
virtual egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
Image *getRenderTarget();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
......@@ -80,7 +79,7 @@ public:
virtual GLsizei getSamples() const;
private:
gl::BindingPointer<Texture2D> mTexture2D;
BindingPointer<Texture2D> mTexture2D;
};
class RenderbufferTextureCubeMap : public RenderbufferInterface
......@@ -93,9 +92,7 @@ public:
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
virtual Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
Image *getRenderTarget();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
......@@ -104,7 +101,7 @@ public:
virtual GLsizei getSamples() const;
private:
gl::BindingPointer<TextureCubeMap> mTextureCubeMap;
BindingPointer<TextureCubeMap> mTextureCubeMap;
GLenum mTarget;
};
......@@ -118,9 +115,7 @@ public:
virtual ~RenderbufferStorage() = 0;
virtual egl::Image *getRenderTarget() = 0;
virtual egl::Image *createSharedImage() = 0;
virtual bool isShared() const = 0;
virtual Image *getRenderTarget();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
......@@ -153,9 +148,7 @@ public:
virtual void addRef();
virtual void release();
egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
Image *getRenderTarget();
GLsizei getWidth() const;
GLsizei getHeight() const;
......@@ -178,39 +171,35 @@ private:
class Colorbuffer : public RenderbufferStorage
{
public:
explicit Colorbuffer(egl::Image *renderTarget);
explicit Colorbuffer(Image *renderTarget);
Colorbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
virtual ~Colorbuffer();
virtual egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
virtual Image *getRenderTarget();
private:
egl::Image *mRenderTarget;
Image *mRenderTarget;
};
class DepthStencilbuffer : public RenderbufferStorage
{
public:
explicit DepthStencilbuffer(egl::Image *depthStencil);
explicit DepthStencilbuffer(Image *depthStencil);
DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
~DepthStencilbuffer();
virtual egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
virtual Image *getRenderTarget();
protected:
egl::Image *mDepthStencil;
Image *mDepthStencil;
};
class Depthbuffer : public DepthStencilbuffer
{
public:
explicit Depthbuffer(egl::Image *depthStencil);
explicit Depthbuffer(Image *depthStencil);
Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
virtual ~Depthbuffer();
......@@ -219,7 +208,7 @@ public:
class Stencilbuffer : public DepthStencilbuffer
{
public:
explicit Stencilbuffer(egl::Image *depthStencil);
explicit Stencilbuffer(Image *depthStencil);
Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
virtual ~Stencilbuffer();
......
......@@ -71,7 +71,13 @@ void ResourceManager::release()
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
GLuint handle = mBufferNameSpace.allocate();
//GLuint handle = mBufferNameSpace.allocate();
unsigned int handle = 1;
while (mBufferMap.find(handle) != mBufferMap.end())
{
handle++;
}
mBufferMap[handle] = NULL;
......@@ -81,7 +87,13 @@ GLuint ResourceManager::createBuffer()
// Returns an unused shader/program name
GLuint ResourceManager::createShader(GLenum type)
{
GLuint handle = mProgramShaderNameSpace.allocate();
//GLuint handle = mProgramShaderNameSpace.allocate();
unsigned int handle = 1;
while (mShaderMap.find(handle) != mShaderMap.end())
{
handle++;
}
if(type == GL_VERTEX_SHADER)
{
......@@ -99,7 +111,13 @@ GLuint ResourceManager::createShader(GLenum type)
// Returns an unused program/shader name
GLuint ResourceManager::createProgram()
{
GLuint handle = mProgramShaderNameSpace.allocate();
//GLuint handle = mProgramShaderNameSpace.allocate();
unsigned int handle = 1;
while (mProgramMap.find(handle) != mProgramMap.end())
{
handle++;
}
mProgramMap[handle] = new Program(this, handle);
......@@ -109,7 +127,13 @@ GLuint ResourceManager::createProgram()
// Returns an unused texture name
GLuint ResourceManager::createTexture()
{
GLuint handle = mTextureNameSpace.allocate();
//GLuint handle = mTextureNameSpace.allocate();
unsigned int handle = 1;
while (mTextureMap.find(handle) != mTextureMap.end())
{
handle++;
}
mTextureMap[handle] = NULL;
......@@ -119,7 +143,13 @@ GLuint ResourceManager::createTexture()
// Returns an unused renderbuffer name
GLuint ResourceManager::createRenderbuffer()
{
GLuint handle = mRenderbufferNameSpace.allocate();
//GLuint handle = mRenderbufferNameSpace.allocate();
unsigned int handle = 1;
while (mRenderbufferMap.find(handle) != mRenderbufferMap.end())
{
handle++;
}
mRenderbufferMap[handle] = NULL;
......@@ -132,7 +162,7 @@ void ResourceManager::deleteBuffer(GLuint buffer)
if(bufferObject != mBufferMap.end())
{
mBufferNameSpace.release(bufferObject->first);
//mBufferNameSpace.release(bufferObject->first);
if(bufferObject->second) bufferObject->second->release();
mBufferMap.erase(bufferObject);
}
......@@ -146,7 +176,7 @@ void ResourceManager::deleteShader(GLuint shader)
{
if(shaderObject->second->getRefCount() == 0)
{
mProgramShaderNameSpace.release(shaderObject->first);
//mProgramShaderNameSpace.release(shaderObject->first);
delete shaderObject->second;
mShaderMap.erase(shaderObject);
}
......@@ -165,7 +195,7 @@ void ResourceManager::deleteProgram(GLuint program)
{
if(programObject->second->getRefCount() == 0)
{
mProgramShaderNameSpace.release(programObject->first);
//mProgramShaderNameSpace.release(programObject->first);
delete programObject->second;
mProgramMap.erase(programObject);
}
......@@ -182,7 +212,7 @@ void ResourceManager::deleteTexture(GLuint texture)
if(textureObject != mTextureMap.end())
{
mTextureNameSpace.release(textureObject->first);
//mTextureNameSpace.release(textureObject->first);
if(textureObject->second) textureObject->second->release();
mTextureMap.erase(textureObject);
}
......@@ -194,7 +224,7 @@ void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
if(renderbufferObject != mRenderbufferMap.end())
{
mRenderbufferNameSpace.release(renderbufferObject->first);
//mRenderbufferNameSpace.release(renderbufferObject->first);
if(renderbufferObject->second) renderbufferObject->second->release();
mRenderbufferMap.erase(renderbufferObject);
}
......@@ -268,12 +298,6 @@ Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
}
else
{
if (!renderbuffer->second)
{
Renderbuffer *renderbufferObject = new Renderbuffer(handle, new Colorbuffer(0, 0, GL_RGBA4_OES, 0));
mRenderbufferMap[handle] = renderbufferObject;
renderbufferObject->addRef();
}
return renderbuffer->second;
}
}
......@@ -307,10 +331,6 @@ void ResourceManager::checkTextureAllocation(GLuint texture, TextureType type)
{
textureObject = new TextureCubeMap(texture);
}
else if(type == TEXTURE_EXTERNAL)
{
textureObject = new TextureExternal(texture);
}
else
{
UNREACHABLE();
......@@ -322,4 +342,14 @@ void ResourceManager::checkTextureAllocation(GLuint texture, TextureType type)
}
}
void ResourceManager::checkRenderbufferAllocation(GLuint renderbuffer)
{
if(renderbuffer != 0 && !getRenderbuffer(renderbuffer))
{
Renderbuffer *renderbufferObject = new Renderbuffer(renderbuffer, new Colorbuffer(0, 0, GL_RGBA4, 0));
mRenderbufferMap[renderbuffer] = renderbufferObject;
renderbufferObject->addRef();
}
}
}
......@@ -17,8 +17,11 @@
#include "common/NameSpace.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
#include <map>
......@@ -33,8 +36,8 @@ class Renderbuffer;
enum TextureType
{
TEXTURE_2D,
PROXY_TEXTURE_2D,
TEXTURE_CUBE,
TEXTURE_EXTERNAL,
TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN
......@@ -71,28 +74,29 @@ class ResourceManager
void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type);
void checkRenderbufferAllocation(GLuint renderbuffer);
private:
std::size_t mRefCount;
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
NameSpace mBufferNameSpace;
//NameSpace mBufferNameSpace;
typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap;
NameSpace mProgramShaderNameSpace;
//NameSpace mProgramShaderNameSpace;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
NameSpace mTextureNameSpace;
//NameSpace mTextureNameSpace;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
NameSpace mRenderbufferNameSpace;
//NameSpace mRenderbufferNameSpace;
};
}
......
......@@ -11,7 +11,7 @@
// Shader.cpp: Implements the Shader class and its derived classes
// VertexShader and FragmentShader. Implements GL shader objects and related
// functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section 3.8 page 84.
// functionality.
#include "Shader.h"
......
......@@ -11,8 +11,8 @@
// Shader.h: Defines the abstract Shader class and its concrete derived
// classes VertexShader and FragmentShader. Implements GL shader objects and
// related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section
// 3.8 page 84.
// related functionality.
#ifndef LIBGL_SHADER_H_
#define LIBGL_SHADER_H_
......@@ -21,8 +21,11 @@
#include "compiler/TranslatorASM.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
#include <list>
#include <vector>
......
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2013 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// Surface.cpp: Implements the Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers.
#include "Surface.h"
#include "main.h"
#include "Display.h"
#include "Image.hpp"
#include "Context.h"
#include "common/debug.h"
#include "Main/FrameBuffer.hpp"
#if defined(_WIN32)
#include <tchar.h>
#endif
#include <algorithm>
namespace gl
{
Surface::Surface(Display *display, NativeWindowType window)
: mDisplay(display), mWindow(window)
{
frameBuffer = 0;
backBuffer = 0;
mDepthStencil = NULL;
mTextureFormat = GL_NONE;
mTextureTarget = GL_NONE;
mSwapInterval = -1;
setSwapInterval(1);
}
Surface::Surface(Display *display, GLint width, GLint height, GLenum textureFormat, GLenum textureType)
: mDisplay(display), mWindow(NULL), mWidth(width), mHeight(height)
{
frameBuffer = 0;
backBuffer = 0;
mDepthStencil = NULL;
mWindowSubclassed = false;
mTextureFormat = textureFormat;
mTextureTarget = textureType;
mSwapInterval = -1;
setSwapInterval(1);
}
Surface::~Surface()
{
release();
}
bool Surface::initialize()
{
ASSERT(!frameBuffer && !backBuffer && !mDepthStencil);
return reset();
}
void Surface::release()
{
if(mDepthStencil)
{
mDepthStencil->release();
mDepthStencil = NULL;
}
if(backBuffer)
{
backBuffer->release();
backBuffer = 0;
}
delete frameBuffer;
frameBuffer = 0;
}
bool Surface::reset()
{
if(!mWindow)
{
return reset(mWidth, mHeight);
}
// FIXME: Wrap into an abstract Window class
#if defined(_WIN32)
RECT windowRect;
GetClientRect(mWindow, &windowRect);
return reset(windowRect.right - windowRect.left, windowRect.bottom - windowRect.top);
#else
XWindowAttributes windowAttributes;
XGetWindowAttributes(mDisplay->getNativeDisplay(), mWindow, &windowAttributes);
return reset(windowAttributes.width, windowAttributes.height);
#endif
}
bool Surface::reset(int backBufferWidth, int backBufferHeight)
{
release();
if(mWindow)
{
frameBuffer = ::createFrameBuffer(mDisplay->getNativeDisplay(), mWindow, backBufferWidth, backBufferHeight);
if(!frameBuffer)
{
ERR("Could not create frame buffer");
release();
return error(GL_OUT_OF_MEMORY, false);
}
}
backBuffer = new Image(0, backBufferWidth, backBufferHeight, GL_RGB, GL_UNSIGNED_BYTE);
if(!backBuffer)
{
ERR("Could not create back buffer");
release();
return error(GL_OUT_OF_MEMORY, false);
}
if(true) // Always provide a depth/stencil buffer
{
mDepthStencil = new Image(0, backBufferWidth, backBufferHeight, sw::FORMAT_D24S8, 1, false, true);
if(!mDepthStencil)
{
ERR("Could not create depth/stencil buffer for surface");
release();
return error(GL_OUT_OF_MEMORY, false);
}
}
mWidth = backBufferWidth;
mHeight = backBufferHeight;
return true;
}
void Surface::swap()
{
#if PERF_PROFILE
profiler.nextFrame();
#endif
if(backBuffer)
{
void *source = backBuffer->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
frameBuffer->flip(source, backBuffer->getInternalFormat());
backBuffer->unlockInternal();
checkForResize();
}
}
Image *Surface::getRenderTarget()
{
if(backBuffer)
{
backBuffer->addRef();
}
return backBuffer;
}
Image *Surface::getDepthStencil()
{
if(mDepthStencil)
{
mDepthStencil->addRef();
}
return mDepthStencil;
}
void Surface::setSwapInterval(GLint interval)
{
if(mSwapInterval == interval)
{
return;
}
mSwapInterval = interval;
mSwapInterval = std::max(mSwapInterval, mDisplay->getMinSwapInterval());
mSwapInterval = std::min(mSwapInterval, mDisplay->getMaxSwapInterval());
}
GLint Surface::getWidth() const
{
return mWidth;
}
GLint Surface::getHeight() const
{
return mHeight;
}
GLenum Surface::getTextureFormat() const
{
return mTextureFormat;
}
GLenum Surface::getTextureTarget() const
{
return mTextureTarget;
}
bool Surface::checkForResize()
{
#if defined(_WIN32)
RECT client;
if(!GetClientRect(mWindow, &client))
{
ASSERT(false);
return false;
}
int clientWidth = client.right - client.left;
int clientHeight = client.bottom - client.top;
#else
XWindowAttributes windowAttributes;
XGetWindowAttributes(mDisplay->getNativeDisplay(), mWindow, &windowAttributes);
int clientWidth = windowAttributes.width;
int clientHeight = windowAttributes.height;
#endif
bool sizeDirty = clientWidth != getWidth() || clientHeight != getHeight();
if(sizeDirty)
{
reset(clientWidth, clientHeight);
if(getCurrentDrawSurface() == this)
{
getContext()->makeCurrent(this);
}
return true;
}
return false;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// Surface.h: Defines the Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers.
#ifndef INCLUDE_SURFACE_H_
#define INCLUDE_SURFACE_H_
#include "Main/FrameBuffer.hpp"
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
#if defined(_WIN32)
typedef HDC NativeDisplayType;
typedef HBITMAP NativePixmapType;
typedef HWND NativeWindowType;
#else
#error
#endif
namespace gl
{
class Image;
class Display;
class Surface
{
public:
Surface(Display *display, NativeWindowType window);
Surface(Display *display, GLint width, GLint height, GLenum textureFormat, GLenum textureTarget);
virtual ~Surface();
bool initialize();
void swap();
virtual Image *getRenderTarget();
virtual Image *getDepthStencil();
void setSwapInterval(GLint interval);
virtual GLint getWidth() const;
virtual GLint getHeight() const;
virtual GLenum getTextureFormat() const;
virtual GLenum getTextureTarget() const;
bool checkForResize(); // Returns true if surface changed due to resize
private:
void release();
bool reset();
Display *const mDisplay;
Image *mDepthStencil;
sw::FrameBuffer *frameBuffer;
Image *backBuffer;
bool reset(int backbufferWidth, int backbufferHeight);
const NativeWindowType mWindow; // Window that the surface is created for.
bool mWindowSubclassed; // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking
GLint mHeight; // Height of surface
GLint mWidth; // Width of surface
GLenum mTextureFormat; // Format of texture: RGB, RGBA, or no texture
GLenum mTextureTarget; // Type of texture: 2D or no texture
GLint mSwapInterval;
};
}
#endif // INCLUDE_SURFACE_H_
......@@ -11,7 +11,7 @@
// Texture.h: Defines the abstract Texture class and its concrete derived
// classes Texture2D and TextureCubeMap. Implements GL texture objects and
// related functionality. [OpenGL ES 2.0.24] section 3.7 page 63.
// related functionality.
#ifndef LIBGL_TEXTURE_H_
#define LIBGL_TEXTURE_H_
......@@ -19,22 +19,20 @@
#include "Renderbuffer.h"
#include "common/Object.hpp"
#include "utilities.h"
#include "libEGL/Texture.hpp"
#include "common/debug.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
#include <vector>
namespace egl
namespace gl
{
class Surface;
class Config;
}
namespace gl
{
class Framebuffer;
enum
......@@ -46,7 +44,7 @@ enum
IMPLEMENTATION_MAX_SAMPLES = 4
};
class Texture : public egl::Texture
class Texture : public Object
{
public:
explicit Texture(GLuint name);
......@@ -65,6 +63,7 @@ public:
bool setWrapS(GLenum wrap);
bool setWrapT(GLenum wrap);
bool setMaxAnisotropy(GLfloat textureMaxAnisotropy);
bool setMaxLevel(int level);
GLenum getMinFilter() const;
GLenum getMagFilter() const;
......@@ -84,20 +83,18 @@ public:
virtual bool isDepth(GLenum target, GLint level) const = 0;
virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
virtual egl::Image *getRenderTarget(GLenum target, unsigned int level) = 0;
virtual egl::Image *createSharedImage(GLenum target, unsigned int level);
virtual bool isShared(GLenum target, unsigned int level) const = 0;
virtual Image *getRenderTarget(GLenum target, unsigned int level) = 0;
virtual void generateMipmaps() = 0;
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
protected:
void setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image);
void subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image);
void subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, egl::Image *image);
void setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *image);
void subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, Image *image);
void subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, Image *image);
bool copy(egl::Image *source, const sw::Rect &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, egl::Image *dest);
bool copy(Image *source, const sw::Rect &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, Image *dest);
bool isMipmapFiltered() const;
......@@ -106,6 +103,7 @@ protected:
GLenum mWrapS;
GLenum mWrapT;
GLfloat mMaxAnisotropy;
GLint mMaxLevel;
sw::Resource *resource;
};
......@@ -136,28 +134,23 @@ public:
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void setImage(egl::Image *image);
void setImage(Image *image);
virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const;
virtual bool isDepth(GLenum target, GLint level) const;
virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage();
virtual void generateMipmaps();
virtual Renderbuffer *getRenderbuffer(GLenum target);
virtual egl::Image *getRenderTarget(GLenum target, unsigned int level);
virtual bool isShared(GLenum target, unsigned int level) const;
virtual Image *getRenderTarget(GLenum target, unsigned int level);
egl::Image *getImage(unsigned int level);
Image *getImage(unsigned int level);
protected:
bool isMipmapComplete() const;
egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
egl::Surface *mSurface;
Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
// A specific internal reference count is kept for colorbuffer proxy references,
// because, as the renderbuffer acting as proxy will maintain a binding pointer
......@@ -198,13 +191,11 @@ public:
virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const;
virtual bool isDepth(GLenum target, GLint level) const;
virtual void releaseTexImage();
virtual void generateMipmaps();
virtual Renderbuffer *getRenderbuffer(GLenum target);
virtual Image *getRenderTarget(GLenum target, unsigned int level);
virtual bool isShared(GLenum target, unsigned int level) const;
Image *getImage(int face, unsigned int level);
......@@ -226,15 +217,6 @@ private:
unsigned int mFaceProxyRefs[6];
};
class TextureExternal : public Texture2D
{
public:
explicit TextureExternal(GLuint name);
virtual ~TextureExternal();
virtual GLenum getTarget() const;
};
}
#endif // LIBGL_TEXTURE_H_
......@@ -121,11 +121,14 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
// Determine the required storage size per used buffer
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
if(program->getAttributeStream(i) != -1 && attribs[i].mArrayEnabled)
if(!program || program->getAttributeStream(i) != -1)
{
if(!attribs[i].mBoundBuffer)
if(attribs[i].mArrayEnabled)
{
mStreamingBuffer->addRequiredSpace(attribs[i].typeSize() * count);
if(!attribs[i].mBoundBuffer)
{
mStreamingBuffer->addRequiredSpace(attribs[i].typeSize() * count);
}
}
}
}
......@@ -135,7 +138,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
// Perform the vertex data translations
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
if(program->getAttributeStream(i) != -1)
if(!program || program->getAttributeStream(i) != -1)
{
if(attribs[i].mArrayEnabled)
{
......
......@@ -18,8 +18,11 @@
#include "Context.h"
#include "Device.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -14,13 +14,11 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
......@@ -70,7 +68,11 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "SwiftShader OpenGL Dynamic Link Library"
#ifdef WIN64
VALUE "FileDescription", "SwiftShader OpenGL 64-bit Dynamic Link Library"
#else
VALUE "FileDescription", "SwiftShader OpenGL 32-bit Dynamic Link Library"
#endif
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "libGL"
VALUE "LegalCopyright", "Copyright (C) 2012 TransGaming Inc."
......@@ -86,7 +88,41 @@ BEGIN
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOGEX 0, 0, 129, 47
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Waiting for debugger"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,72,26,50,14
LTEXT "Attach a debugger or ESC to cancel",IDC_STATIC,7,7,115,8
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 40
END
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
......@@ -100,3 +136,4 @@ END
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
......@@ -324,17 +324,20 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
<ClCompile Include="Context.cpp" />
<ClCompile Include="..\common\debug.cpp" />
<ClCompile Include="Device.cpp" />
<ClCompile Include="Display.cpp" />
<ClCompile Include="Fence.cpp" />
<ClCompile Include="Framebuffer.cpp" />
<ClCompile Include="Image.cpp" />
<ClCompile Include="IndexDataManager.cpp" />
<ClCompile Include="libGL.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="MatrixStack.cpp" />
<ClCompile Include="Program.cpp" />
<ClCompile Include="Query.cpp" />
<ClCompile Include="Renderbuffer.cpp" />
<ClCompile Include="ResourceManager.cpp" />
<ClCompile Include="Shader.cpp" />
<ClCompile Include="Surface.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="utilities.cpp" />
<ClCompile Include="VertexDataManager.cpp" />
......@@ -343,24 +346,28 @@ copy "$(OutDir)opengl32.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platf
<ClInclude Include="..\common\debug.h" />
<ClInclude Include="..\common\NameSpace.hpp" />
<ClInclude Include="..\common\Object.hpp" />
<ClInclude Include="..\include\GLES2\gl2.h" />
<ClInclude Include="..\include\GLES2\gl2ext.h" />
<ClInclude Include="..\include\GLES2\gl2platform.h" />
<ClInclude Include="..\include\GL\glcorearb.h" />
<ClInclude Include="..\include\GL\glext.h" />
<ClInclude Include="..\include\GL\glxext.h" />
<ClInclude Include="..\include\GL\wglext.h" />
<ClInclude Include="Buffer.h" />
<ClInclude Include="Context.h" />
<ClInclude Include="Device.hpp" />
<ClInclude Include="Display.h" />
<ClInclude Include="Fence.h" />
<ClInclude Include="Framebuffer.h" />
<ClInclude Include="Image.hpp" />
<ClInclude Include="IndexDataManager.h" />
<ClInclude Include="main.h" />
<ClInclude Include="mathutil.h" />
<ClInclude Include="MatrixStack.hpp" />
<ClInclude Include="Program.h" />
<ClInclude Include="Query.h" />
<ClInclude Include="Renderbuffer.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="ResourceManager.h" />
<ClInclude Include="Shader.h" />
<ClInclude Include="Surface.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="utilities.h" />
<ClInclude Include="VertexDataManager.h" />
......
......@@ -65,12 +65,21 @@
<ClCompile Include="Query.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\Object.cpp">
<ClCompile Include="MatrixStack.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\NameSpace.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Display.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Surface.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Buffer.h">
......@@ -124,25 +133,37 @@
<ClInclude Include="Image.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES2\gl2.h">
<ClInclude Include="Query.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES2\gl2ext.h">
<ClInclude Include="..\common\debug.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES2\gl2platform.h">
<ClInclude Include="MatrixStack.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Query.h">
<ClInclude Include="Display.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\debug.h">
<ClInclude Include="Surface.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\Object.hpp">
<ClInclude Include="..\common\NameSpace.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\NameSpace.hpp">
<ClInclude Include="..\include\GL\glcorearb.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GL\glext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GL\glxext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GL\wglext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\Object.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
......
......@@ -13,12 +13,14 @@
#include "main.h"
#include "resource.h"
#include "Framebuffer.h"
#include "libEGL/Surface.h"
#include "Surface.h"
#include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
#include "common/debug.h"
static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#if !defined(_MSC_VER)
#define CONSTRUCTOR __attribute__((constructor))
#define DESTRUCTOR __attribute__((destructor))
......@@ -30,43 +32,57 @@
static void glAttachThread()
{
TRACE("()");
gl::Current *current = new gl::Current;
if(current)
{
sw::Thread::setLocalStorage(currentTLS, current);
current->context = 0;
current->display = 0;
current->drawSurface = 0;
current->readSurface = 0;
}
}
static void glDetachThread()
{
TRACE("()");
gl::Current *current = (gl::Current*)sw::Thread::getLocalStorage(currentTLS);
if(current)
{
delete current;
}
}
CONSTRUCTOR static bool glAttachProcess()
{
TRACE("()");
glAttachThread();
#if !(ANGLE_DISABLE_TRACE)
FILE *debug = fopen(TRACE_OUTPUT_FILE, "rt");
#if defined(_WIN32)
const char *libEGL_lib[] = {"libEGL.dll", "libEGL_translator.dll"};
#elif defined(__LP64__)
const char *libEGL_lib[] = {"lib64EGL_translator.so", "libEGL.so.1", "libEGL.so"};
#else
const char *libEGL_lib[] = {"libEGL_translator.so", "libEGL.so.1", "libEGL.so"};
if(debug)
{
fclose(debug);
debug = fopen(TRACE_OUTPUT_FILE, "wt"); // Erase
fclose(debug);
}
#endif
libEGL = loadLibrary(libEGL_lib);
egl::getCurrentContext = (egl::Context *(*)())getProcAddress(libEGL, "clientGetCurrentContext");
egl::getCurrentDisplay = (egl::Display *(*)())getProcAddress(libEGL, "clientGetCurrentDisplay");
currentTLS = sw::Thread::allocateLocalStorageKey();
#if defined(_WIN32)
const char *libGLES_CM_lib[] = {"libGLES_CM.dll", "libGLES_CM_translator.dll"};
#elif defined(__LP64__)
const char *libGLES_CM_lib[] = {"lib64GLES_CM_translator.so", "libGLES_CM.so.1", "libGLES_CM.so"};
#else
const char *libGLES_CM_lib[] = {"libGLES_CM_translator.so", "libGLES_CM.so.1", "libGLES_CM.so"};
#endif
if(currentTLS == TLS_OUT_OF_INDEXES)
{
return false;
}
libGLES_CM = loadLibrary(libGLES_CM_lib);
es1::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLES_CM, "glGetProcAddress");
glAttachThread();
return libEGL != 0;
return true;
}
DESTRUCTOR static void glDetachProcess()
......@@ -74,16 +90,57 @@ DESTRUCTOR static void glDetachProcess()
TRACE("()");
glDetachThread();
freeLibrary(libEGL);
freeLibrary(libGLES_CM);
sw::Thread::freeLocalStorageKey(currentTLS);
}
#if defined(_WIN32)
static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
switch(uMsg)
{
case WM_INITDIALOG:
GetWindowRect(GetDesktopWindow(), &rect);
SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE);
SetTimer(hwnd, 1, 100, NULL);
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwnd, 0);
}
break;
case WM_TIMER:
if(IsDebuggerPresent())
{
EndDialog(hwnd, 0);
}
}
return FALSE;
}
static void WaitForDebugger(HINSTANCE instance)
{
if(!IsDebuggerPresent())
{
HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG);
DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog);
DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc);
}
}
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
if(false)
{
WaitForDebugger(instance);
}
return glAttachProcess();
break;
case DLL_THREAD_ATTACH:
......@@ -105,21 +162,43 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
namespace gl
{
gl::Context *getContext()
static gl::Current *getCurrent(void)
{
egl::Context *context = egl::getCurrentContext();
Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS);
if(context && context->getClientVersion() == 2)
if(!current)
{
return static_cast<gl::Context*>(context);
glAttachThread();
}
return 0;
return (Current*)sw::Thread::getLocalStorage(currentTLS);
}
void makeCurrent(Context *context, Display *display, Surface *surface)
{
Current *current = getCurrent();
current->context = context;
current->display = display;
if(context && display && surface)
{
context->makeCurrent(surface);
}
}
egl::Display *getDisplay()
Context *getContext()
{
return egl::getCurrentDisplay();
Current *current = getCurrent();
return current->context;
}
Display *getDisplay()
{
Current *current = getCurrent();
return current->display;
}
Device *getDevice()
......@@ -128,15 +207,47 @@ Device *getDevice()
return context ? context->getDevice() : 0;
}
void setCurrentDisplay(Display *dpy)
{
Current *current = getCurrent();
current->display = dpy;
}
void setCurrentContext(gl::Context *ctx)
{
Current *current = getCurrent();
current->context = ctx;
}
void setCurrentDrawSurface(Surface *surface)
{
Current *current = getCurrent();
current->drawSurface = surface;
}
namespace egl
Surface *getCurrentDrawSurface()
{
GLint getClientVersion()
Current *current = getCurrent();
return current->drawSurface;
}
void setCurrentReadSurface(Surface *surface)
{
Context *context = egl::getCurrentContext();
Current *current = getCurrent();
return context ? context->getClientVersion() : 0;
current->readSurface = surface;
}
Surface *getCurrentReadSurface()
{
Current *current = getCurrent();
return current->readSurface;
}
}
......@@ -173,17 +284,3 @@ void error(GLenum errorCode)
}
}
}
namespace egl
{
egl::Context *(*getCurrentContext)() = 0;
egl::Display *(*getCurrentDisplay)() = 0;
}
namespace es1
{
__eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0;
}
void *libEGL = 0; // Handle to the libEGL module
void *libGLES_CM = 0; // Handle to the libGLES_CM module
......@@ -17,48 +17,56 @@
#include "Context.h"
#include "Device.hpp"
#include "common/debug.h"
#include "libEGL/Display.h"
#include "Display.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
namespace gl
{
struct Current
{
Context *context;
Display *display;
Surface *drawSurface;
Surface *readSurface;
};
void makeCurrent(Context *context, Display *display, Surface *surface);
Context *getContext();
egl::Display *getDisplay();
Display *getDisplay();
Device *getDevice();
}
namespace egl
{
GLint getClientVersion();
Surface *getCurrentDrawSurface();
Surface *getCurrentReadSurface();
void setCurrentDisplay(Display *dpy);
void setCurrentContext(gl::Context *ctx);
void setCurrentDrawSurface(Surface *surface);
void setCurrentReadSurface(Surface *surface);
}
void error(GLenum errorCode);
template<class T>
const T &error(GLenum errorCode, const T &returnValue)
T &error(GLenum errorCode, T &returnValue)
{
error(errorCode);
return returnValue;
}
// libEGL dependencies
namespace egl
template<class T>
const T &error(GLenum errorCode, const T &returnValue)
{
extern egl::Context *(*getCurrentContext)();
extern egl::Display *(*getCurrentDisplay)();
}
error(errorCode);
// libGLES_CM dependencies
namespace es1
{
extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname);
return returnValue;
}
extern void *libEGL; // Handle to the libEGL module
extern void *libGLES_CM; // Handle to the libGLES_CM module
extern "C" sw::FrameBuffer *createFrameBuffer(NativeDisplayType display, NativeWindowType window, int width, int height);
#endif // LIBGL_MAIN_H_
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by libGL.rc
//
#define IDD_DIALOG1 101
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
......
......@@ -31,8 +31,6 @@ namespace gl
case GL_INT:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_3D_OES:
return 1;
case GL_BOOL_VEC2:
case GL_FLOAT_VEC2:
......@@ -78,8 +76,6 @@ namespace gl
case GL_INT:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_3D_OES:
case GL_INT_VEC2:
case GL_INT_VEC3:
case GL_INT_VEC4:
......@@ -123,8 +119,6 @@ namespace gl
case GL_INT_VEC4:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES:
case GL_SAMPLER_3D_OES:
return 1;
case GL_FLOAT_MAT2:
return 2;
......@@ -210,10 +204,9 @@ namespace gl
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_ETC1_RGB8_OES:
return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
return 16 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
default:
return 0;
......@@ -224,21 +217,20 @@ namespace gl
{
return format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE ||
format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE ||
format == GL_ETC1_RGB8_OES;
format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
}
bool IsDepthTexture(GLenum format)
{
return format == GL_DEPTH_COMPONENT ||
format == GL_DEPTH_STENCIL_OES;
format == GL_DEPTH_STENCIL_EXT;
}
bool IsStencilTexture(GLenum format)
{
return format == GL_STENCIL_INDEX_OES ||
format == GL_DEPTH_STENCIL_OES;
return format == GL_STENCIL_INDEX ||
format == GL_DEPTH_STENCIL_EXT;
}
// Returns the size, in bytes, of a single texel in an Image
......@@ -264,7 +256,8 @@ namespace gl
case GL_UNSIGNED_SHORT:
return sizeof(unsigned short);
case GL_UNSIGNED_INT:
case GL_UNSIGNED_INT_24_8_OES:
case GL_UNSIGNED_INT_24_8_EXT:
case GL_UNSIGNED_INT_8_8_8_8_REV:
return sizeof(unsigned int);
case GL_FLOAT:
switch(format)
......@@ -277,7 +270,7 @@ namespace gl
default: UNREACHABLE();
}
break;
case GL_HALF_FLOAT_OES:
case GL_HALF_FLOAT:
switch(format)
{
case GL_ALPHA: return sizeof(unsigned short);
......@@ -338,7 +331,7 @@ namespace gl
return false;
}
case GL_FLOAT:
case GL_HALF_FLOAT_OES:
case GL_HALF_FLOAT:
switch(format)
{
case GL_RGBA:
......@@ -357,8 +350,10 @@ namespace gl
return (format == GL_RGB);
case GL_UNSIGNED_INT:
return (format == GL_DEPTH_COMPONENT);
case GL_UNSIGNED_INT_24_8_OES:
return (format == GL_DEPTH_STENCIL_OES);
case GL_UNSIGNED_INT_24_8_EXT:
return (format == GL_DEPTH_STENCIL_EXT);
case GL_UNSIGNED_INT_8_8_8_8_REV:
return (format == GL_BGRA);
default:
return false;
}
......@@ -371,12 +366,13 @@ namespace gl
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGB565:
case GL_RGB8_OES:
case GL_RGBA8_OES:
case GL_RGB8_EXT:
case GL_RGBA8_EXT:
return true;
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
case GL_STENCIL_INDEX8:
case GL_DEPTH24_STENCIL8_OES:
case GL_DEPTH24_STENCIL8_EXT:
return false;
default:
UNIMPLEMENTED();
......@@ -390,14 +386,15 @@ namespace gl
switch(internalformat)
{
case GL_DEPTH_COMPONENT16:
case GL_DEPTH24_STENCIL8_OES:
case GL_DEPTH_COMPONENT24:
case GL_DEPTH24_STENCIL8_EXT:
return true;
case GL_STENCIL_INDEX8:
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGB565:
case GL_RGB8_OES:
case GL_RGBA8_OES:
case GL_RGB8_EXT:
case GL_RGBA8_EXT:
return false;
default:
UNIMPLEMENTED();
......@@ -411,14 +408,15 @@ namespace gl
switch(internalformat)
{
case GL_STENCIL_INDEX8:
case GL_DEPTH24_STENCIL8_OES:
case GL_DEPTH24_STENCIL8_EXT:
return true;
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGB565:
case GL_RGB8_OES:
case GL_RGBA8_OES:
case GL_RGB8_EXT:
case GL_RGBA8_EXT:
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
return false;
default:
UNIMPLEMENTED();
......@@ -533,6 +531,7 @@ namespace es2sw
{
switch(wrap)
{
case GL_CLAMP: return sw::ADDRESSING_CLAMP;
case GL_REPEAT: return sw::ADDRESSING_WRAP;
case GL_CLAMP_TO_EDGE: return sw::ADDRESSING_CLAMP;
case GL_MIRRORED_REPEAT: return sw::ADDRESSING_MIRROR;
......@@ -650,6 +649,10 @@ namespace es2sw
swPrimitiveType = gl::DRAW_TRIANGLEFAN;
primitiveCount = elementCount - 2;
break;
case GL_QUADS:
swPrimitiveType = gl::DRAW_QUADLIST;
primitiveCount = (elementCount / 4) * 2;
break;
default:
return false;
}
......@@ -663,12 +666,13 @@ namespace es2sw
{
case GL_RGBA4:
case GL_RGB5_A1:
case GL_RGBA8_OES: return sw::FORMAT_A8R8G8B8;
case GL_RGBA8_EXT: return sw::FORMAT_A8R8G8B8;
case GL_RGB565: return sw::FORMAT_R5G6B5;
case GL_RGB8_OES: return sw::FORMAT_X8R8G8B8;
case GL_RGB8_EXT: return sw::FORMAT_X8R8G8B8;
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
case GL_STENCIL_INDEX8:
case GL_DEPTH24_STENCIL8_OES: return sw::FORMAT_D24S8;
case GL_DEPTH24_STENCIL8_EXT: return sw::FORMAT_D24S8;
default: UNREACHABLE(); return sw::FORMAT_A8R8G8B8;
}
}
......@@ -812,10 +816,10 @@ namespace sw2es
switch(format)
{
case sw::FORMAT_A4R4G4B4: return GL_RGBA4;
case sw::FORMAT_A8R8G8B8: return GL_RGBA8_OES;
case sw::FORMAT_A8R8G8B8: return GL_RGBA8_EXT;
case sw::FORMAT_A1R5G5B5: return GL_RGB5_A1;
case sw::FORMAT_R5G6B5: return GL_RGB565;
case sw::FORMAT_X8R8G8B8: return GL_RGB8_OES;
case sw::FORMAT_X8R8G8B8: return GL_RGB8_EXT;
default:
UNREACHABLE();
}
......@@ -828,15 +832,16 @@ namespace sw2es
switch(format)
{
case sw::FORMAT_D16:
case sw::FORMAT_D24X8:
case sw::FORMAT_D32:
return GL_DEPTH_COMPONENT16;
case sw::FORMAT_D24X8:
return GL_DEPTH_COMPONENT24;
case sw::FORMAT_D24S8:
return GL_DEPTH24_STENCIL8_OES;
return GL_DEPTH24_STENCIL8_EXT;
default:
UNREACHABLE();
}
return GL_DEPTH24_STENCIL8_OES;
return GL_DEPTH24_STENCIL8_EXT;
}
}
......@@ -18,9 +18,11 @@
#include "Image.hpp"
#include "Texture.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#define _GDI32_
#include <windows.h>
#include <GL/GL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glext.h>
#include <string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment