Home | History | Annotate | Download | only in libGL
      1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //    http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 // VertexDataManager.h: Defines the VertexDataManager, a class that
     16 // runs the Buffer translation process.
     17 
     18 #ifndef LIBGL_VERTEXDATAMANAGER_H_
     19 #define LIBGL_VERTEXDATAMANAGER_H_
     20 
     21 #include "Context.h"
     22 #include "Device.hpp"
     23 
     24 #define _GDI32_
     25 #include <windows.h>
     26 #include <GL/GL.h>
     27 #include <GL/glext.h>
     28 
     29 namespace gl
     30 {
     31 
     32 struct TranslatedAttribute
     33 {
     34 	sw::StreamType type;
     35 	int count;
     36 	bool normalized;
     37 
     38 	unsigned int offset;
     39 	unsigned int stride;   // 0 means not to advance the read pointer at all
     40 
     41 	sw::Resource *vertexBuffer;
     42 };
     43 
     44 class VertexBuffer
     45 {
     46 public:
     47 	VertexBuffer(unsigned int size);
     48 	virtual ~VertexBuffer();
     49 
     50 	void unmap();
     51 
     52 	sw::Resource *getResource() const;
     53 
     54 protected:
     55 	sw::Resource *mVertexBuffer;
     56 };
     57 
     58 class ConstantVertexBuffer : public VertexBuffer
     59 {
     60 public:
     61 	ConstantVertexBuffer(float x, float y, float z, float w);
     62 	~ConstantVertexBuffer();
     63 };
     64 
     65 class StreamingVertexBuffer : public VertexBuffer
     66 {
     67 public:
     68 	StreamingVertexBuffer(unsigned int size);
     69 	~StreamingVertexBuffer();
     70 
     71 	void *map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *streamOffset);
     72 	void reserveRequiredSpace();
     73 	void addRequiredSpace(unsigned int requiredSpace);
     74 
     75 protected:
     76 	unsigned int mBufferSize;
     77 	unsigned int mWritePosition;
     78 	unsigned int mRequiredSpace;
     79 };
     80 
     81 class VertexDataManager
     82 {
     83 public:
     84 	VertexDataManager(Context *context);
     85 	virtual ~VertexDataManager();
     86 
     87 	void dirtyCurrentValue(int index) { mDirtyCurrentValue[index] = true; }
     88 
     89 	GLenum prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *outAttribs);
     90 
     91 private:
     92 	unsigned int writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute);
     93 
     94 	Context *const mContext;
     95 
     96 	StreamingVertexBuffer *mStreamingBuffer;
     97 
     98 	bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS];
     99 	ConstantVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS];
    100 };
    101 
    102 }
    103 
    104 #endif   // LIBGL_VERTEXDATAMANAGER_H_
    105