Commit f97ae8b4 by Nicolas Capens Committed by Nicolas Capens

Remove libGLES_CM and rename libGLESv2 to libRAD.

BUG=18218488 Change-Id: I790ed12fb4e2e38196fb88e2bc17a43ef8bfadbb Reviewed-on: https://swiftshader-review.googlesource.com/1322Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 103896ba
// 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 es1
{
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->getBuffer(), 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 LIBGLES_CM_BUFFER_H_
#define LIBGLES_CM_BUFFER_H_
#include "RefCountObject.h"
#include "Common/Resource.hpp"
#define GL_API
#include <GLES/gl.h>
#include <cstddef>
#include <vector>
namespace es1
{
class Buffer : public 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->getBuffer() : 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 // LIBGLES_CM_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 es1
{
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 setScissorEnable(bool enable);
virtual void setRenderTarget(egl::Image *renderTarget);
virtual void setScissorRect(const sw::Rect &rect);
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();
bool bindViewport(); // Also adjusts for scissoring
bool validRectangle(const sw::Rect *rect, egl::Image *surface);
Viewport viewport;
sw::Rect scissorRect;
bool scissorEnable;
egl::Image *renderTarget;
egl::Image *depthStencil;
};
}
#endif // gl_Device_hpp
// 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 LIBGLES_CM_FRAMEBUFFER_H_
#define LIBGLES_CM_FRAMEBUFFER_H_
#include "RefCountObject.h"
#include "Image.hpp"
#define GL_API
#include <GLES/gl.h>
namespace es1
{
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;
BindingPointer<Renderbuffer> mColorbufferPointer;
GLenum mDepthbufferType;
BindingPointer<Renderbuffer> mDepthbufferPointer;
GLenum mStencilbufferType;
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 // LIBGLES_CM_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 es1
{
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 LIBGLES_CM_HANDLEALLOCATOR_H_
#define LIBGLES_CM_HANDLEALLOCATOR_H_
#define GL_API
#include <GLES/gl.h>
#include <vector>
namespace es1
{
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 // LIBGLES_CM_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_API
#include <GLES/gl.h>
namespace es1
{
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();
void unbind(); // 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 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 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 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 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 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);
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 es1
{
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_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_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;
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_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 LIBGLES_CM_INDEXDATAMANAGER_H_
#define LIBGLES_CM_INDEXDATAMANAGER_H_
#include "Context.h"
#define GL_API
#include <GLES/gl.h>
namespace es1
{
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 // LIBGLES_CM_INDEXDATAMANAGER_H_
#include "MatrixStack.hpp"
#include "Common/Math.hpp"
namespace sw
{
MatrixStack::MatrixStack(int size)
{
stack = new Matrix[size];
stack[0] = 1;
top = 0;
this->size = size;
}
MatrixStack::~MatrixStack()
{
delete[] stack;
stack = 0;
}
void MatrixStack::identity()
{
stack[top] = 1;
}
void MatrixStack::load(const float *M)
{
stack[top] = Matrix(M[0], M[4], M[8], M[12],
M[1], M[5], M[9], M[13],
M[2], M[6], M[10], M[14],
M[3], M[7], M[11], M[15]);
}
void MatrixStack::load(const double *M)
{
stack[top] = Matrix((float)M[0], (float)M[4], (float)M[8], (float)M[12],
(float)M[1], (float)M[5], (float)M[9], (float)M[13],
(float)M[2], (float)M[6], (float)M[10], (float)M[14],
(float)M[3], (float)M[7], (float)M[11], (float)M[15]);
}
void MatrixStack::translate(float x, float y, float z)
{
stack[top] *= Matrix::translate(x, y, z);
}
void MatrixStack::translate(double x, double y, double z)
{
translate((float)x, (float)y, (float)z);
}
void MatrixStack::rotate(float angle, float x, float y, float z)
{
float n = 1.0f / sqrt(x*x + y*y + z*z);
x *= n;
y *= n;
z *= n;
float theta = angle * 0.0174532925f; // In radians
float c = cos(theta);
float _c = 1 - c;
float s = sin(theta);
// Rodrigues' rotation formula
sw::Matrix rotate(c+x*x*_c, x*y*_c-z*s, x*z*_c+y*s,
x*y*_c+z*s, c+y*y*_c, y*z*_c-x*s,
x*z*_c-y*s, y*z*_c+x*s, c+z*z*_c);
stack[top] *= rotate;
}
void MatrixStack::rotate(double angle, double x, double y, double z)
{
rotate((float)angle, (float)x, (float)y, (float)z);
}
void MatrixStack::scale(float x, float y, float z)
{
stack[top] *= Matrix::scale(x, y, z);
}
void MatrixStack::scale(double x, double y, double z)
{
scale((float)x, (float)y, (float)z);
}
void MatrixStack::multiply(const float *M)
{
stack[top] *= Matrix(M[0], M[4], M[8], M[12],
M[1], M[5], M[9], M[13],
M[2], M[6], M[10], M[14],
M[3], M[7], M[11], M[15]);
}
void MatrixStack::multiply(const double *M)
{
stack[top] *= Matrix((float)M[0], (float)M[4], (float)M[8], (float)M[12],
(float)M[1], (float)M[5], (float)M[9], (float)M[13],
(float)M[2], (float)M[6], (float)M[10], (float)M[14],
(float)M[3], (float)M[7], (float)M[11], (float)M[15]);
}
void MatrixStack::frustum(float left, float right, float bottom, float top, float zNear, float zFar)
{
float l = (float)left;
float r = (float)right;
float b = (float)bottom;
float t = (float)top;
float n = (float)zNear;
float f = (float)zFar;
float A = (r + l) / (r - l);
float B = (t + b) / (t - b);
float C = -(f + n) / (r - n);
float D = -2 * r * n / (f - n);
Matrix frustum(2 * n / (r - l), 0, A, 0,
0, 2 * n / (t - b), B, 0,
0, 0, C, D,
0, 0, -1, 0);
stack[this->top] *= frustum;
}
void MatrixStack::ortho(double left, double right, double bottom, double top, double zNear, double zFar)
{
float l = (float)left;
float r = (float)right;
float b = (float)bottom;
float t = (float)top;
float n = (float)zNear;
float f = (float)zFar;
float tx = -(r + l) / (r - l);
float ty = -(t + b) / (t - b);
float tz = -(f + n) / (f - n);
Matrix ortho(2 / (r - l), 0, 0, tx,
0, 2 / (t - b), 0, ty,
0, 0, -2 / (f - n), tz,
0, 0, 0, 1);
stack[this->top] *= ortho;
}
bool MatrixStack::push()
{
if(top >= size - 1) return false;
stack[top + 1] = stack[top];
top++;
return true;
}
bool MatrixStack::pop()
{
if(top <= 0) return false;
top--;
return true;
}
const Matrix &MatrixStack::current()
{
return stack[top];
}
bool MatrixStack::isIdentity() const
{
const Matrix &m = stack[top];
if(m.m[0][0] != 1.0f) return false;
if(m.m[0][1] != 0.0f) return false;
if(m.m[0][2] != 0.0f) return false;
if(m.m[0][3] != 0.0f) return false;
if(m.m[1][0] != 0.0f) return false;
if(m.m[1][1] != 1.0f) return false;
if(m.m[1][2] != 0.0f) return false;
if(m.m[1][3] != 0.0f) return false;
if(m.m[2][0] != 0.0f) return false;
if(m.m[2][1] != 0.0f) return false;
if(m.m[2][2] != 1.0f) return false;
if(m.m[2][3] != 0.0f) return false;
if(m.m[3][0] != 0.0f) return false;
if(m.m[3][1] != 0.0f) return false;
if(m.m[3][2] != 0.0f) return false;
if(m.m[3][3] != 1.0f) return false;
return true;
}
}
#ifndef OpenGL32_MatrixStack_hpp
#define OpenGL32_MatrixStack_hpp
#include "Renderer/Matrix.hpp"
namespace sw
{
class MatrixStack
{
public:
MatrixStack(int size = 2);
~MatrixStack();
void identity();
void load(const float *M);
void load(const double *M);
void translate(float x, float y, float z);
void translate(double x, double y, double z);
void rotate(float angle, float x, float y, float z);
void rotate(double angle, double x, double y, double z);
void scale(float x, float y, float z);
void scale(double x, double y, double z);
void multiply(const float *M);
void multiply(const double *M);
void frustum(float left, float right, float bottom, float top, float zNear, float zFar);
void ortho(double left, double right, double bottom, double top, double zNear, double zFar);
bool push(); // False on overflow
bool pop(); // False on underflow
const Matrix &current();
bool isIdentity() const;
private:
int top;
int size;
Matrix *stack;
};
}
#endif // OpenGL32_MatrixStack_hpp
// 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.
//
// RefCountObject.cpp: Defines the RefCountObject base class that provides
// lifecycle support for GL objects using the traditional BindObject scheme, but
// that need to be reference counted for correct cross-context deletion.
// (Concretely, textures, buffers and renderbuffers.)
#include "RefCountObject.h"
#include "Common/Thread.hpp"
namespace es1
{
RefCountObject::RefCountObject(GLuint id)
{
mId = id;
referenceCount = 0;
}
RefCountObject::~RefCountObject()
{
ASSERT(referenceCount == 0);
}
void RefCountObject::addRef()
{
sw::atomicIncrement(&referenceCount);
}
void RefCountObject::release()
{
ASSERT(referenceCount > 0);
if(referenceCount > 0)
{
sw::atomicDecrement(&referenceCount);
}
if(referenceCount == 0)
{
delete this;
}
}
void RefCountObjectBindingPointer::set(RefCountObject *newObject)
{
// addRef first in case newObject == mObject and this is the last reference to it.
if(newObject != NULL) newObject->addRef();
if(mObject != NULL) mObject->release();
mObject = newObject;
}
}
// 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.
//
// RefCountObject.h: Defines the RefCountObject base class that provides
// lifecycle support for GL objects using the traditional BindObject scheme, but
// that need to be reference counted for correct cross-context deletion.
// (Concretely, textures, buffers and renderbuffers.)
#ifndef LIBGLES_CM_REFCOUNTOBJECT_H_
#define LIBGLES_CM_REFCOUNTOBJECT_H_
#include "common/debug.h"
#define GL_APIL
#include <GLES/gl.h>
#include <cstddef>
namespace es1
{
class RefCountObject
{
public:
explicit RefCountObject(GLuint id);
virtual ~RefCountObject();
virtual void addRef();
virtual void release();
GLuint id() const {return mId;}
private:
GLuint mId;
volatile int referenceCount;
};
class RefCountObjectBindingPointer
{
protected:
RefCountObjectBindingPointer() : mObject(NULL) { }
~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up.
void set(RefCountObject *newObject);
RefCountObject *get() const { return mObject; }
public:
GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; }
bool operator ! () const { return (get() == NULL); }
private:
RefCountObject *mObject;
};
template<class ObjectType>
class BindingPointer : public RefCountObjectBindingPointer
{
public:
void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); }
ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); }
ObjectType *operator -> () const { return get(); }
};
}
#endif // LIBGLES_CM_REFCOUNTOBJECT_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 LIBGLES_CM_RENDERBUFFER_H_
#define LIBGLES_CM_RENDERBUFFER_H_
#include "RefCountObject.h"
#include "Image.hpp"
#define GL_API
#include <GLES/gl.h>
namespace es1
{
class Texture2D;
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:
BindingPointer<Texture2D> mTexture2D;
};
// 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 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 // LIBGLES_CM_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 "Renderbuffer.h"
#include "Texture.h"
namespace es1
{
ResourceManager::ResourceManager()
{
mRefCount = 1;
}
ResourceManager::~ResourceManager()
{
while(!mBufferMap.empty())
{
deleteBuffer(mBufferMap.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 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::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;
}
}
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;
}
}
Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
{
RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle);
if(renderbuffer == mRenderbufferMap.end())
{
return NULL;
}
else
{
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_EXTERNAL)
{
textureObject = new TextureExternal(texture);
}
else
{
UNREACHABLE();
return;
}
mTextureMap[texture] = textureObject;
textureObject->addRef();
}
}
void ResourceManager::checkRenderbufferAllocation(GLuint renderbuffer)
{
if(renderbuffer != 0 && !getRenderbuffer(renderbuffer))
{
Renderbuffer *renderbufferObject = new Renderbuffer(renderbuffer, new Colorbuffer(0, 0, GL_RGBA4_OES, 0));
mRenderbufferMap[renderbuffer] = renderbufferObject;
renderbufferObject->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 LIBGLES_CM_RESOURCEMANAGER_H_
#define LIBGLES_CM_RESOURCEMANAGER_H_
#include "HandleAllocator.h"
#define GL_API
#include <GLES/gl.h>
#include <map>
namespace es1
{
class Buffer;
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 createTexture();
GLuint createRenderbuffer();
void deleteBuffer(GLuint buffer);
void deleteTexture(GLuint texture);
void deleteRenderbuffer(GLuint renderbuffer);
Buffer *getBuffer(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);
void checkRenderbufferAllocation(GLuint renderbuffer);
private:
std::size_t mRefCount;
typedef std::map<GLint, Buffer*> BufferMap;
BufferMap mBufferMap;
HandleAllocator mBufferHandleAllocator;
typedef std::map<GLint, Texture*> TextureMap;
TextureMap mTextureMap;
HandleAllocator mTextureHandleAllocator;
typedef std::map<GLint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap;
HandleAllocator mRenderbufferHandleAllocator;
};
}
#endif // LIBGLES_CM_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.
//
// 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 LIBGLES_CM_TEXTURE_H_
#define LIBGLES_CM_TEXTURE_H_
#include "Renderbuffer.h"
#include "RefCountObject.h"
#include "utilities.h"
#include "libEGL/Texture2D.hpp"
#include "common/debug.h"
#define GL_API
#include <GLES/gl.h>
#include <vector>
namespace egl
{
class Surface;
class Config;
}
namespace es1
{
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 RefCountObject
{
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 egl::Texture2D
{
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);
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 TextureExternal : public Texture2D
{
public:
explicit TextureExternal(GLuint id);
virtual ~TextureExternal();
virtual GLenum getTarget() const;
void setImage(Image *image);
};
}
#endif // LIBGLES_CM_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 "IndexDataManager.h"
#include "common/debug.h"
#include <algorithm>
namespace
{
enum {INITIAL_STREAM_BUFFER_SIZE = 1024 * 1024};
}
namespace es1
{
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();
// Determine the required storage size per used buffer
for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
{
if(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(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 LIBGLES_CM_VERTEXDATAMANAGER_H_
#define LIBGLES_CM_VERTEXDATAMANAGER_H_
#include "Context.h"
#include "Device.hpp"
#define GL_API
#include <GLES/gl.h>
namespace es1
{
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 // LIBGLES_CM_VERTEXDATAMANAGER_H_
This source diff could not be displayed because it is too large. You can view the blob instead.
LIBRARY libGLES_CM
EXPORTS
eglBindTexImage @134
eglChooseConfig @1
eglCopyBuffers @2
eglCreateContext @3
eglCreatePbufferSurface @4
eglCreatePixmapSurface @5
eglCreateWindowSurface @6
eglDestroyContext @7
eglDestroySurface @8
eglGetConfigAttrib @9
eglGetConfigs @10
eglGetCurrentContext @11
eglGetCurrentDisplay @12
eglGetCurrentSurface @13
eglGetDisplay @14
eglGetError @15
eglGetProcAddress @16
eglInitialize @17
eglMakeCurrent @18
eglQueryContext @19
eglQueryString @20
eglQuerySurface @21
eglReleaseTexImage @135
eglSurfaceAttrib @133
eglSwapBuffers @22
eglSwapInterval @132
eglTerminate @23
eglWaitGL @24
eglWaitNative @25
glActiveTexture @26
glAlphaFunc @27
glAlphaFuncx @28
glBindBuffer @136
glBindTexture @29
glBlendFunc @30
glBufferData @137
glBufferSubData @138
glClear @31
glClearColor @32
glClearColorx @33
glClearDepthf @34
glClearDepthx @35
glClearStencil @36
glClientActiveTexture @37
glClipPlanef @139
glClipPlanex @140
glColor4f @38
glColor4ub @141
glColor4x @39
glColorMask @40
glColorPointer @41
glCompressedTexImage2D @42
glCompressedTexSubImage2D @43
glCopyTexImage2D @44
glCopyTexSubImage2D @45
glCullFace @46
glDeleteBuffers @142
glDeleteTextures @47
glDepthFunc @48
glDepthMask @49
glDepthRangef @50
glDepthRangex @51
glDisable @52
glDisableClientState @53
glDrawArrays @54
glDrawElements @55
glEnable @56
glEnableClientState @57
glFinish @58
glFlush @59
glFogf @60
glFogfv @61
glFogx @62
glFogxv @63
glFrontFace @64
glFrustumf @65
glFrustumx @66
glGenBuffers @147
glGenTextures @67
glGetBooleanv @143
glGetBufferParameteriv @144
glGetClipPlanef @145
glGetClipPlanex @146
glGetError @68
glGetFixedv @148
glGetFloatv @149
glGetIntegerv @69
glGetLightfv @150
glGetLightxv @151
glGetMaterialfv @152
glGetMaterialxv @153
glGetPointerv @154
glGetString @70
glGetTexEnvfv @156
glGetTexEnviv @155
glGetTexEnvxv @157
glGetTexParameterfv @159
glGetTexParameteriv @158
glGetTexParameterxv @160
glHint @71
glIsBuffer @161
glIsEnabled @162
glIsTexture @163
glLightModelf @72
glLightModelfv @73
glLightModelx @74
glLightModelxv @75
glLightf @76
glLightfv @77
glLightx @78
glLightxv @79
glLineWidth @80
glLineWidthx @81
glLoadIdentity @82
glLoadMatrixf @83
glLoadMatrixx @84
glLogicOp @85
glMaterialf @86
glMaterialfv @87
glMaterialx @88
glMaterialxv @89
glMatrixMode @90
glMultMatrixf @91
glMultMatrixx @92
glMultiTexCoord4f @93
glMultiTexCoord4x @94
glNormal3f @95
glNormal3x @96
glNormalPointer @97
glOrthof @98
glOrthox @99
glPixelStorei @100
glPointParameterf @164
glPointParameterfv @165
glPointParameterx @166
glPointParameterxv @167
glPointSize @101
glPointSizePointerOES @168
glPointSizex @102
glPolygonOffset @103
glPolygonOffsetx @104
glPopMatrix @105
glPushMatrix @106
glReadPixels @107
glRotatef @108
glRotatex @109
glSampleCoverage @110
glSampleCoveragex @111
glScalef @112
glScalex @113
glScissor @114
glShadeModel @115
glStencilFunc @116
glStencilMask @117
glStencilOp @118
glTexCoordPointer @119
glTexEnvf @120
glTexEnvfv @121
glTexEnvi @169
glTexEnviv @174
glTexEnvx @122
glTexEnvxv @123
glTexImage2D @124
glTexParameterf @125
glTexParameterfv @171
glTexParameteri @170
glTexParameteriv @172
glTexParameterx @126
glTexParameterxv @173
glTexSubImage2D @127
glTranslatef @128
glTranslatex @129
glVertexPointer @130
glViewport @131
; 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 libGLES_CM Dynamic Link Library"
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "libGLES_CM"
VALUE "LegalCopyright", "Copyright (C) 2012 TransGaming Inc."
VALUE "OriginalFilename", "libGLES_CM.dll"
VALUE "PrivateBuild", VERSION_STRING
VALUE "ProductName", "SwiftShader libGLES_CM 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="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="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RefCountObject.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="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="libGLES_CM.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MatrixStack.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="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="RefCountObject.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="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="..\common\debug.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES\egl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES\gl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES\glext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\GLES\glplatform.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MatrixStack.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libGLES_CM.rc" />
</ItemGroup>
<ItemGroup>
<None Include="libGLES_CM.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";
#else
const char *libEGL_lib = "libEGL.so.1";
#endif
libEGL = loadLibrary(libEGL_lib);
egl::getCurrentContext = (egl::Context *(*)())getProcAddress(libEGL, "eglGetCurrentContext");
egl::getCurrentDisplay = (egl::Display *(*)())getProcAddress(libEGL, "eglGetCurrentDisplay");
return libEGL != 0;
}
DESTRUCTOR static void glDetachProcess()
{
TRACE("()");
glDetachThread();
freeLibrary(libEGL);
}
#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 es1
{
es1::Context *getContext()
{
egl::Context *context = egl::getCurrentContext();
if(context && context->getClientVersion() == 1)
{
return static_cast<es1::Context*>(context);
}
return 0;
}
egl::Display *getDisplay()
{
return egl::getCurrentDisplay();
}
Device *getDevice()
{
Context *context = getContext();
return context ? context->getDevice() : 0;
}
}
// Records an error code
void error(GLenum errorCode)
{
es1::Context *context = es1::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_OES:
context->recordInvalidFramebufferOperation();
TRACE("\t! Error generated: invalid framebuffer operation\n");
break;
default: UNREACHABLE();
}
}
}
namespace egl
{
egl::Context *(*getCurrentContext)() = 0;
egl::Display *(*getCurrentDisplay)() = 0;
}
void *libEGL = 0; // Handle to the libEGL module
\ No newline at end of file
// 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 LIBGLES_CM_MAIN_H_
#define LIBGLES_CM_MAIN_H_
#include "Context.h"
#include "Device.hpp"
#include "common/debug.h"
#include "libEGL/Display.h"
#define GL_API
#include <GLES/gl.h>
#define GL_GLEXT_PROTOTYPES
#include <GLES/glext.h>
namespace es1
{
Context *getContext();
egl::Display *getDisplay();
Device *getDevice();
}
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)();
}
extern void *libEGL; // Handle to the libEGL module
#endif // LIBGLES_CM_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 LIBGLES_CM_MATHUTIL_H_
#define LIBGLES_CM_MATHUTIL_H_
#include "common/debug.h"
#include <math.h>
namespace es1
{
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 // LIBGLES_CM_MATHUTIL_H_
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by libGLES_CM.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 LIBGLES_CM_UTILITIES_H
#define LIBGLES_CM_UTILITIES_H
#include "Device.hpp"
#include "Image.hpp"
#include "Texture.h"
#define GL_API
#include <GLES/gl.h>
#define GL_GLEXT_PROTOTYPES
#include <GLES/glext.h>
#include <string>
namespace es1
{
struct Color;
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(es1::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, es1::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 // LIBGLES_CM_UTILITIES_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;
# EGL dependencies
glCreateContext;
glDestroyContext;
glMakeCurrent;
glGetCurrentContext;
glGetProcAddress;
glBindTexImage;
createFrameBuffer;
createBackBuffer;
createDevice;
Register;
local:
*;
};
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