Commit 264f1526 by Nicolas Capens

Copy libGLESv2 to libGL.

Bug 18962347 Change-Id: I1864755cac7f009119d0efb5278d7dfe3e669354 Reviewed-on: https://swiftshader-review.googlesource.com/1723Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent cc863da5
// 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.
//
// 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"
#include "main.h"
#include "VertexDataManager.h"
#include "IndexDataManager.h"
namespace es2
{
Buffer::Buffer(GLuint id) : RefCountObject(id)
{
mContents = 0;
mSize = 0;
mUsage = GL_DYNAMIC_DRAW;
}
Buffer::~Buffer()
{
if(mContents)
{
mContents->destruct();
}
}
void Buffer::bufferData(const void *data, GLsizeiptr size, GLenum usage)
{
if(mContents)
{
mContents->destruct();
mContents = 0;
}
mSize = size;
mUsage = usage;
if(size > 0)
{
const int padding = 1024; // For SIMD processing of vertices
mContents = new sw::Resource(size + padding);
if(!mContents)
{
return error(GL_OUT_OF_MEMORY);
}
if(data)
{
memcpy((void*)mContents->data(), data, size);
}
}
}
void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset)
{
if(mContents)
{
char *buffer = (char*)mContents->lock(sw::PUBLIC);
memcpy(buffer + offset, data, size);
mContents->unlock();
}
}
sw::Resource *Buffer::getResource()
{
return mContents;
}
}
// 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.
//
// 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 LIBGLESV2_BUFFER_H_
#define LIBGLESV2_BUFFER_H_
#include "common/Object.hpp"
#include "Common/Resource.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <cstddef>
#include <vector>
namespace es2
{
class Buffer : public gl::RefCountObject
{
public:
explicit Buffer(GLuint id);
virtual ~Buffer();
void bufferData(const void *data, GLsizeiptr size, GLenum usage);
void bufferSubData(const void *data, GLsizeiptr size, GLintptr offset);
const void *data() { return mContents ? mContents->data() : 0; }
size_t size() const { return mSize; }
GLenum usage() const { return mUsage; }
sw::Resource *getResource();
private:
sw::Resource *mContents;
size_t mSize;
GLenum mUsage;
};
}
#endif // LIBGLESV2_BUFFER_H_
// 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.
//
#ifndef gl_Device_hpp
#define gl_Device_hpp
#include "Renderer/Renderer.hpp"
namespace egl
{
class Image;
}
namespace es2
{
class Texture;
class Image;
enum PrimitiveType
{
DRAW_POINTLIST,
DRAW_LINELIST,
DRAW_LINESTRIP,
DRAW_LINELOOP,
DRAW_TRIANGLELIST,
DRAW_TRIANGLESTRIP,
DRAW_TRIANGLEFAN
};
struct Viewport
{
int x0;
int y0;
unsigned int width;
unsigned int height;
float minZ;
float maxZ;
};
class Device : public sw::Renderer
{
public:
explicit Device(sw::Context *context);
virtual ~Device();
virtual void clearColor(unsigned int color, unsigned int rgbaMask);
virtual void clearDepth(float z);
virtual void clearStencil(unsigned int stencil, unsigned int mask);
virtual Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
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 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 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 void finish();
private:
sw::Context *const context;
bool bindResources();
void bindShaderConstants();
bool bindViewport(); // Also adjusts for scissoring
bool validRectangle(const sw::Rect *rect, egl::Image *surface);
Viewport viewport;
sw::Rect scissorRect;
bool scissorEnable;
sw::PixelShader *pixelShader;
sw::VertexShader *vertexShader;
bool pixelShaderDirty;
unsigned int pixelShaderConstantsFDirty;
bool vertexShaderDirty;
unsigned int vertexShaderConstantsFDirty;
float pixelShaderConstantF[224][4];
float vertexShaderConstantF[256][4];
egl::Image *renderTarget;
egl::Image *depthStencil;
};
}
#endif // gl_Device_hpp
// 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.
//
// Fence.cpp: Implements the Fence class, which supports the GL_NV_fence extension.
#include "Fence.h"
#include "main.h"
#include "Common/Thread.hpp"
namespace es2
{
Fence::Fence()
{
mQuery = false;
mCondition = GL_NONE;
mStatus = GL_FALSE;
}
Fence::~Fence()
{
mQuery = false;
}
GLboolean Fence::isFence()
{
// GL_NV_fence spec:
// A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence.
return mQuery;
}
void Fence::setFence(GLenum condition)
{
if(condition != GL_ALL_COMPLETED_NV)
{
return error(GL_INVALID_VALUE);
}
mQuery = true;
mCondition = condition;
mStatus = GL_FALSE;
}
GLboolean Fence::testFence()
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION, GL_TRUE);
}
// The current assumtion is that no matter where the fence is placed, it is
// done by the time it is tested, which is similar to Context::flush(), since
// we don't queue anything without processing it as fast as possible.
mStatus = GL_TRUE;
return mStatus;
}
void Fence::finishFence()
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION);
}
while(!testFence())
{
sw::Thread::yield();
}
}
void Fence::getFenceiv(GLenum pname, GLint *params)
{
if(!mQuery)
{
return error(GL_INVALID_OPERATION);
}
switch (pname)
{
case GL_FENCE_STATUS_NV:
{
// GL_NV_fence spec:
// Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV
// or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
if(mStatus)
{
params[0] = GL_TRUE;
return;
}
mStatus = testFence();
params[0] = mStatus;
break;
}
case GL_FENCE_CONDITION_NV:
params[0] = mCondition;
break;
default:
return error(GL_INVALID_ENUM);
break;
}
}
}
// 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.
//
// Fence.h: Defines the Fence class, which supports the GL_NV_fence extension.
#ifndef LIBGLESV2_FENCE_H_
#define LIBGLESV2_FENCE_H_
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
class Fence
{
public:
Fence();
virtual ~Fence();
GLboolean isFence();
void setFence(GLenum condition);
GLboolean testFence();
void finishFence();
void getFenceiv(GLenum pname, GLint *params);
private:
bool mQuery;
GLenum mCondition;
GLboolean mStatus;
};
}
#endif // LIBGLESV2_FENCE_H_
// 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.
//
// Framebuffer.cpp: Implements the Framebuffer class. Implements GL framebuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
#include "Framebuffer.h"
#include "main.h"
#include "Renderbuffer.h"
#include "Texture.h"
#include "utilities.h"
namespace es2
{
Framebuffer::Framebuffer()
{
mColorbufferType = GL_NONE;
mDepthbufferType = GL_NONE;
mStencilbufferType = GL_NONE;
}
Framebuffer::~Framebuffer()
{
mColorbufferPointer.set(NULL);
mDepthbufferPointer.set(NULL);
mStencilbufferPointer.set(NULL);
}
Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const
{
Context *context = getContext();
Renderbuffer *buffer = NULL;
if(type == GL_NONE)
{
buffer = NULL;
}
else if(type == GL_RENDERBUFFER)
{
buffer = context->getRenderbuffer(handle);
}
else if(IsTextureTarget(type))
{
buffer = context->getTexture(handle)->getRenderbuffer(type);
}
else
{
UNREACHABLE();
}
return buffer;
}
void Framebuffer::setColorbuffer(GLenum type, GLuint colorbuffer)
{
mColorbufferType = (colorbuffer != 0) ? type : GL_NONE;
mColorbufferPointer.set(lookupRenderbuffer(type, colorbuffer));
}
void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer)
{
mDepthbufferType = (depthbuffer != 0) ? type : GL_NONE;
mDepthbufferPointer.set(lookupRenderbuffer(type, depthbuffer));
}
void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer)
{
mStencilbufferType = (stencilbuffer != 0) ? type : GL_NONE;
mStencilbufferPointer.set(lookupRenderbuffer(type, stencilbuffer));
}
void Framebuffer::detachTexture(GLuint texture)
{
if(mColorbufferPointer.id() == texture && IsTextureTarget(mColorbufferType))
{
mColorbufferType = GL_NONE;
mColorbufferPointer.set(NULL);
}
if(mDepthbufferPointer.id() == texture && IsTextureTarget(mDepthbufferType))
{
mDepthbufferType = GL_NONE;
mDepthbufferPointer.set(NULL);
}
if(mStencilbufferPointer.id() == texture && IsTextureTarget(mStencilbufferType))
{
mStencilbufferType = GL_NONE;
mStencilbufferPointer.set(NULL);
}
}
void Framebuffer::detachRenderbuffer(GLuint renderbuffer)
{
if(mColorbufferPointer.id() == renderbuffer && mColorbufferType == GL_RENDERBUFFER)
{
mColorbufferType = GL_NONE;
mColorbufferPointer.set(NULL);
}
if(mDepthbufferPointer.id() == renderbuffer && mDepthbufferType == GL_RENDERBUFFER)
{
mDepthbufferType = GL_NONE;
mDepthbufferPointer.set(NULL);
}
if(mStencilbufferPointer.id() == renderbuffer && mStencilbufferType == GL_RENDERBUFFER)
{
mStencilbufferType = GL_NONE;
mStencilbufferPointer.set(NULL);
}
}
// Increments refcount on surface.
// caller must Release() the returned surface
egl::Image *Framebuffer::getRenderTarget()
{
Renderbuffer *colorbuffer = mColorbufferPointer.get();
if(colorbuffer)
{
return colorbuffer->getRenderTarget();
}
return NULL;
}
// Increments refcount on surface.
// caller must Release() the returned surface
egl::Image *Framebuffer::getDepthStencil()
{
Renderbuffer *depthstencilbuffer = mDepthbufferPointer.get();
if(!depthstencilbuffer)
{
depthstencilbuffer = mStencilbufferPointer.get();
}
if(depthstencilbuffer)
{
return depthstencilbuffer->getRenderTarget();
}
return NULL;
}
Renderbuffer *Framebuffer::getColorbuffer()
{
return mColorbufferPointer.get();
}
Renderbuffer *Framebuffer::getDepthbuffer()
{
return mDepthbufferPointer.get();
}
Renderbuffer *Framebuffer::getStencilbuffer()
{
return mStencilbufferPointer.get();
}
GLenum Framebuffer::getColorbufferType()
{
return mColorbufferType;
}
GLenum Framebuffer::getDepthbufferType()
{
return mDepthbufferType;
}
GLenum Framebuffer::getStencilbufferType()
{
return mStencilbufferType;
}
GLuint Framebuffer::getColorbufferHandle()
{
return mColorbufferPointer.id();
}
GLuint Framebuffer::getDepthbufferHandle()
{
return mDepthbufferPointer.id();
}
GLuint Framebuffer::getStencilbufferHandle()
{
return mStencilbufferPointer.id();
}
bool Framebuffer::hasStencil()
{
if(mStencilbufferType != GL_NONE)
{
Renderbuffer *stencilbufferObject = getStencilbuffer();
if(stencilbufferObject)
{
return stencilbufferObject->getStencilSize() > 0;
}
}
return false;
}
GLenum Framebuffer::completeness()
{
int width;
int height;
int samples;
return completeness(width, height, samples);
}
GLenum Framebuffer::completeness(int &width, int &height, int &samples)
{
width = -1;
height = -1;
samples = -1;
if(mColorbufferType != GL_NONE)
{
Renderbuffer *colorbuffer = getColorbuffer();
if(!colorbuffer)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(mColorbufferType == GL_RENDERBUFFER)
{
if(!es2::IsColorRenderable(colorbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if(IsTextureTarget(mColorbufferType))
{
GLenum format = colorbuffer->getFormat();
if(IsCompressed(format) ||
format == GL_ALPHA ||
format == GL_LUMINANCE ||
format == GL_LUMINANCE_ALPHA)
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
if(es2::IsDepthTexture(format) || es2::IsStencilTexture(format))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else
{
UNREACHABLE();
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
width = colorbuffer->getWidth();
height = colorbuffer->getHeight();
samples = colorbuffer->getSamples();
}
Renderbuffer *depthbuffer = NULL;
Renderbuffer *stencilbuffer = NULL;
if(mDepthbufferType != GL_NONE)
{
depthbuffer = getDepthbuffer();
if(!depthbuffer)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(depthbuffer->getWidth() == 0 || depthbuffer->getHeight() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(mDepthbufferType == GL_RENDERBUFFER)
{
if(!es2::IsDepthRenderable(depthbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if(IsTextureTarget(mDepthbufferType))
{
if(!es2::IsDepthTexture(depthbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else
{
UNREACHABLE();
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(width == -1 || height == -1)
{
width = depthbuffer->getWidth();
height = depthbuffer->getHeight();
samples = depthbuffer->getSamples();
}
else if(width != depthbuffer->getWidth() || height != depthbuffer->getHeight())
{
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
}
else if(samples != depthbuffer->getSamples())
{
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
}
}
if(mStencilbufferType != GL_NONE)
{
stencilbuffer = getStencilbuffer();
if(!stencilbuffer)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(stencilbuffer->getWidth() == 0 || stencilbuffer->getHeight() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(mStencilbufferType == GL_RENDERBUFFER)
{
if(!es2::IsStencilRenderable(stencilbuffer->getFormat()))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if(IsTextureTarget(mStencilbufferType))
{
GLenum internalformat = stencilbuffer->getFormat();
if(!es2::IsStencilTexture(internalformat))
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else
{
UNREACHABLE();
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
if(width == -1 || height == -1)
{
width = stencilbuffer->getWidth();
height = stencilbuffer->getHeight();
samples = stencilbuffer->getSamples();
}
else if(width != stencilbuffer->getWidth() || height != stencilbuffer->getHeight())
{
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
}
else if(samples != stencilbuffer->getSamples())
{
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
}
}
// If we have both a depth and stencil buffer, they must refer to the same object
// since we only support packed_depth_stencil and not separate depth and stencil
if(depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer))
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
// We need to have at least one attachment to be complete
if(width == -1 || height == -1)
{
return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
}
return GL_FRAMEBUFFER_COMPLETE;
}
DefaultFramebuffer::DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil)
{
mColorbufferPointer.set(new Renderbuffer(0, colorbuffer));
Renderbuffer *depthStencilRenderbuffer = new Renderbuffer(0, depthStencil);
mDepthbufferPointer.set(depthStencilRenderbuffer);
mStencilbufferPointer.set(depthStencilRenderbuffer);
mColorbufferType = GL_RENDERBUFFER;
mDepthbufferType = (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE;
mStencilbufferType = (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE;
}
GLenum DefaultFramebuffer::completeness()
{
// The default framebuffer should always be complete
ASSERT(Framebuffer::completeness() == GL_FRAMEBUFFER_COMPLETE);
return GL_FRAMEBUFFER_COMPLETE;
}
}
// 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.
//
// Framebuffer.h: Defines the Framebuffer class. Implements GL framebuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
#ifndef LIBGLESV2_FRAMEBUFFER_H_
#define LIBGLESV2_FRAMEBUFFER_H_
#include "common/Object.hpp"
#include "Image.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
class Renderbuffer;
class Colorbuffer;
class Depthbuffer;
class Stencilbuffer;
class DepthStencilbuffer;
class Framebuffer
{
public:
Framebuffer();
virtual ~Framebuffer();
void setColorbuffer(GLenum type, GLuint colorbuffer);
void setDepthbuffer(GLenum type, GLuint depthbuffer);
void setStencilbuffer(GLenum type, GLuint stencilbuffer);
void detachTexture(GLuint texture);
void detachRenderbuffer(GLuint renderbuffer);
egl::Image *getRenderTarget();
egl::Image *getDepthStencil();
Renderbuffer *getColorbuffer();
Renderbuffer *getDepthbuffer();
Renderbuffer *getStencilbuffer();
GLenum getColorbufferType();
GLenum getDepthbufferType();
GLenum getStencilbufferType();
GLuint getColorbufferHandle();
GLuint getDepthbufferHandle();
GLuint getStencilbufferHandle();
bool hasStencil();
virtual GLenum completeness();
GLenum completeness(int &width, int &height, int &samples);
protected:
GLenum mColorbufferType;
gl::BindingPointer<Renderbuffer> mColorbufferPointer;
GLenum mDepthbufferType;
gl::BindingPointer<Renderbuffer> mDepthbufferPointer;
GLenum mStencilbufferType;
gl::BindingPointer<Renderbuffer> mStencilbufferPointer;
private:
Renderbuffer *lookupRenderbuffer(GLenum type, GLuint handle) const;
};
class DefaultFramebuffer : public Framebuffer
{
public:
DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil);
virtual GLenum completeness();
};
}
#endif // LIBGLESV2_FRAMEBUFFER_H_
// 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.
//
// HandleAllocator.cpp: Implements the HandleAllocator class, which is used
// to allocate GL handles.
#include "HandleAllocator.h"
#include "main.h"
namespace es2
{
HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
{
}
HandleAllocator::~HandleAllocator()
{
}
void HandleAllocator::setBaseHandle(GLuint value)
{
ASSERT(mBaseValue == mNextValue);
mBaseValue = value;
mNextValue = value;
}
GLuint HandleAllocator::allocate()
{
if(mFreeValues.size())
{
GLuint handle = mFreeValues.back();
mFreeValues.pop_back();
return handle;
}
return mNextValue++;
}
void HandleAllocator::release(GLuint handle)
{
if(handle == mNextValue - 1)
{
// Don't drop below base value
if(mNextValue > mBaseValue)
{
mNextValue--;
}
}
else
{
// Only free handles that we own - don't drop below the base value
if(handle >= mBaseValue)
{
mFreeValues.push_back(handle);
}
}
}
}
// 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.
//
// HandleAllocator.h: Defines the HandleAllocator class, which is used to
// allocate GL handles.
#ifndef LIBGLESV2_HANDLEALLOCATOR_H_
#define LIBGLESV2_HANDLEALLOCATOR_H_
#define GL_APICALL
#include <GLES2/gl2.h>
#include <vector>
namespace es2
{
class HandleAllocator
{
public:
HandleAllocator();
virtual ~HandleAllocator();
void setBaseHandle(GLuint value);
GLuint allocate();
void release(GLuint handle);
private:
GLuint mBaseValue;
GLuint mNextValue;
typedef std::vector<GLuint> HandleList;
HandleList mFreeValues;
};
}
#endif // LIBGLESV2_HANDLEALLOCATOR_H_
// 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.
//
#ifndef gl_Image_hpp
#define gl_Image_hpp
#include "Renderer/Surface.hpp"
#include "libEGL/Image.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
class Texture;
class Image : public egl::Image
{
public:
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget);
void loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
virtual void addRef();
virtual void release();
virtual void unbind(const egl::Texture *parent); // Break parent ownership and release
static sw::Format selectInternalFormat(GLenum format, GLenum type);
private:
virtual ~Image();
void loadAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGB565ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBA4444ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBA5551ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadBGRAImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD16ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
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;
volatile int referenceCount;
};
}
#endif // gl_Image_hpp
// 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.
//
// IndexDataManager.cpp: Defines the IndexDataManager, a class that
// runs the Buffer translation process for index buffers.
#include "IndexDataManager.h"
#include "Buffer.h"
#include "common/debug.h"
#include <string.h>
#include <algorithm>
namespace
{
enum { INITIAL_INDEX_BUFFER_SIZE = 4096 * sizeof(GLuint) };
}
namespace es2
{
IndexDataManager::IndexDataManager()
{
mStreamingBuffer = new StreamingIndexBuffer(INITIAL_INDEX_BUFFER_SIZE);
if(!mStreamingBuffer)
{
ERR("Failed to allocate the streaming index buffer.");
}
}
IndexDataManager::~IndexDataManager()
{
delete mStreamingBuffer;
}
void copyIndices(GLenum type, const void *input, GLsizei count, void *output)
{
if(type == GL_UNSIGNED_BYTE)
{
memcpy(output, input, count * sizeof(GLubyte));
}
else if(type == GL_UNSIGNED_INT)
{
memcpy(output, input, count * sizeof(GLuint));
}
else if(type == GL_UNSIGNED_SHORT)
{
memcpy(output, input, count * sizeof(GLushort));
}
else UNREACHABLE();
}
template<class IndexType>
void computeRange(const IndexType *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex)
{
*minIndex = indices[0];
*maxIndex = indices[0];
for(GLsizei i = 0; i < count; i++)
{
if(*minIndex > indices[i]) *minIndex = indices[i];
if(*maxIndex < indices[i]) *maxIndex = indices[i];
}
}
void computeRange(GLenum type, const void *indices, GLsizei count, GLuint *minIndex, GLuint *maxIndex)
{
if(type == GL_UNSIGNED_BYTE)
{
computeRange(static_cast<const GLubyte*>(indices), count, minIndex, maxIndex);
}
else if(type == GL_UNSIGNED_INT)
{
computeRange(static_cast<const GLuint*>(indices), count, minIndex, maxIndex);
}
else if(type == GL_UNSIGNED_SHORT)
{
computeRange(static_cast<const GLushort*>(indices), count, minIndex, maxIndex);
}
else UNREACHABLE();
}
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const void *indices, TranslatedIndexData *translated)
{
if(!mStreamingBuffer)
{
return GL_OUT_OF_MEMORY;
}
intptr_t offset = reinterpret_cast<intptr_t>(indices);
bool alignedOffset = false;
if(buffer != NULL)
{
switch(type)
{
case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break;
case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break;
case GL_UNSIGNED_INT: alignedOffset = (offset % sizeof(GLuint) == 0); break;
default: UNREACHABLE(); alignedOffset = false;
}
if(typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size()))
{
return GL_INVALID_OPERATION;
}
indices = static_cast<const GLubyte*>(buffer->data()) + offset;
}
StreamingIndexBuffer *streamingBuffer = mStreamingBuffer;
sw::Resource *staticBuffer = buffer ? buffer->getResource() : NULL;
if(staticBuffer)
{
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
translated->indexBuffer = staticBuffer;
translated->indexOffset = offset;
}
else
{
unsigned int streamOffset = 0;
int convertCount = count;
streamingBuffer->reserveSpace(convertCount * typeSize(type), type);
void *output = streamingBuffer->map(typeSize(type) * convertCount, &streamOffset);
if(output == NULL)
{
ERR("Failed to map index buffer.");
return GL_OUT_OF_MEMORY;
}
copyIndices(type, staticBuffer ? buffer->data() : indices, convertCount, output);
streamingBuffer->unmap();
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
translated->indexBuffer = streamingBuffer->getResource();
translated->indexOffset = streamOffset;
}
return GL_NO_ERROR;
}
std::size_t IndexDataManager::typeSize(GLenum type)
{
switch(type)
{
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
default: UNREACHABLE(); return sizeof(GLushort);
}
}
StreamingIndexBuffer::StreamingIndexBuffer(unsigned int initialSize) : mBufferSize(initialSize), mIndexBuffer(NULL)
{
if(initialSize > 0)
{
mIndexBuffer = new sw::Resource(initialSize + 16);
if(!mIndexBuffer)
{
ERR("Out of memory allocating an index buffer of size %lu.", initialSize);
}
}
mWritePosition = 0;
}
StreamingIndexBuffer::~StreamingIndexBuffer()
{
if(mIndexBuffer)
{
mIndexBuffer->destruct();
}
}
void *StreamingIndexBuffer::map(unsigned int requiredSpace, unsigned int *offset)
{
void *mapPtr = NULL;
if(mIndexBuffer)
{
mapPtr = (char*)mIndexBuffer->lock(sw::PUBLIC) + mWritePosition;
if(!mapPtr)
{
ERR(" Lock failed");
return NULL;
}
*offset = mWritePosition;
mWritePosition += requiredSpace;
}
return mapPtr;
}
void StreamingIndexBuffer::unmap()
{
if(mIndexBuffer)
{
mIndexBuffer->unlock();
}
}
void StreamingIndexBuffer::reserveSpace(unsigned int requiredSpace, GLenum type)
{
if(requiredSpace > mBufferSize)
{
if(mIndexBuffer)
{
mIndexBuffer->destruct();
mIndexBuffer = 0;
}
mBufferSize = std::max(requiredSpace, 2 * mBufferSize);
mIndexBuffer = new sw::Resource(mBufferSize + 16);
if(!mIndexBuffer)
{
ERR("Out of memory allocating an index buffer of size %lu.", mBufferSize);
}
mWritePosition = 0;
}
else if(mWritePosition + requiredSpace > mBufferSize) // Recycle
{
if(mIndexBuffer)
{
mIndexBuffer->destruct();
mIndexBuffer = new sw::Resource(mBufferSize + 16);
}
mWritePosition = 0;
}
}
sw::Resource *StreamingIndexBuffer::getResource() const
{
return mIndexBuffer;
}
}
// 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.
//
// IndexDataManager.h: Defines the IndexDataManager, a class that
// runs the Buffer translation process for index buffers.
#ifndef LIBGLESV2_INDEXDATAMANAGER_H_
#define LIBGLESV2_INDEXDATAMANAGER_H_
#include "Context.h"
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
struct TranslatedIndexData
{
unsigned int minIndex;
unsigned int maxIndex;
unsigned int indexOffset;
sw::Resource *indexBuffer;
};
class StreamingIndexBuffer
{
public:
StreamingIndexBuffer(unsigned int initialSize);
virtual ~StreamingIndexBuffer();
void *map(unsigned int requiredSpace, unsigned int *offset);
void unmap();
void reserveSpace(unsigned int requiredSpace, GLenum type);
sw::Resource *getResource() const;
private:
sw::Resource *mIndexBuffer;
unsigned int mBufferSize;
unsigned int mWritePosition;
};
class IndexDataManager
{
public:
IndexDataManager();
virtual ~IndexDataManager();
GLenum prepareIndexData(GLenum type, GLsizei count, Buffer *arrayElementBuffer, const void *indices, TranslatedIndexData *translated);
static std::size_t typeSize(GLenum type);
private:
StreamingIndexBuffer *mStreamingBuffer;
};
}
#endif // LIBGLESV2_INDEXDATAMANAGER_H_
// 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.
//
// Program.h: Defines the Program class. Implements GL program objects
// and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28.
#ifndef LIBGLESV2_PROGRAM_H_
#define LIBGLESV2_PROGRAM_H_
#include "Shader.h"
#include "Context.h"
#include "Shader/PixelShader.hpp"
#include "Shader/VertexShader.hpp"
#include <string>
#include <vector>
#include <set>
namespace es2
{
class Device;
class ResourceManager;
class FragmentShader;
class VertexShader;
// Helper struct representing a single shader uniform
struct Uniform
{
Uniform(GLenum type, GLenum precision, const std::string &name, unsigned int arraySize);
~Uniform();
bool isArray() const;
int size() const;
int registerCount() const;
const GLenum type;
const GLenum precision;
const std::string name;
const unsigned int arraySize;
unsigned char *data;
bool dirty;
short psRegisterIndex;
short vsRegisterIndex;
};
// Struct used for correlating uniforms/elements of uniform arrays to handles
struct UniformLocation
{
UniformLocation(const std::string &name, unsigned int element, unsigned int index);
std::string name;
unsigned int element;
unsigned int index;
};
class Program
{
public:
Program(ResourceManager *manager, GLuint handle);
~Program();
bool attachShader(Shader *shader);
bool detachShader(Shader *shader);
int getAttachedShadersCount() const;
sw::PixelShader *getPixelShader();
sw::VertexShader *getVertexShader();
void bindAttributeLocation(GLuint index, const char *name);
GLuint getAttributeLocation(const char *name);
int getAttributeStream(int attributeIndex);
GLint getSamplerMapping(sw::SamplerType type, unsigned int samplerIndex);
TextureType getSamplerTextureType(sw::SamplerType type, unsigned int samplerIndex);
GLint getUniformLocation(std::string name);
bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
bool setUniform2iv(GLint location, GLsizei count, const GLint *v);
bool setUniform3iv(GLint location, GLsizei count, const GLint *v);
bool setUniform4iv(GLint location, GLsizei count, const GLint *v);
bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
void dirtyAllUniforms();
void applyUniforms();
void link();
bool isLinked();
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
GLint getActiveAttributeCount() const;
GLint getActiveAttributeMaxLength() const;
void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
GLint getActiveUniformCount() const;
GLint getActiveUniformMaxLength() const;
void addRef();
void release();
unsigned int getRefCount() const;
void flagForDeletion();
bool isFlaggedForDeletion() const;
void validate();
bool validateSamplers(bool logErrors);
bool isValidated() const;
unsigned int getSerial() const;
private:
void unlink();
int packVaryings(const Varying *packing[][4]);
bool linkVaryings();
bool linkAttributes();
int getAttributeBinding(const std::string &name);
bool linkUniforms(Shader *shader);
bool defineUniform(GLenum shader, GLenum type, GLenum precision, const std::string &_name, unsigned int arraySize, int registerIndex);
bool applyUniform1bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform2bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform3bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform4bv(GLint location, GLsizei count, const GLboolean *v);
bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v);
bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
bool applyUniform1iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform2iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform3iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform4iv(GLint location, GLsizei count, const GLint *v);
void appendToInfoLog(const char *info, ...);
void resetInfoLog();
static unsigned int issueSerial();
private:
es2::Device *device;
FragmentShader *fragmentShader;
VertexShader *vertexShader;
sw::PixelShader *pixelBinary;
sw::VertexShader *vertexBinary;
std::set<std::string> attributeBinding[MAX_VERTEX_ATTRIBS];
sh::Attribute linkedAttribute[MAX_VERTEX_ATTRIBS];
int attributeStream[MAX_VERTEX_ATTRIBS];
struct Sampler
{
bool active;
GLint logicalTextureUnit;
TextureType textureType;
};
Sampler samplersPS[MAX_TEXTURE_IMAGE_UNITS];
Sampler samplersVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS];
typedef std::vector<Uniform*> UniformArray;
UniformArray uniforms;
typedef std::vector<UniformLocation> UniformIndex;
UniformIndex uniformIndex;
bool linked;
bool orphaned; // Flag to indicate that the program can be deleted when no longer in use
char *infoLog;
bool validated;
unsigned int referenceCount;
const unsigned int serial;
static unsigned int currentSerial;
ResourceManager *resourceManager;
const GLuint handle;
};
}
#endif // LIBGLESV2_PROGRAM_H_
// 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.
//
// Query.cpp: Implements the es2::Query class
#include "Query.h"
#include "main.h"
#include "Common/Thread.hpp"
namespace es2
{
Query::Query(GLuint id, GLenum type) : RefCountObject(id)
{
mQuery = NULL;
mStatus = GL_FALSE;
mResult = GL_FALSE;
mType = type;
}
Query::~Query()
{
if(mQuery != NULL)
{
delete mQuery;
}
}
void Query::begin()
{
if(mQuery == NULL)
{
mQuery = new sw::Query();
if(!mQuery)
{
return error(GL_OUT_OF_MEMORY);
}
}
Device *device = getDevice();
mQuery->begin();
device->addQuery(mQuery);
device->setOcclusionEnabled(true);
}
void Query::end()
{
if(mQuery == NULL)
{
return error(GL_INVALID_OPERATION);
}
Device *device = getDevice();
mQuery->end();
device->removeQuery(mQuery);
device->setOcclusionEnabled(false);
mStatus = GL_FALSE;
mResult = GL_FALSE;
}
GLuint Query::getResult()
{
if(mQuery != NULL)
{
while(!testQuery())
{
sw::Thread::yield();
}
}
return (GLuint)mResult;
}
GLboolean Query::isResultAvailable()
{
if(mQuery != NULL)
{
testQuery();
}
return mStatus;
}
GLenum Query::getType() const
{
return mType;
}
GLboolean Query::testQuery()
{
if(mQuery != NULL && mStatus != GL_TRUE)
{
if(!mQuery->building && mQuery->reference == 0)
{
unsigned int numPixels = mQuery->data;
mStatus = GL_TRUE;
switch(mType)
{
case GL_ANY_SAMPLES_PASSED_EXT:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
mResult = (numPixels > 0) ? GL_TRUE : GL_FALSE;
break;
default:
ASSERT(false);
}
}
return mStatus;
}
return GL_TRUE; // Prevent blocking when query is null
}
}
// 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.
//
// Query.h: Defines the es2::Query class
#ifndef LIBGLESV2_QUERY_H_
#define LIBGLESV2_QUERY_H_
#include "common/Object.hpp"
#include "Renderer/Renderer.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
class Query : public gl::RefCountObject
{
public:
Query(GLuint id, GLenum type);
virtual ~Query();
void begin();
void end();
GLuint getResult();
GLboolean isResultAvailable();
GLenum getType() const;
private:
GLboolean testQuery();
sw::Query* mQuery;
GLenum mType;
GLboolean mStatus;
GLint mResult;
};
}
#endif // LIBGLESV2_QUERY_H_
// 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.
//
// 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.
#ifndef LIBGLESV2_RENDERBUFFER_H_
#define LIBGLESV2_RENDERBUFFER_H_
#include "common/Object.hpp"
#include "Image.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
class Texture2D;
class TextureCubeMap;
class Renderbuffer;
class Colorbuffer;
class DepthStencilbuffer;
class RenderbufferInterface
{
public:
RenderbufferInterface();
virtual ~RenderbufferInterface() {};
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 GLsizei getWidth() const = 0;
virtual GLsizei getHeight() const = 0;
virtual GLenum getFormat() const = 0;
virtual sw::Format getInternalFormat() const = 0;
virtual GLsizei getSamples() const = 0;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
};
class RenderbufferTexture2D : public RenderbufferInterface
{
public:
RenderbufferTexture2D(Texture2D *texture);
virtual ~RenderbufferTexture2D();
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
virtual egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
private:
gl::BindingPointer<Texture2D> mTexture2D;
};
class RenderbufferTextureCubeMap : public RenderbufferInterface
{
public:
RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target);
virtual ~RenderbufferTextureCubeMap();
virtual void addProxyRef(const Renderbuffer *proxy);
virtual void releaseProxy(const Renderbuffer *proxy);
virtual Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
private:
gl::BindingPointer<TextureCubeMap> mTextureCubeMap;
GLenum mTarget;
};
// A class derived from RenderbufferStorage is created whenever glRenderbufferStorage
// is called. The specific concrete type depends on whether the internal format is
// colour depth, stencil or packed depth/stencil.
class RenderbufferStorage : public RenderbufferInterface
{
public:
RenderbufferStorage();
virtual ~RenderbufferStorage() = 0;
virtual egl::Image *getRenderTarget() = 0;
virtual egl::Image *createSharedImage() = 0;
virtual bool isShared() const = 0;
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
protected:
GLsizei mWidth;
GLsizei mHeight;
GLenum format;
sw::Format internalFormat;
GLsizei mSamples;
};
// Renderbuffer implements the GL renderbuffer object.
// It's only a proxy for a RenderbufferInterface instance; the internal object
// can change whenever glRenderbufferStorage is called.
class Renderbuffer : public gl::RefCountObject
{
public:
Renderbuffer(GLuint id, RenderbufferInterface *storage);
virtual ~Renderbuffer();
// These functions from RefCountObject are overloaded here because
// Textures need to maintain their own count of references to them via
// Renderbuffers/RenderbufferTextures. These functions invoke those
// reference counting functions on the RenderbufferInterface.
virtual void addRef();
virtual void release();
egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
GLsizei getWidth() const;
GLsizei getHeight() const;
GLenum getFormat() const;
sw::Format getInternalFormat() const;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
GLsizei getSamples() const;
void setStorage(RenderbufferStorage *newStorage);
private:
RenderbufferInterface *mInstance;
};
class Colorbuffer : public RenderbufferStorage
{
public:
explicit Colorbuffer(egl::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;
private:
egl::Image *mRenderTarget;
};
class DepthStencilbuffer : public RenderbufferStorage
{
public:
explicit DepthStencilbuffer(egl::Image *depthStencil);
DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
~DepthStencilbuffer();
virtual egl::Image *getRenderTarget();
virtual egl::Image *createSharedImage();
virtual bool isShared() const;
protected:
egl::Image *mDepthStencil;
};
class Depthbuffer : public DepthStencilbuffer
{
public:
explicit Depthbuffer(egl::Image *depthStencil);
Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
virtual ~Depthbuffer();
};
class Stencilbuffer : public DepthStencilbuffer
{
public:
explicit Stencilbuffer(egl::Image *depthStencil);
Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
virtual ~Stencilbuffer();
};
}
#endif // LIBGLESV2_RENDERBUFFER_H_
// 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.
//
// ResourceManager.cpp: Implements the ResourceManager class, which tracks and
// retrieves objects which may be shared by multiple Contexts.
#include "ResourceManager.h"
#include "Buffer.h"
#include "Program.h"
#include "Renderbuffer.h"
#include "Shader.h"
#include "Texture.h"
namespace es2
{
ResourceManager::ResourceManager()
{
mRefCount = 1;
}
ResourceManager::~ResourceManager()
{
while(!mBufferMap.empty())
{
deleteBuffer(mBufferMap.begin()->first);
}
while(!mProgramMap.empty())
{
deleteProgram(mProgramMap.begin()->first);
}
while(!mShaderMap.empty())
{
deleteShader(mShaderMap.begin()->first);
}
while(!mRenderbufferMap.empty())
{
deleteRenderbuffer(mRenderbufferMap.begin()->first);
}
while(!mTextureMap.empty())
{
deleteTexture(mTextureMap.begin()->first);
}
}
void ResourceManager::addRef()
{
mRefCount++;
}
void ResourceManager::release()
{
if(--mRefCount == 0)
{
delete this;
}
}
// Returns an unused buffer name
GLuint ResourceManager::createBuffer()
{
GLuint handle = mBufferHandleAllocator.allocate();
mBufferMap[handle] = NULL;
return handle;
}
// Returns an unused shader/program name
GLuint ResourceManager::createShader(GLenum type)
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
if(type == GL_VERTEX_SHADER)
{
mShaderMap[handle] = new VertexShader(this, handle);
}
else if(type == GL_FRAGMENT_SHADER)
{
mShaderMap[handle] = new FragmentShader(this, handle);
}
else UNREACHABLE();
return handle;
}
// Returns an unused program/shader name
GLuint ResourceManager::createProgram()
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
mProgramMap[handle] = new Program(this, handle);
return handle;
}
// Returns an unused texture name
GLuint ResourceManager::createTexture()
{
GLuint handle = mTextureHandleAllocator.allocate();
mTextureMap[handle] = NULL;
return handle;
}
// Returns an unused renderbuffer name
GLuint ResourceManager::createRenderbuffer()
{
GLuint handle = mRenderbufferHandleAllocator.allocate();
mRenderbufferMap[handle] = NULL;
return handle;
}
void ResourceManager::deleteBuffer(GLuint buffer)
{
BufferMap::iterator bufferObject = mBufferMap.find(buffer);
if(bufferObject != mBufferMap.end())
{
mBufferHandleAllocator.release(bufferObject->first);
if(bufferObject->second) bufferObject->second->release();
mBufferMap.erase(bufferObject);
}
}
void ResourceManager::deleteShader(GLuint shader)
{
ShaderMap::iterator shaderObject = mShaderMap.find(shader);
if(shaderObject != mShaderMap.end())
{
if(shaderObject->second->getRefCount() == 0)
{
mProgramShaderHandleAllocator.release(shaderObject->first);
delete shaderObject->second;
mShaderMap.erase(shaderObject);
}
else
{
shaderObject->second->flagForDeletion();
}
}
}
void ResourceManager::deleteProgram(GLuint program)
{
ProgramMap::iterator programObject = mProgramMap.find(program);
if(programObject != mProgramMap.end())
{
if(programObject->second->getRefCount() == 0)
{
mProgramShaderHandleAllocator.release(programObject->first);
delete programObject->second;
mProgramMap.erase(programObject);
}
else
{
programObject->second->flagForDeletion();
}
}
}
void ResourceManager::deleteTexture(GLuint texture)
{
TextureMap::iterator textureObject = mTextureMap.find(texture);
if(textureObject != mTextureMap.end())
{
mTextureHandleAllocator.release(textureObject->first);
if(textureObject->second) textureObject->second->release();
mTextureMap.erase(textureObject);
}
}
void ResourceManager::deleteRenderbuffer(GLuint renderbuffer)
{
RenderbufferMap::iterator renderbufferObject = mRenderbufferMap.find(renderbuffer);
if(renderbufferObject != mRenderbufferMap.end())
{
mRenderbufferHandleAllocator.release(renderbufferObject->first);
if(renderbufferObject->second) renderbufferObject->second->release();
mRenderbufferMap.erase(renderbufferObject);
}
}
Buffer *ResourceManager::getBuffer(unsigned int handle)
{
BufferMap::iterator buffer = mBufferMap.find(handle);
if(buffer == mBufferMap.end())
{
return NULL;
}
else
{
return buffer->second;
}
}
Shader *ResourceManager::getShader(unsigned int handle)
{
ShaderMap::iterator shader = mShaderMap.find(handle);
if(shader == mShaderMap.end())
{
return NULL;
}
else
{
return shader->second;
}
}
Texture *ResourceManager::getTexture(unsigned int handle)
{
if(handle == 0) return NULL;
TextureMap::iterator texture = mTextureMap.find(handle);
if(texture == mTextureMap.end())
{
return NULL;
}
else
{
return texture->second;
}
}
Program *ResourceManager::getProgram(unsigned int handle)
{
ProgramMap::iterator program = mProgramMap.find(handle);
if(program == mProgramMap.end())
{
return NULL;
}
else
{
return program->second;
}
}
Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
{
RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle);
if(renderbuffer == mRenderbufferMap.end())
{
return NULL;
}
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;
}
}
void ResourceManager::setRenderbuffer(GLuint handle, Renderbuffer *buffer)
{
mRenderbufferMap[handle] = buffer;
}
void ResourceManager::checkBufferAllocation(unsigned int buffer)
{
if(buffer != 0 && !getBuffer(buffer))
{
Buffer *bufferObject = new Buffer(buffer);
mBufferMap[buffer] = bufferObject;
bufferObject->addRef();
}
}
void ResourceManager::checkTextureAllocation(GLuint texture, TextureType type)
{
if(!getTexture(texture) && texture != 0)
{
Texture *textureObject;
if(type == TEXTURE_2D)
{
textureObject = new Texture2D(texture);
}
else if(type == TEXTURE_CUBE)
{
textureObject = new TextureCubeMap(texture);
}
else if(type == TEXTURE_EXTERNAL)
{
textureObject = new TextureExternal(texture);
}
else
{
UNREACHABLE();
return;
}
mTextureMap[texture] = textureObject;
textureObject->addRef();
}
}
}
// 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.
//
// ResourceManager.h : Defines the ResourceManager class, which tracks objects
// shared by multiple GL contexts.
#ifndef LIBGLESV2_RESOURCEMANAGER_H_
#define LIBGLESV2_RESOURCEMANAGER_H_
#include "HandleAllocator.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <map>
namespace es2
{
class Buffer;
class Shader;
class Program;
class Texture;
class Renderbuffer;
enum TextureType
{
TEXTURE_2D,
TEXTURE_CUBE,
TEXTURE_EXTERNAL,
TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN
};
class ResourceManager
{
public:
ResourceManager();
~ResourceManager();
void addRef();
void release();
GLuint createBuffer();
GLuint createShader(GLenum type);
GLuint createProgram();
GLuint createTexture();
GLuint createRenderbuffer();
void deleteBuffer(GLuint buffer);
void deleteShader(GLuint shader);
void deleteProgram(GLuint program);
void deleteTexture(GLuint texture);
void deleteRenderbuffer(GLuint renderbuffer);
Buffer *getBuffer(GLuint handle);
Shader *getShader(GLuint handle);
Program *getProgram(GLuint handle);
Texture *getTexture(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle);
void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type);
private:
std::size_t mRefCount;
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
HandleAllocator mBufferHandleAllocator;
typedef std::map<GLint, Shader*> ShaderMap;
ShaderMap mShaderMap;
typedef std::map<GLint, Program*> ProgramMap;
ProgramMap mProgramMap;
HandleAllocator mProgramShaderHandleAllocator;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
HandleAllocator mTextureHandleAllocator;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
HandleAllocator mRenderbufferHandleAllocator;
};
}
#endif // LIBGLESV2_RESOURCEMANAGER_H_
// 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.
//
// 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.
#ifndef LIBGLESV2_SHADER_H_
#define LIBGLESV2_SHADER_H_
#include "ResourceManager.h"
#include "compiler/TranslatorASM.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <list>
#include <vector>
namespace sh
{
class OutputASM;
}
namespace es2
{
struct Varying
{
Varying(GLenum type, const std::string &name, int arraySize, int reg = -1, int col = -1)
: type(type), name(name), arraySize(arraySize), reg(reg), col(col)
{
}
bool isArray() const
{
return arraySize >= 1;
}
int size() const // Unify with es2::Uniform?
{
return arraySize > 0 ? arraySize : 1;
}
GLenum type;
std::string name;
int arraySize;
int reg; // First varying register, assigned during link
int col; // First register element, assigned during link
};
typedef std::list<Varying> VaryingList;
class Shader
{
friend class Program;
friend class sh::OutputASM;
public:
Shader(ResourceManager *manager, GLuint handle);
virtual ~Shader();
virtual GLenum getType() = 0;
GLuint getHandle() const;
void deleteSource();
void setSource(GLsizei count, const char *const *string, const GLint *length);
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
int getSourceLength() const;
void getSource(GLsizei bufSize, GLsizei *length, char *source);
virtual void compile() = 0;
bool isCompiled();
virtual sw::Shader *getShader() const = 0;
virtual sw::PixelShader *getPixelShader() const;
virtual sw::VertexShader *getVertexShader() const;
void addRef();
void release();
unsigned int getRefCount() const;
bool isFlaggedForDeletion() const;
void flagForDeletion();
static void releaseCompiler();
protected:
static bool compilerInitialized;
TranslatorASM *createCompiler(ShShaderType type);
void clear();
static GLenum parseType(const std::string &type);
static bool compareVarying(const Varying &x, const Varying &y);
char *mSource;
char *mInfoLog;
VaryingList varyings;
sh::ActiveUniforms activeUniforms;
sh::ActiveAttributes activeAttributes;
private:
const GLuint mHandle;
unsigned int mRefCount; // Number of program objects this shader is attached to
bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
ResourceManager *mResourceManager;
};
class VertexShader : public Shader
{
friend class Program;
public:
VertexShader(ResourceManager *manager, GLuint handle);
~VertexShader();
virtual GLenum getType();
virtual void compile();
int getSemanticIndex(const std::string &attributeName);
virtual sw::Shader *getShader() const;
virtual sw::VertexShader *getVertexShader() const;
private:
sw::VertexShader *vertexShader;
};
class FragmentShader : public Shader
{
public:
FragmentShader(ResourceManager *manager, GLuint handle);
~FragmentShader();
virtual GLenum getType();
virtual void compile();
virtual sw::Shader *getShader() const;
virtual sw::PixelShader *getPixelShader() const;
private:
sw::PixelShader *pixelShader;
};
}
#endif // LIBGLESV2_SHADER_H_
// 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.
//
// 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.
#ifndef LIBGLESV2_TEXTURE_H_
#define LIBGLESV2_TEXTURE_H_
#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>
#include <vector>
namespace egl
{
class Surface;
class Config;
}
namespace es2
{
class Framebuffer;
enum
{
IMPLEMENTATION_MAX_TEXTURE_LEVELS = MIPMAP_LEVELS,
IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,
IMPLEMENTATION_MAX_SAMPLES = 4
};
class Texture : public egl::Texture
{
public:
explicit Texture(GLuint id);
virtual ~Texture();
sw::Resource *getResource() const;
virtual void addProxyRef(const Renderbuffer *proxy) = 0;
virtual void releaseProxy(const Renderbuffer *proxy) = 0;
virtual GLenum getTarget() const = 0;
bool setMinFilter(GLenum filter);
bool setMagFilter(GLenum filter);
bool setWrapS(GLenum wrap);
bool setWrapT(GLenum wrap);
bool setMaxAnisotropy(GLfloat textureMaxAnisotropy);
GLenum getMinFilter() const;
GLenum getMagFilter() const;
GLenum getWrapS() const;
GLenum getWrapT() const;
GLfloat getMaxAnisotropy() const;
virtual GLsizei getWidth(GLenum target, GLint level) const = 0;
virtual GLsizei getHeight(GLenum target, GLint level) const = 0;
virtual GLenum getFormat(GLenum target, GLint level) const = 0;
virtual GLenum getType(GLenum target, GLint level) const = 0;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const = 0;
virtual int getLevelCount() const = 0;
virtual bool isSamplerComplete() const = 0;
virtual bool isCompressed(GLenum target, GLint level) const = 0;
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 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);
bool copy(egl::Image *source, const sw::Rect &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, egl::Image *dest);
bool isMipmapFiltered() const;
GLenum mMinFilter;
GLenum mMagFilter;
GLenum mWrapS;
GLenum mWrapT;
GLfloat mMaxAnisotropy;
sw::Resource *resource;
};
class Texture2D : public Texture
{
public:
explicit Texture2D(GLuint id);
virtual ~Texture2D();
void addProxyRef(const Renderbuffer *proxy);
void releaseProxy(const Renderbuffer *proxy);
virtual GLenum getTarget() const;
virtual GLsizei getWidth(GLenum target, GLint level) const;
virtual GLsizei getHeight(GLenum target, GLint level) const;
virtual GLenum getFormat(GLenum target, GLint level) const;
virtual GLenum getType(GLenum target, GLint level) const;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const;
virtual int getLevelCount() const;
void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
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);
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;
egl::Image *getImage(unsigned int level);
protected:
bool isMipmapComplete() const;
egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
egl::Surface *mSurface;
// A specific internal reference count is kept for colorbuffer proxy references,
// because, as the renderbuffer acting as proxy will maintain a binding pointer
// back to this texture, there would be a circular reference if we used a binding
// pointer here. This reference count will cause the pointer to be set to NULL if
// the count drops to zero, but will not cause deletion of the Renderbuffer.
Renderbuffer *mColorbufferProxy;
unsigned int mProxyRefs;
};
class TextureCubeMap : public Texture
{
public:
explicit TextureCubeMap(GLuint id);
virtual ~TextureCubeMap();
void addProxyRef(const Renderbuffer *proxy);
void releaseProxy(const Renderbuffer *proxy);
virtual GLenum getTarget() const;
virtual GLsizei getWidth(GLenum target, GLint level) const;
virtual GLsizei getHeight(GLenum target, GLint level) const;
virtual GLenum getFormat(GLenum target, GLint level) const;
virtual GLenum getType(GLenum target, GLint level) const;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const;
virtual int getLevelCount() const;
void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
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);
private:
bool isCubeComplete() const;
bool isMipmapCubeComplete() const;
// face is one of the GL_TEXTURE_CUBE_MAP_* enumerants. Returns NULL on failure.
Image *getImage(GLenum face, unsigned int level);
Image *image[6][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
// back to this texture, there would be a circular reference if we used a binding
// pointer here. This reference count will cause the pointer to be set to NULL if
// the count drops to zero, but will not cause deletion of the Renderbuffer.
Renderbuffer *mFaceProxies[6];
unsigned int mFaceProxyRefs[6];
};
class TextureExternal : public Texture2D
{
public:
explicit TextureExternal(GLuint id);
virtual ~TextureExternal();
virtual GLenum getTarget() const;
};
}
#endif // LIBGLESV2_TEXTURE_H_
// 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.
//
// VertexDataManager.h: Defines the VertexDataManager, a class that
// runs the Buffer translation process.
#include "VertexDataManager.h"
#include "Buffer.h"
#include "Program.h"
#include "IndexDataManager.h"
#include "common/debug.h"
namespace
{
enum {INITIAL_STREAM_BUFFER_SIZE = 1024 * 1024};
}
namespace es2
{
VertexDataManager::VertexDataManager(Context *context) : mContext(context)
{
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
mDirtyCurrentValue[i] = true;
mCurrentValueBuffer[i] = NULL;
}
mStreamingBuffer = new StreamingVertexBuffer(INITIAL_STREAM_BUFFER_SIZE);
if(!mStreamingBuffer)
{
ERR("Failed to allocate the streaming vertex buffer.");
}
}
VertexDataManager::~VertexDataManager()
{
delete mStreamingBuffer;
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
delete mCurrentValueBuffer[i];
}
}
unsigned int VertexDataManager::writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute)
{
Buffer *buffer = attribute.mBoundBuffer.get();
int inputStride = attribute.stride();
int elementSize = attribute.typeSize();
unsigned int streamOffset = 0;
char *output = NULL;
if(vertexBuffer)
{
output = (char*)vertexBuffer->map(attribute, attribute.typeSize() * count, &streamOffset);
}
if(output == NULL)
{
ERR("Failed to map vertex buffer.");
return -1;
}
const char *input = NULL;
if(buffer)
{
int offset = attribute.mOffset;
input = static_cast<const char*>(buffer->data()) + offset;
}
else
{
input = static_cast<const char*>(attribute.mPointer);
}
input += inputStride * start;
if(inputStride == elementSize)
{
memcpy(output, input, count * inputStride);
}
else
{
for(int i = 0; i < count; i++)
{
memcpy(output, input, elementSize);
output += elementSize;
input += inputStride;
}
}
vertexBuffer->unmap();
return streamOffset;
}
GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *translated)
{
if(!mStreamingBuffer)
{
return GL_OUT_OF_MEMORY;
}
const VertexAttributeArray &attribs = mContext->getVertexAttributes();
Program *program = mContext->getCurrentProgram();
// 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(!attribs[i].mBoundBuffer)
{
mStreamingBuffer->addRequiredSpace(attribs[i].typeSize() * count);
}
}
}
mStreamingBuffer->reserveRequiredSpace();
// Perform the vertex data translations
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
if(program->getAttributeStream(i) != -1)
{
if(attribs[i].mArrayEnabled)
{
Buffer *buffer = attribs[i].mBoundBuffer.get();
if(!buffer && attribs[i].mPointer == NULL)
{
// This is an application error that would normally result in a crash, but we catch it and return an error
ERR("An enabled vertex array has no buffer and no pointer.");
return GL_INVALID_OPERATION;
}
sw::Resource *staticBuffer = buffer ? buffer->getResource() : NULL;
if(staticBuffer)
{
translated[i].vertexBuffer = staticBuffer;
translated[i].offset = start * attribs[i].stride() + attribs[i].mOffset;
translated[i].stride = attribs[i].stride();
}
else
{
unsigned int streamOffset = writeAttributeData(mStreamingBuffer, start, count, attribs[i]);
if(streamOffset == -1)
{
return GL_OUT_OF_MEMORY;
}
translated[i].vertexBuffer = mStreamingBuffer->getResource();
translated[i].offset = streamOffset;
translated[i].stride = attribs[i].typeSize();
}
switch(attribs[i].mType)
{
case GL_BYTE: translated[i].type = sw::STREAMTYPE_SBYTE; break;
case GL_UNSIGNED_BYTE: translated[i].type = sw::STREAMTYPE_BYTE; break;
case GL_SHORT: translated[i].type = sw::STREAMTYPE_SHORT; break;
case GL_UNSIGNED_SHORT: translated[i].type = sw::STREAMTYPE_USHORT; break;
case GL_FIXED: translated[i].type = sw::STREAMTYPE_FIXED; break;
case GL_FLOAT: translated[i].type = sw::STREAMTYPE_FLOAT; break;
default: UNREACHABLE(); translated[i].type = sw::STREAMTYPE_FLOAT; break;
}
translated[i].count = attribs[i].mSize;
translated[i].normalized = attribs[i].mNormalized;
}
else
{
if(mDirtyCurrentValue[i])
{
delete mCurrentValueBuffer[i];
mCurrentValueBuffer[i] = new ConstantVertexBuffer(attribs[i].mCurrentValue[0], attribs[i].mCurrentValue[1], attribs[i].mCurrentValue[2], attribs[i].mCurrentValue[3]);
mDirtyCurrentValue[i] = false;
}
translated[i].vertexBuffer = mCurrentValueBuffer[i]->getResource();
translated[i].type = sw::STREAMTYPE_FLOAT;
translated[i].count = 4;
translated[i].stride = 0;
translated[i].offset = 0;
}
}
}
return GL_NO_ERROR;
}
VertexBuffer::VertexBuffer(unsigned int size) : mVertexBuffer(NULL)
{
if(size > 0)
{
mVertexBuffer = new sw::Resource(size + 1024);
if(!mVertexBuffer)
{
ERR("Out of memory allocating a vertex buffer of size %lu.", size);
}
}
}
VertexBuffer::~VertexBuffer()
{
if(mVertexBuffer)
{
mVertexBuffer->destruct();
}
}
void VertexBuffer::unmap()
{
if(mVertexBuffer)
{
mVertexBuffer->unlock();
}
}
sw::Resource *VertexBuffer::getResource() const
{
return mVertexBuffer;
}
ConstantVertexBuffer::ConstantVertexBuffer(float x, float y, float z, float w) : VertexBuffer(4 * sizeof(float))
{
if(mVertexBuffer)
{
float *vector = (float*)mVertexBuffer->lock(sw::PUBLIC);
vector[0] = x;
vector[1] = y;
vector[2] = z;
vector[3] = w;
mVertexBuffer->unlock();
}
}
ConstantVertexBuffer::~ConstantVertexBuffer()
{
}
StreamingVertexBuffer::StreamingVertexBuffer(unsigned int size) : VertexBuffer(size)
{
mBufferSize = size;
mWritePosition = 0;
mRequiredSpace = 0;
}
StreamingVertexBuffer::~StreamingVertexBuffer()
{
}
void StreamingVertexBuffer::addRequiredSpace(unsigned int requiredSpace)
{
mRequiredSpace += requiredSpace;
}
void *StreamingVertexBuffer::map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *offset)
{
void *mapPtr = NULL;
if(mVertexBuffer)
{
mapPtr = (char*)mVertexBuffer->lock(sw::PUBLIC) + mWritePosition;
if(!mapPtr)
{
ERR("Lock failed");
return NULL;
}
*offset = mWritePosition;
mWritePosition += requiredSpace;
}
return mapPtr;
}
void StreamingVertexBuffer::reserveRequiredSpace()
{
if(mRequiredSpace > mBufferSize)
{
if(mVertexBuffer)
{
mVertexBuffer->destruct();
mVertexBuffer = 0;
}
mBufferSize = std::max(mRequiredSpace, 3 * mBufferSize / 2); // 1.5 x mBufferSize is arbitrary and should be checked to see we don't have too many reallocations.
mVertexBuffer = new sw::Resource(mBufferSize);
if(!mVertexBuffer)
{
ERR("Out of memory allocating a vertex buffer of size %lu.", mBufferSize);
}
mWritePosition = 0;
}
else if(mWritePosition + mRequiredSpace > mBufferSize) // Recycle
{
if(mVertexBuffer)
{
mVertexBuffer->destruct();
mVertexBuffer = new sw::Resource(mBufferSize);
}
mWritePosition = 0;
}
mRequiredSpace = 0;
}
}
// 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.
//
// VertexDataManager.h: Defines the VertexDataManager, a class that
// runs the Buffer translation process.
#ifndef LIBGLESV2_VERTEXDATAMANAGER_H_
#define LIBGLESV2_VERTEXDATAMANAGER_H_
#include "Context.h"
#include "Device.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
namespace es2
{
struct TranslatedAttribute
{
sw::StreamType type;
int count;
bool normalized;
unsigned int offset;
unsigned int stride; // 0 means not to advance the read pointer at all
sw::Resource *vertexBuffer;
};
class VertexBuffer
{
public:
VertexBuffer(unsigned int size);
virtual ~VertexBuffer();
void unmap();
sw::Resource *getResource() const;
protected:
sw::Resource *mVertexBuffer;
};
class ConstantVertexBuffer : public VertexBuffer
{
public:
ConstantVertexBuffer(float x, float y, float z, float w);
~ConstantVertexBuffer();
};
class StreamingVertexBuffer : public VertexBuffer
{
public:
StreamingVertexBuffer(unsigned int size);
~StreamingVertexBuffer();
void *map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *streamOffset);
void reserveRequiredSpace();
void addRequiredSpace(unsigned int requiredSpace);
protected:
unsigned int mBufferSize;
unsigned int mWritePosition;
unsigned int mRequiredSpace;
};
class VertexDataManager
{
public:
VertexDataManager(Context *context);
virtual ~VertexDataManager();
void dirtyCurrentValue(int index) { mDirtyCurrentValue[index] = true; }
GLenum prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *outAttribs);
private:
unsigned int writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute);
Context *const mContext;
StreamingVertexBuffer *mStreamingBuffer;
bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS];
ConstantVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS];
};
}
#endif // LIBGLESV2_VERTEXDATAMANAGER_H_
{
global:
glActiveTexture;
glAttachShader;
glBindAttribLocation;
glBindBuffer;
glBindFramebuffer;
glBindRenderbuffer;
glBindTexture;
glBlendColor;
glBlendEquation;
glBlendEquationSeparate;
glBlendFunc;
glBlendFuncSeparate;
glBufferData;
glBufferSubData;
glCheckFramebufferStatus;
glClear;
glClearColor;
glClearDepthf;
glClearStencil;
glColorMask;
glCompileShader;
glCompressedTexImage2D;
glCompressedTexSubImage2D;
glCopyTexImage2D;
glCopyTexSubImage2D;
glCreateProgram;
glCreateShader;
glCullFace;
glDeleteBuffers;
glDeleteFramebuffers;
glDeleteProgram;
glDeleteRenderbuffers;
glDeleteShader;
glDeleteTextures;
glDepthFunc;
glDepthMask;
glDepthRangef;
glDetachShader;
glDisable;
glDisableVertexAttribArray;
glDrawArrays;
glDrawElements;
glEnable;
glEnableVertexAttribArray;
glFinish;
glFlush;
glFramebufferRenderbuffer;
glFramebufferTexture2D;
glFrontFace;
glGenBuffers;
glGenFramebuffers;
glGenRenderbuffers;
glGenTextures;
glGenerateMipmap;
glGetActiveAttrib;
glGetActiveUniform;
glGetAttachedShaders;
glGetAttribLocation;
glGetBooleanv;
glGetBufferParameteriv;
glGetError;
glGetFloatv;
glGetFramebufferAttachmentParameteriv;
glGetIntegerv;
glGetProgramInfoLog;
glGetProgramiv;
glGetRenderbufferParameteriv;
glGetShaderInfoLog;
glGetShaderPrecisionFormat;
glGetShaderSource;
glGetShaderiv;
glGetString;
glGetTexParameterfv;
glGetTexParameteriv;
glGetUniformLocation;
glGetUniformfv;
glGetUniformiv;
glGetVertexAttribPointerv;
glGetVertexAttribfv;
glGetVertexAttribiv;
glHint;
glIsBuffer;
glIsEnabled;
glIsFramebuffer;
glIsProgram;
glIsRenderbuffer;
glIsShader;
glIsTexture;
glLineWidth;
glLinkProgram;
glPixelStorei;
glPolygonOffset;
glReadPixels;
glReleaseShaderCompiler;
glRenderbufferStorage;
glSampleCoverage;
glScissor;
glShaderBinary;
glShaderSource;
glStencilFunc;
glStencilFuncSeparate;
glStencilMask;
glStencilMaskSeparate;
glStencilOp;
glStencilOpSeparate;
glTexImage2D;
glTexParameterf;
glTexParameterfv;
glTexParameteri;
glTexParameteriv;
glTexSubImage2D;
glUniform1f;
glUniform1fv;
glUniform1i;
glUniform1iv;
glUniform2f;
glUniform2fv;
glUniform2i;
glUniform2iv;
glUniform3f;
glUniform3fv;
glUniform3i;
glUniform3iv;
glUniform4f;
glUniform4fv;
glUniform4i;
glUniform4iv;
glUniformMatrix2fv;
glUniformMatrix3fv;
glUniformMatrix4fv;
glUseProgram;
glValidateProgram;
glVertexAttrib1f;
glVertexAttrib1fv;
glVertexAttrib2f;
glVertexAttrib2fv;
glVertexAttrib3f;
glVertexAttrib3fv;
glVertexAttrib4f;
glVertexAttrib4fv;
glVertexAttribPointer;
glViewport;
# Extensions
glTexImage3DOES;
glBlitFramebufferANGLE;
glRenderbufferStorageMultisampleANGLE;
glDeleteFencesNV;
glFinishFenceNV;
glGenFencesNV;
glGetFenceivNV;
glIsFenceNV;
glSetFenceNV;
glTestFenceNV;
glGetGraphicsResetStatusEXT;
glReadnPixelsEXT;
glGetnUniformfvEXT;
glGetnUniformivEXT;
glGenQueriesEXT;
glDeleteQueriesEXT;
glIsQueryEXT;
glBeginQueryEXT;
glEndQueryEXT;
glGetQueryivEXT;
glGetQueryObjectuivEXT;
glEGLImageTargetTexture2DOES;
glEGLImageTargetRenderbufferStorageOES;
# EGL dependencies
glCreateContext;
glGetProcAddress;
createFrameBuffer;
createBackBuffer;
createDepthStencil;
Register;
local:
*;
};
This source diff could not be displayed because it is too large. You can view the blob instead.
LIBRARY libGLESv2
EXPORTS
glActiveTexture @1
glAttachShader @2
glBindAttribLocation @3
glBindBuffer @4
glBindFramebuffer @5
glBindRenderbuffer @6
glBindTexture @7
glBlendColor @8
glBlendEquation @9
glBlendEquationSeparate @10
glBlendFunc @11
glBlendFuncSeparate @12
glBufferData @13
glBufferSubData @14
glCheckFramebufferStatus @15
glClear @16
glClearColor @17
glClearDepthf @18
glClearStencil @19
glColorMask @20
glCompileShader @21
glCompressedTexImage2D @22
glCompressedTexSubImage2D @23
glCopyTexImage2D @24
glCopyTexSubImage2D @25
glCreateProgram @26
glCreateShader @27
glCullFace @28
glDeleteBuffers @29
glDeleteFramebuffers @30
glDeleteProgram @32
glDeleteRenderbuffers @33
glDeleteShader @34
glDeleteTextures @31
glDepthFunc @36
glDepthMask @37
glDepthRangef @38
glDetachShader @35
glDisable @39
glDisableVertexAttribArray @40
glDrawArrays @41
glDrawElements @42
glEnable @43
glEnableVertexAttribArray @44
glFinish @45
glFlush @46
glFramebufferRenderbuffer @47
glFramebufferTexture2D @48
glFrontFace @49
glGenBuffers @50
glGenFramebuffers @52
glGenRenderbuffers @53
glGenTextures @54
glGenerateMipmap @51
glGetActiveAttrib @55
glGetActiveUniform @56
glGetAttachedShaders @57
glGetAttribLocation @58
glGetBooleanv @59
glGetBufferParameteriv @60
glGetError @61
glGetFloatv @62
glGetFramebufferAttachmentParameteriv @63
glGetIntegerv @64
glGetProgramInfoLog @66
glGetProgramiv @65
glGetRenderbufferParameteriv @67
glGetShaderInfoLog @69
glGetShaderPrecisionFormat @70
glGetShaderSource @71
glGetShaderiv @68
glGetString @72
glGetTexParameterfv @73
glGetTexParameteriv @74
glGetUniformLocation @77
glGetUniformfv @75
glGetUniformiv @76
glGetVertexAttribPointerv @80
glGetVertexAttribfv @78
glGetVertexAttribiv @79
glHint @81
glIsBuffer @82
glIsEnabled @83
glIsFramebuffer @84
glIsProgram @85
glIsRenderbuffer @86
glIsShader @87
glIsTexture @88
glLineWidth @89
glLinkProgram @90
glPixelStorei @91
glPolygonOffset @92
glReadPixels @93
glReleaseShaderCompiler @94
glRenderbufferStorage @95
glSampleCoverage @96
glScissor @97
glShaderBinary @98
glShaderSource @99
glStencilFunc @100
glStencilFuncSeparate @101
glStencilMask @102
glStencilMaskSeparate @103
glStencilOp @104
glStencilOpSeparate @105
glTexImage2D @106
glTexParameterf @107
glTexParameterfv @108
glTexParameteri @109
glTexParameteriv @110
glTexSubImage2D @111
glUniform1f @112
glUniform1fv @113
glUniform1i @114
glUniform1iv @115
glUniform2f @116
glUniform2fv @117
glUniform2i @118
glUniform2iv @119
glUniform3f @120
glUniform3fv @121
glUniform3i @122
glUniform3iv @123
glUniform4f @124
glUniform4fv @125
glUniform4i @126
glUniform4iv @127
glUniformMatrix2fv @128
glUniformMatrix3fv @129
glUniformMatrix4fv @130
glUseProgram @131
glValidateProgram @132
glVertexAttrib1f @133
glVertexAttrib1fv @134
glVertexAttrib2f @135
glVertexAttrib2fv @136
glVertexAttrib3f @137
glVertexAttrib3fv @138
glVertexAttrib4f @139
glVertexAttrib4fv @140
glVertexAttribPointer @141
glViewport @142
; Extensions
glTexImage3DOES @143
glBlitFramebufferANGLE @149
glRenderbufferStorageMultisampleANGLE @150
glDeleteFencesNV @151
glFinishFenceNV @152
glGenFencesNV @153
glGetFenceivNV @154
glIsFenceNV @155
glSetFenceNV @156
glTestFenceNV @157
glGetGraphicsResetStatusEXT @161
glReadnPixelsEXT @162
glGetnUniformfvEXT @163
glGetnUniformivEXT @164
glGenQueriesEXT @165
glDeleteQueriesEXT @166
glIsQueryEXT @167
glBeginQueryEXT @168
glEndQueryEXT @169
glGetQueryivEXT @170
glGetQueryObjectuivEXT @171
glEGLImageTargetTexture2DOES
glEGLImageTargetRenderbufferStorageOES
; EGL dependencies
glCreateContext
glGetProcAddress
createFrameBuffer
createBackBuffer
createDepthStencil
Register
\ No newline at end of file
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include "../../common/Version.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) 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
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""../common/version.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
PRODUCTVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "SwiftShader libGLESv2 Dynamic Link Library"
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "libGLESv2"
VALUE "LegalCopyright", "Copyright (C) 2012 TransGaming Inc."
VALUE "OriginalFilename", "libGLESv2.dll"
VALUE "PrivateBuild", VERSION_STRING
VALUE "ProductName", "SwiftShader libGLESv2 Dynamic Link Library"
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Buffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Context.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\debug.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Fence.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Framebuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HandleAllocator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IndexDataManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libGLESv2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Program.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Renderbuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ResourceManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Shader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Texture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utilities.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="VertexDataManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Device.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Image.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Query.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\common\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Buffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Context.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Fence.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Framebuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HandleAllocator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IndexDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="main.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="mathutil.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Program.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Renderbuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ResourceManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Shader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Texture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utilities.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VertexDataManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Device.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Image.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES2\gl2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES2\gl2ext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES2\gl2platform.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Query.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\debug.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\Object.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libGLESv2.rc" />
</ItemGroup>
<ItemGroup>
<None Include="libGLESv2.def" />
</ItemGroup>
</Project>
\ No newline at end of file
// 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.
//
// main.cpp: DLL entry point and management of thread-local data.
#include "main.h"
#include "Framebuffer.h"
#include "libEGL/Surface.h"
#include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
#include "common/debug.h"
#if !defined(_MSC_VER)
#define CONSTRUCTOR __attribute__((constructor))
#define DESTRUCTOR __attribute__((destructor))
#else
#define CONSTRUCTOR
#define DESTRUCTOR
#endif
static void glAttachThread()
{
TRACE("()");
}
static void glDetachThread()
{
TRACE("()");
}
CONSTRUCTOR static bool glAttachProcess()
{
TRACE("()");
glAttachThread();
#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"};
#endif
libEGL = loadLibrary(libEGL_lib);
egl::getCurrentContext = (egl::Context *(*)())getProcAddress(libEGL, "clientGetCurrentContext");
egl::getCurrentDisplay = (egl::Display *(*)())getProcAddress(libEGL, "clientGetCurrentDisplay");
#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
libGLES_CM = loadLibrary(libGLES_CM_lib);
es1::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLES_CM, "glGetProcAddress");
return libEGL != 0;
}
DESTRUCTOR static void glDetachProcess()
{
TRACE("()");
glDetachThread();
freeLibrary(libEGL);
freeLibrary(libGLES_CM);
}
#if defined(_WIN32)
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
return glAttachProcess();
break;
case DLL_THREAD_ATTACH:
glAttachThread();
break;
case DLL_THREAD_DETACH:
glDetachThread();
break;
case DLL_PROCESS_DETACH:
glDetachProcess();
break;
default:
break;
}
return TRUE;
}
#endif
namespace es2
{
es2::Context *getContext()
{
egl::Context *context = egl::getCurrentContext();
if(context && context->getClientVersion() == 2)
{
return static_cast<es2::Context*>(context);
}
return 0;
}
egl::Display *getDisplay()
{
return egl::getCurrentDisplay();
}
Device *getDevice()
{
Context *context = getContext();
return context ? context->getDevice() : 0;
}
}
namespace egl
{
GLint getClientVersion()
{
Context *context = egl::getCurrentContext();
return context ? context->getClientVersion() : 0;
}
}
// Records an error code
void error(GLenum errorCode)
{
es2::Context *context = es2::getContext();
if(context)
{
switch(errorCode)
{
case GL_INVALID_ENUM:
context->recordInvalidEnum();
TRACE("\t! Error generated: invalid enum\n");
break;
case GL_INVALID_VALUE:
context->recordInvalidValue();
TRACE("\t! Error generated: invalid value\n");
break;
case GL_INVALID_OPERATION:
context->recordInvalidOperation();
TRACE("\t! Error generated: invalid operation\n");
break;
case GL_OUT_OF_MEMORY:
context->recordOutOfMemory();
TRACE("\t! Error generated: out of memory\n");
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
context->recordInvalidFramebufferOperation();
TRACE("\t! Error generated: invalid framebuffer operation\n");
break;
default: UNREACHABLE();
}
}
}
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
// 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.
//
// main.h: Management of thread-local data.
#ifndef LIBGLESV2_MAIN_H_
#define LIBGLESV2_MAIN_H_
#include "Context.h"
#include "Device.hpp"
#include "common/debug.h"
#include "libEGL/Display.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
namespace es2
{
Context *getContext();
egl::Display *getDisplay();
Device *getDevice();
}
namespace egl
{
GLint getClientVersion();
}
void error(GLenum errorCode);
template<class T>
const T &error(GLenum errorCode, const T &returnValue)
{
error(errorCode);
return returnValue;
}
// libEGL dependencies
namespace egl
{
extern egl::Context *(*getCurrentContext)();
extern egl::Display *(*getCurrentDisplay)();
}
// libGLES_CM dependencies
namespace es1
{
extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname);
}
extern void *libEGL; // Handle to the libEGL module
extern void *libGLES_CM; // Handle to the libGLES_CM module
#endif // LIBGLESV2_MAIN_H_
// 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.
//
// mathutil.h: Math and bit manipulation functions.
#ifndef LIBGLESV2_MATHUTIL_H_
#define LIBGLESV2_MATHUTIL_H_
#include "common/debug.h"
#include <math.h>
namespace es2
{
inline bool isPow2(int x)
{
return (x & (x - 1)) == 0 && (x != 0);
}
inline int log2(int x)
{
int r = 0;
while((x >> r) > 1) r++;
return r;
}
inline unsigned int ceilPow2(unsigned int x)
{
if(x != 0) x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
return x;
}
template<typename T, typename MIN, typename MAX>
inline T clamp(T x, MIN min, MAX max)
{
return x < min ? min : (x > max ? max : x);
}
inline float clamp01(float x)
{
return clamp(x, 0.0f, 1.0f);
}
template<const int n>
inline unsigned int unorm(float x)
{
const unsigned int max = 0xFFFFFFFF >> (32 - n);
if(x > 1)
{
return max;
}
else if(x < 0)
{
return 0;
}
else
{
return (unsigned int)(max * x + 0.5f);
}
}
}
#endif // LIBGLESV2_MATHUTIL_H_
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by libGLESv2.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
// 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.
//
// utilities.h: Conversion functions and other utility routines.
#ifndef LIBGLESV2_UTILITIES_H
#define LIBGLESV2_UTILITIES_H
#include "Device.hpp"
#include "Image.hpp"
#include "Texture.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <string>
namespace es2
{
struct Color;
int UniformComponentCount(GLenum type);
GLenum UniformComponentType(GLenum type);
size_t UniformTypeSize(GLenum type);
int VariableRowCount(GLenum type);
int VariableColumnCount(GLenum type);
int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);
int ComputePixelSize(GLenum format, GLenum type);
GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);
GLsizei ComputeCompressedPitch(GLsizei width, GLenum format);
GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);
bool IsCompressed(GLenum format);
bool IsDepthTexture(GLenum format);
bool IsStencilTexture(GLenum format);
bool IsCubemapTextureTarget(GLenum target);
int CubeFaceIndex(GLenum cubeTarget);
bool IsTextureTarget(GLenum target);
bool CheckTextureFormatType(GLenum format, GLenum type);
bool IsColorRenderable(GLenum internalformat);
bool IsDepthRenderable(GLenum internalformat);
bool IsStencilRenderable(GLenum internalformat);
}
namespace es2sw
{
sw::DepthCompareMode ConvertDepthComparison(GLenum comparison);
sw::StencilCompareMode ConvertStencilComparison(GLenum comparison);
sw::Color<float> ConvertColor(es2::Color color);
sw::BlendFactor ConvertBlendFunc(GLenum blend);
sw::BlendOperation ConvertBlendOp(GLenum blendOp);
sw::StencilOperation ConvertStencilOp(GLenum stencilOp);
sw::AddressingMode ConvertTextureWrap(GLenum wrap);
sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace);
unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha);
sw::FilterType ConvertMagFilter(GLenum magFilter);
void ConvertMinFilter(GLenum texFilter, sw::FilterType *minFilter, sw::MipmapType *mipFilter, float maxAnisotropy);
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, es2::PrimitiveType &swPrimitiveType, int &primitiveCount);
sw::Format ConvertRenderbufferFormat(GLenum format);
}
namespace sw2es
{
GLuint GetAlphaSize(sw::Format colorFormat);
GLuint GetRedSize(sw::Format colorFormat);
GLuint GetGreenSize(sw::Format colorFormat);
GLuint GetBlueSize(sw::Format colorFormat);
GLuint GetDepthSize(sw::Format depthFormat);
GLuint GetStencilSize(sw::Format stencilFormat);
GLenum ConvertBackBufferFormat(sw::Format format);
GLenum ConvertDepthStencilFormat(sw::Format format);
}
#endif // LIBGLESV2_UTILITIES_H
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